← Lessons

quiz vs the machine

Gold1420

System Design

The Presence System

Tracking which users are online in near real time and expiring stale state so the list stays accurate.

5 min read · core · beat Gold to climb

What it is

A presence system answers a simple question at scale: who is online right now. It powers the green dots, typing indicators, and last seen times that make realtime apps feel alive.

The core mechanism

  • When a user connects, the gateway writes a presence record with a short time to live.
  • The connection sends a heartbeat that refreshes the time to live.
  • If heartbeats stop, the record expires and the user is shown offline.

Why expiry beats explicit logout

A user who loses network never sends a clean logout. Relying on an explicit signal leaves ghosts marked online forever. A time to live that the heartbeat refreshes makes presence self healing: stale records vanish on their own.

Fanning presence out

  • Changes are pushed to interested users such as friends in a contact list.
  • Batching and debouncing rapid flaps avoids a storm of online and offline updates.

Key idea

A presence system tracks who is online by refreshing a short lived record with heartbeats, letting stale state expire automatically instead of trusting an explicit logout.

Check yourself

Answer to earn rating on the learn ladder.

1. Why does presence rely on a time to live instead of explicit logout?

2. What keeps a presence record alive?