Using NodeJS with MongoDB+Mongoose.
First of all, I know the advantages of async non-blocking code. So I do deal with callbacks. But finally I faced the following proble
You don't want to waste RAM, so replace
lock_function_for_user[user_id] = false
with
delete lock_function_for_user[user_id]
Apart from that: You could just be optimistic and retry if a conflict happens. Just leave out the locking and make sure that the DB notices when stuff goes wrong (and retry in that case). Of course, which way is better depends on how often such conflicts really happen.