Design a notification system
System design, Hard
Design a system that sends email, SMS and push notifications to users. There are 10 million users. A normal day sends 2 million notifications. A marketing campaign can send 5 million pushes within 10 minutes. One-time passcodes (OTP) must arrive within 10 seconds. Messages must not be lost, and users must not get the same message twice. Cover the flow from request to delivery, retries, duplicates, user preferences and how you protect urgent messages from a large campaign. Out of scope: building the email, SMS or push providers.
Examples
Input POST /notifications { "userId": "u1", "channel": "push", "type": "campaign", "idempotencyKey": "c42-u1" } is sent twice within one minute.
Output The API accepts both calls, and the user gets one push.
Why Callers retry. The design must say how a repeat is recognised.
Input A one-time passcode is requested while a 5-million-push campaign is still sending.
Output The passcode reaches the user within 10 seconds.
Why This is the requirement a large campaign puts at risk. Say what keeps it safe.
Input The push provider answers HTTP 503 for 2 minutes. 40,000 notifications are waiting.
Output None is lost. After the provider recovers they are sent, and no user gets the same message twice.
Why A provider failure is normal. Say what happens to messages in flight and to those that keep failing.
Constraints
- 10 million users. 2 million notifications on a normal day.
- A campaign can send 5 million pushes within 10 minutes.
- One-time passcodes must arrive within 10 seconds.
- Three channels: email, SMS and push. Messages must not be lost and users must not get the same message twice.
- Out of scope: building the email, SMS or push providers.
Your answer must contain
- Rough throughput numbers, the flow, how you handle failure of a provider, how you prevent duplicates (and what you cannot promise), and how a user turns a channel off.