call(back)

Design a Notification System

Design Pinterest's notification system: push, email, and in-app notifications for comments, saves, follows, new pins on boards you follow, and recommendations. Billions of candidate events a day, with user preferences and volume limits.

The hard part: when someone comments on a pin, its owner gets a push — but a pin can go viral and draw thousands of comments in minutes, and the owner should not get thousands of pushes.

Assume push (APNs/FCM), email, and an in-app inbox with unread counts. Social events should notify within ~5 s p99; board updates within minutes; digests are batched. Internally delivery is at-least-once — the user must still see at-most-once. Respect per-user caps, quiet hours, and per-type preferences; unsubscribe takes effect immediately. The system must absorb 100x spikes from viral pins without backing up unrelated traffic.

Hints

Hint 1

The viral pin is a stream-aggregation problem with a hot key: 1M comments in 10 minutes is ~1.7k events/s hashing to one partition. Two-stage aggregation — partition by (pin, salt) for partial counts, then merge keyed by pin — turns the firehose into one message per salt per second.

Hint 2

Exactly-once to the user on an at-least-once pipeline means the last hop is idempotent: a dedup key of (recipient, event or window id) with an atomic set-if-absent before calling the push provider.

Hint 3

The senior half of the answer is volume control: fan-out produces candidates, not sends. A ranker over per-user event pools plus a feedback controller tuning score thresholds to hit send-volume targets is what separates plumbing from product.

Asked at