#MedusaJS performance issue for large stores? Error.

1 messages · Page 1 of 1 (latest)

narrow stratus
#
Error: could not serialize access due to concurrent update
    at formatException (/lab/node_modules/@medusajs/medusa/dist/utils/exception-formatter.js:26:20)
    at exports.default (/lab/node_modules/@medusajs/medusa/dist/api/middlewares/error-handler.js:14:43)
    at Layer.handle_error (/lab/node_modules/express/lib/router/layer.js:71:5)
    at trim_prefix (/lab/node_modules/express/lib/router/index.js:326:13)
    at /lab/node_modules/express/lib/router/index.js:286:9
    at Function.process_params (/lab/node_modules/express/lib/router/index.js:346:12)
    at next (/lab/node_modules/express/lib/router/index.js:280:10)
    at /lab/node_modules/express/lib/router/index.js:646:15
    at next (/lab/node_modules/express/lib/router/index.js:265:14)
    at /lab/node_modules/express/lib/router/index.js:646:15 {
  type: 'conflict',
  code: undefined,
  date: 2022-12-19T09:00:01.488Z
}```

PostgresQL + Redis. Everything is standard out of the box.
Occurs when I click several times, 5+, on the add to cart button.
knotty marlin
#

Adrien will probably come here and confirm but I think it's not an issue for large stores.
You are updating the same cart (the same row). And there's a row lock on transaction.
Normally different customers would update different rows (different carts) and the issue would not exist.
By the way I am disabling the Add To Cart button with loading state until the response comes back.

narrow stratus
#

Thanks @knotty marlin for the clarification . I hope this is so, otherwise we have a project on Medusa 💜 at the exit to the prod, and then suddenly I accidentally saw this behavior. It's a good idea to add to cart on loading, so I'll do that.
Interestingly, when I click on add to cart 4 times (before the first one is added), everything is ok, everything is added, but the 5th one already causes an error.

thorn pagoda
#

@narrow stratus What version of the core is installed in your setup?

cc @torn sedge

torn sedge
#

@narrow stratus Indeed @knotty marlin is right, you should add a debounce (i.d what kosek suggested) on your add to cart on the same product.
What happens is that the same line item is being updated concurrently, and each action is run in a serializable transaction which means that if two transactions try to update the item at the same time and both are not finished, it creates an error like this. Of course, it will not always happen since it depends on when a transaction does the updqte and if the concurrent one is already released or not. But the more concurrent transaction you create and the more likely it is to happen

#

cc @thorn pagoda

narrow stratus
#

Thanks a lot for the clarifications. Now I'm working on a variant that kosek suggested.

narrow stratus
torn sedge
#

Yes, in a serializable mode (the strongest one) even reading data that have been updated by another transaction is not allowed