Sunday, 3 February 2019

SocketIO rooms and lost frames

I have a trading engine that streams data for over 100 markets via socketIO. Initially, I'd broadcast the data for all markets to all users, with a tag indicating which store the client (SPA) should save each frame to, which was fine, but just as stupid as I figure you'd be imagining now.So, I decided to do it right... create a subscription concept, so a user only receives data for the market they're subscribed to. The subscription is done by emitting the market ID to the server. The server joins a room identified by the market ID and the trading engine isolates broadcasts by emitting to rooms, rather than to all connected sockets.The Problem: If there is a disconnection/reconnection, the client is not auto resubscribed to the market. The client has to emit another subscription payload after reconnecting, which implies that all trade data broadcasted to subscribers of the market/room during the client's downtime would be absolutely missed by the client.The !Solution: I make the client refetch trade data right after reconnection in an attempt to stay up to date, but some frames are still lost to the fetch delay and resubscription.Any ideas how to get this PITA situation over with?

Submitted February 04, 2019 at 06:06AM by r3dh4r7

No comments:

Post a Comment