Reputation: 3212
Our setup is Rails 3 with a 6 app servers behind a load balancer and one PostgreSQL database.
In our app, and user can "tip" and artist during a performance.
The process flow looks like this:
What can happen is that if the user "spams" the tip button, multiple tips can be in-process at once. When this occurs the "does this user have enough money?" check returns the same value for many tips since the financial transaction have not happened yet.
What I need is to make sure each "tip" gets process sequentially. That way, the balance check for tip #2 does happen before tip #1 updates the balance.
We're already using Resque for other stuff, so that might be one solution. Although I don't know of a way of making sure multiple works don't start processing jobs in parallel and cause the same issue. Having one worker do tip jobs would not be viable solution as our app processes a lot of tips at any given instant.
Upvotes: 0
Views: 144
Reputation: 19471
If you enforce this within database transactions it is a fairly simple problem to solve.
http://www.postgresql.org/docs/9.1/interactive/mvcc.html
Upvotes: 3