Dev.to
7/9/2026

The Bug That Taught Me What "Real-Time" Actually Means
Short summary
A developer recounts a presence-tracking bug in their real-time chat app ChatSphere where online status was keyed by socket ID instead of username, causing users with multiple tabs to appear offline when one tab closed. The fix maps each username to a set of active socket connections so a user only goes offline when their last connection drops. The author also adds an in-memory sliding-window rate limiter and discusses when Redis would be needed for multi-instance deployments.
- •Presence tracking must be keyed by user identity, not socket connection, to support multi-tab and multi-device usage
- •Only mark a user offline when all their socket connections are closed, not just the first one
- •In-memory rate limiting works for single-instance deployments; Redis is needed once multiple server instances share state
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



