Lesson 10 of 17
38. Design a Chat App (WhatsApp)

38.9 How does offline delivery work?

3 min read+10 XP

Phones go offline constantly: tunnels, flights, flat batteries.

each device has its own cursor; a reconnecting laptop syncs messages after its cursor, in order.

Figure: a cursor per device per chat makes catching up exact.

  • Every message is stored before delivery, so nothing depends on the recipient being online.
  • Each device keeps a cursor per chat: the last seq it has. On reconnect, it asks for everything after its cursor (in practice, one call for "all chats with something new").
  • In the chapter's code, Ravi's laptop goes offline after seq 2, misses 3, 4, 5, syncs them in order, acks "up to 5", and a second sync returns nothing.
  • While offline, a push notification (APNs/FCM) nudges the app; with end-to-end encryption, the push usually says only "new message", and the app fetches and decrypts it.
  • The server deletes a message once all member devices are past it (plus a safety window), if the product chooses "store until delivered".

Memory code: "Store first, nudge the sleeper, sync from the cursor."