I use Slim in combination with Stripe PHP Library to process payments in my application.
Everything is fine, but until recently, I found an alarming error in my system, which, in my opinion, could be a much more serious problem than I probably think. In my logic, at three separate control points of the payment process, I check the inventory in my (MySQL) database to ensure that the user does not buy more products than is available.
However, when several users make a request approximately 500 ms apart, the payment system seems to process these requests immediately, which leads to many problems, ranging from incorrect and unbalanced inventory to false confirmation of successful payments.
With some due diligence, I narrowed down the solution to two options (although I can sell myself short):
1) Use the Queuing System , which, in my opinion, will queue these requests and process them one at a time, creating a sort first in the first place, first and foremost.
2) Attach some middleware to each request, which will act as a queue, and try to process each request synchronously (although this might look like what I already have)
Now, with that said, any suggestions / opinions on these parameters? and obviously don’t hesitate to completely abandon my ideology and point me in a different direction.