Lesson 30 / 32

Design a Notification System

Fan-out to push, email, and SMS reliably at scale.

Requirements

Many internal services need to notify users (order shipped, comment reply, price drop) via push, email, or SMS, respecting user preferences and avoiding spamming the same event twice.

Decoupled with a queue

Producing services publish a notification requested event to a queue rather than calling providers directly. A notification service consumes it, checks user preferences and quiet hours, picks the channel, and calls the right third-party provider (APNs, FCM, SendGrid, Twilio).

Idempotency and retries

A retried send must not double-notify the user. Dedupe by a stable notification ID before dispatching.

on notification_requested(event):
  if seen(event.notification_id): return  # dedupe
  channel = pick_channel(user.prefs)
  provider[channel].send(event)
  mark_seen(event.notification_id)

Output:

Provider outages are isolated per channel with their own retry/backoff

Batch to avoid spam

For chatty sources (many comments in a minute), batch related events into one digest notification within a short window instead of firing one push per event.