~learn.
0:00 / 1:16
Side quest 2 · WhatsApp

40 messages, and the connection drops halfway

transcript

Bob's phone was off for two days. 40 messages are waiting. He reconnects on a flaky network. Halfway through, it drops.

Each message waits in Bob's queue. A message ID, and a sequence number. He's back. The server drains the queue in batches. Some messages reach his phone. But their acks never make it back. So which ones landed? The server can't tell.

Here's the rule that saves it. Nothing is deleted without an ack. Writing to the socket proves nothing. Only the device's ack does.

Bob reconnects again. The server resends everything unacked. That's at-least-once delivery. Nothing goes missing. But here's the catch. Some messages now arrive twice.

So the phone does the last bit. It drops any message ID it has already seen. It orders the rest by the per-chat sequence. Then the acks flow. The server deletes. Alice's ticks turn double.

Bob sees all 40 messages. Once each. In order. And no global order needed. Order is only per chat. At-least-once on the wire. Dedup on the phone.

Full breakdown in the lecture.