Deal with increment parallelism #7052

Closed
opened 2026-01-22 15:43:47 +01:00 by admin · 0 comments
Owner

Originally created by @l-you on GitHub (Sep 29, 2022).

Suppose we have e-commerce website with hot sales. There often can be a case where product stock is decremented in parallel requests.
Solution can be to use mysql directly UPDATE product SET stock=stock-1.
But it has drawbacks. For example task is "Create order and reduce stock". I reduce stock with direct mysql query, but during
->flush() exception appears and order not saved. So I have reduced stock and no order.
Is there a way UPDATE product SET stock=stock-1 to be persisted, so it will execute with other updates when ->flush() is called?

Originally created by @l-you on GitHub (Sep 29, 2022). Suppose we have e-commerce website with hot sales. There often can be a case where product stock is decremented in parallel requests. Solution can be to use mysql directly `UPDATE product SET stock=stock-1`. But it has drawbacks. For example task is "Create order and reduce stock". I reduce stock with direct mysql query, but during `->flush()` exception appears and order not saved. So I have reduced stock and no order. Is there a way `UPDATE product SET stock=stock-1` to be persisted, so it will execute with other updates when `->flush()` is called?
admin closed this issue 2026-01-22 15:43:47 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7052