LeetDesign
← All problems
Easy

Design an Online Presence Service

Track who's online right now. The data dies in sixty seconds and rebuilds itself from heartbeats — the first contract where a single copy is the right answer, and the trap is deciding you don't need a database at all.

Design the presence layer of a chat product: the green dot. Every online client pings a heartbeat on a 30-second timer — three hundred thousand of them at the evening peak — and profile cards, conversation headers, and buddy lists read status back out.

What makes this contract unlike anything else in the catalog is that the data repairs itself. If every disk in the system burned down at noon, the heartbeats would have rebuilt the entire dataset by 12:00:30. Durability engineering exists to protect data you cannot get back, and this data comes back on its own — so read the durability clauses carefully before you spend a dollar on them, because the cost axis certainly will.

The trap sits on the other side. Presence is so cache-shaped — hundred-byte values, a ten-second staleness budget, a working set that fits in one cache node's RAM a hundred times over — that the tempting design has no real store at all. But every request in this model has to terminate at a system of record, and ten thousand heartbeats a second is an ingest floor no cache can take off your hands.