Chat
Who is online
Before you start
- Open lesson
Requirements
Each worked system starts from a scoped list of verbs and numbers.
Why it matters
Ana’s green dot should react quickly when her phone connects, but a dead phone cannot always announce that it left. At one million connected clients, frequent status updates can overwhelm storage meant for durable messages, and flaky mobile reconnects can make the dot flicker. The presence key must expire within 30 seconds, with only a brief display grace before contacts see her offline.
Example
Design presence
The app shows a green dot when the other person is connected. The dot should disappear within about 30 seconds of a dead connection.
Mental model
The idea
Keep one example in view
Design presence
The app shows a green dot when the other person is connected. The dot should disappear within about 30 seconds of a dead connection.
Keep this exact scenario and its constraint in view while you build the model.
Represent Ana as online while key ana exists: set a 30-second TTL on connect, refresh it with 10-second heartbeats, and delay Bo’s offline dot through a brief reconnect grace period; silence removes the key automatically.
Ana’s connection server writes presence key ana with a 30-second TTL. Her phone sends a heartbeat every 10 seconds, and each one extends that expiry. If the phone dies silently, no refresh arrives and the key disappears automatically; no durable cleanup transaction is needed.
Bo subscribes to Ana’s status or reads it when opening their chat. A short display grace hides a three-second disconnect and reconnect, so the green dot may remain for that grace after the key’s 30-second expiry. At one million devices, 100,000 small writes per second belong in an expiring in-memory store.
Pro
The rest of this is on Pro
The idea above is free. The walkthrough, the cost, and the practice are on Pro.