I'm planning to use Node for my next project, because it seems to be a good fit for the problem I'm solving.
One thing I need to figure out is optimistic and pessimistic locking. http://guides.rubyonrails.org/active_record_querying.html#locking-records-for-update
Say, the user has a balance of 1. Two Node instances make requests concurrently to withdraw 1. The two requests could pass the check of sufficient balance at the same time, thus making two successful withdrawals resulting in a balance of -1.
Rails provides a wrapper around Postgres transactional and locking features. Does some kind of similar wrapper exist for Node?
How do you solve this in Node/Postgresql?
I know this is a database feature, but I wonder if Node or some library provides a abstraction away from writing raw SQL queries?