I'm building a server on Ruby using WebSockets through EventMachine.
Let's say user Carl asks for a Car.
The car of id "7" is requested to the CarManager. CarManager creates a Car instance, Car loads itself from a Mongo Database (id was provided). Car "7" is stored in CarManager, like a cache, as long Carl or anyone else keeps using or requesting it. And then Car is sent through WebSocket, specifically to Carl. I stored Carl's WS somewhere.
What if two users, say, Lenny and Carl, both ask for Car id "7" at the "exact" same time. Will CarManager, because it can't find in either case a cached version of Car 7, fetch it both times from database and instantiate it, or ONE of these two WebSocket request will be processed first, and then the second one will use the cached version?
The whole asynchronous thing of WebSockets made me a bit confused. Thank you for any insights on this!