Question presented to candidate: "We run a chat product on a fleet of WebSocket servers behind a load balancer. Product wants an accurate online indicator, and when a phone drops off the network for a few seconds it should reconnect and get the messages it missed. Do we need sticky sessions on the load balancer to make that work? Where does the state live?"
What a strong answer should cover:
- An open WebSocket is already pinned to one server for its whole life; stickiness only matters for the next connection (a reconnect) or for transports made of several HTTP requests (long-polling fallbacks such as Socket.IO's, which its docs say require sticky sessions)
- Keeping resume buffers or presence in server memory makes correctness depend on routing and on that server staying alive; externalising them (presence store with TTLs, a per-conversation log with sequence numbers) lets any server serve any reconnect
- Presence as heartbeats with a TTL, and why a silent disconnect is only detected when the TTL expires; multi-device presence; the cost of fanning presence changes out
- Resume: the client sends its last sequence number, the server replays from a durable log, and falls back to a full resync when the gap is too old
- Stickiness as an optimisation (warm caches, fewer cross-node hops), and why hash-mod-N stickiness reshuffles users when the fleet changes
Clarifying questions expected:
- How long may a client be gone and still expect a seamless resume (seconds, minutes, days)?
- Is presence per user or per device, and who needs to see it (friends, a room, everyone)?
- Do clients ever fall back to HTTP long polling?
Code / implementation expected: Optional — a design with the state placed explicitly; the example shows resume succeeding or failing under each choice.