I currently am incrementing a column for order number values with the increment()
function in Sequelize. ie: .increment("order_no", { by: 1 });
Occasionally a request hits my api at the exact same second and I end up with a duplicate order number value.
Is there any way that I can guarantee that the increment value is unique for an order number? Do I need to wrap the increment
in a transaction? Should I have a random timed check after creating the number value to see if there is a duplicate? Not sure of the right way to solve this.
From Sequelizes documentation (https://sequelize.org/docs/v6/core-concepts/model-instances/#incrementing-and-decrementing-integer-values)
In order to increment/decrement values of an instance without running into concurrency issues, Sequelize provides the increment and decrement instance methods.
However, while this appears to be working, I still get duplicate values out when being utilized.