Design a notification system
Send notifications (mobile push, SMS, email) to users reliably, at large scale.
Why interviewers ask it
It tests queues, priorities, third-party integrations, retries and avoiding duplicates — everyday problems in real products.
Functional requirements
- Services trigger notifications (order shipped, one-time passcodes, marketing).
- Channels: push, SMS, email; respect each user's preferences and opt-outs.
- Templates, scheduling, and retries on failure.
Non-functional requirements
- Millions a day, with big spikes during campaigns.
- Passcodes must arrive in seconds; marketing can be slower.
- Delivered at least once, without spamming duplicates.
From version 1 to the final design
- Version 1: the order service calls the email provider directly.
- Version 2: a notification service with templates and user preferences.
- Version 3: a queue per channel, workers, retries and a dead-letter queue.
- Version 4: priority lanes, idempotency keys, provider failover and per-user rate limits.
The design, step by step
- A notification service checks preferences and rate limits, and fills in the template.
- It puts messages onto separate queues per channel (push, SMS, email) and per priority (passcodes ahead of marketing).
- Channel workers call the providers (Apple and Google push services, an SMS gateway, an email service).
- Retries with backoff; repeated failures go to a dead-letter queue; every status is recorded in a log.
Deep dives
- De-duplication: an idempotency key per notification, so retries don't send twice.
- Separate priority queues, so a marketing blast never delays a passcode.
- Provider failover: a second SMS provider.
- A per-user rate limit, so nobody gets spammed.
Common mistakes
- Sending the notification inside the user's request, so a slow email or push provider keeps the user waiting. Queue it instead.
- One queue where marketing messages block passcodes.
- Retries without idempotency, so users get duplicates.
Not true: One shared queue is fine for both marketing messages and login passcodes.
In fact: A marketing blast of millions would sit in front of the passcodes and delay them. Use separate queues, by priority.
In the interview
Producers call a notification service that checks preferences, fills in templates and puts messages on queues per channel and priority. Workers deliver through providers like Apple and Google push services and SMS gateways, with retries, dead-letter queues and idempotency keys to avoid duplicates. Passcodes get a high-priority lane, so campaigns never delay them.
Part of Unit 8: High-level design questions in the free System Design course.