Presence and Online Status Tracking
Build a real-time presence system that tracks which users are online using Redis sets, TTLs, and Pub/Sub heartbeats.
What Is Presence?
Presence is the real-time indication of whether a user is online, away, or offline. Chat apps, collaborative editors, and games all rely on it. Redis is ideal because presence data is ephemeral and high-churn.
The Naive Approach
A first idea: store a flag per user. The problem is detecting when someone disconnects ungracefully (closed laptop, lost network). A stale flag would mark them online forever.
SET presence:user:42 onlineAll lessons in this course
- Pattern Matching Subscriptions
- Designing Real-time Chat
- Event-Driven Architecture
- Presence and Online Status Tracking