KatInterview

Building a Multi-Channel Alerting Pipeline at Billion-Scale

System DesignModel answer
MediumModel answerSystem Designsystem-designnotificationskafka

Last updated

Design a platform that takes events from internal services and delivers them to users through push, SMS, email and an in-app inbox, with retries, deduplication and celebrity-scale fanout.

Problem

A large social network wants a single alerting platform that every internal microservice can call. Services emit events such as a like on a photo, a direct message, a friend request, a login verification code, or a platform-wide announcement. The platform must turn those events into messages and deliver them to users over:

  • mobile push (APNs for iOS, FCM for Android),
  • SMS through third-party aggregators,
  • email through an email gateway,
  • an in-app notification center (inbox).

Functional requirements

  • Channel routing: send each message to the right external provider or write it to the user's inbox.
  • Preferences and collapsing: honor per-user channel opt-outs and quiet hours (Do Not Disturb). Merge bursts of similar events into one message, for example "Alice and 14 others liked your photo".
  • Fanout: support single-recipient events (a direct message) and broadcast events (a creator with 20 million followers publishes a video).
  • Inbox: users can page through their notification history and mark items as read.

Scale and quality targets

  • 10 billion notifications per day: roughly 120K requests/s on average and 500K/s at peak.
  • Latency: critical alerts (verification codes, DMs) must reach the external gateway within 2 seconds. Bulk traffic such as digests may take several minutes.
  • Reliability: at-least-once delivery, no data loss once a request has been accepted, and no cascading backpressure when a third-party provider is slow or down.
  • Idempotency: if an upstream service retries a trigger, the end user must not receive duplicate alerts.

What to cover in your answer

  1. API design: how internal services trigger notifications, and how clients read and update their inbox.
  2. Architecture: ingestion, queue layout, worker pools, preference evaluation, and provider dispatchers.
  3. Data model: inbox storage, user preferences, device tokens, and delivery status tracking.
  4. Failure handling and trade-offs: retries, dead-letter queues, slow providers, and how to handle very high-follower accounts.

State your assumptions and back-of-the-envelope numbers explicitly.

Hints

Hint 1

Start with capacity math: convert 10B/day into per-second rates, estimate payload size and inbox row size, and use them to justify a partitioned log and a wide-column inbox store. Also split traffic into priority tiers so urgent messages never wait behind bulk ones.

Hint 2

Make idempotency a two-layer idea: dedupe producer retries at ingestion with a key, and dedupe consumer redeliveries at dispatch with a conditional status write. Acknowledge that exactly-once to a phone is impossible and use provider collapse identifiers to hide the remaining duplicates.

Hint 3

For failures, isolate each provider with its own queue, rate limiter, circuit breaker and bulkhead; retry via delayed retry topics with jittered backoff instead of blocking a partition; and for a 20M-follower account avoid synchronous expansion by chunking, filtering to engaged users, throttling, and using a read-time merge for the rest.