Mysql locking - How to acquire a lock in the DB for each userId
GET_LOCK('rick');
...
RELEASE_LOCK('rick');


During ..., any other thread trying to do GET_LOCK('rick') would be blocked.

Will that work for your application?

Be aware of the caveats:  A disconnect (eg, network glitch) will release the lock.  Multiple locks need some care.  Etc.