~learn.
0:00 / 1:12
W06 · Notification platform

Three likes got batched. The fourth was never sent.

transcript

Your post gets 4 likes. Your notification says 3. The fourth like was never sent. To anyone. Ever.

First, batching. 20 likes without it? 20 separate notifications. With it, just one. 20 people liked your post.

Each like is appended to a Redis list, for that user and category. Flush when it reaches 10 likes. Or after 5 minutes, whichever comes first. So 3 likes still get sent.

Now the flush. Suppose it reads the list, then deletes it. Two steps. It reads 3 likes. In between, a fourth like lands in the list. Then the delete wipes the whole list. Including the fourth. It's never sent. Not a duplicate. Silent loss.

The bug lives in the gap between two steps. So the flush reads and deletes in one Redis pipeline. The window closes. The fourth like lands in the next batch.

Duplicates get noticed. Silent loss doesn't. If you read it and then delete it, do both as one step.

Full breakdown in the lecture.