While user code in NodeJS is single-threaded, the async/await system is event based, if you sleep for a random delay there's no way to tell which is the expected answer, as both calls will run in sequence, immediately logging start, but the event will be triggered first by which has a smaller random delay, causing one end log to be shown before the other in an unpredictable way. To respect the lock mechanism described you must implement a
Semaphore
or a Mutex
which locks operations only for same ID parameter, I am not a nodejs developer, so I can just point you in the right direction.