SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 24
Design a notification service
Many internal teams need to tell users things: a password reset code, "your order shipped", "someone commented on your photo", a weekly digest, a marketing campaign. They call one shared service, which decides how to reach each person and hands the message to outside providers for push, email and SMS.
Requirements
- Accept a notification request (user, category, template data) from internal producers and acknowledge it quickly.
- Choose channels per user from their preferences and the category: opt-outs, quiet hours, verified email or phone.
- Deliver through third-party push, email and SMS providers, retrying failures, and never deliver the same notification twice on the same channel.
- Limit how many low-priority notifications one user receives, and record the delivery status of each notification.
Constraints and assumptions
- 2 billion notifications a day (about 23,000 per second on average); campaigns add bursts of 50 million recipients over 10 minutes.
- Channel mix: 80% push, 18% email, 2% SMS.
- Security codes and password resets must be handed to a provider within 5 seconds at p99, even during a campaign burst.
- Providers enforce their own rate limits (for example 1,000 SMS per second per account) and sometimes fail or slow down for minutes at a time.
- 300 million users with stored preferences and an average of 1.5 devices each.
Out of scope for the first sketch
Building the push, email or SMS providers · Template authoring and localization · An in-app notification inbox
Draw your design
Rough math and notes
SYSTEM DESIGN SKETCHBOOK / FOLLOW-UPS
Design a notification service
Finish your first sketch before answering these. Cross out freely.
- A producer times out and retries the same request. How do you make sure the user gets one push, not two?
- A user gets 40 "someone liked your photo" events in one minute. How do you avoid spamming them?
- Marketing sends to 50 million users while password reset codes keep flowing. How do the reset codes stay fast?
- The SMS provider starts failing 20% of requests. What does your system do over the next five minutes?
- A user opts out of marketing email while a campaign is halfway through sending. Which messages still go out to them?
Compare afterwards: worked approaches and reading at sketchbook /questions/notification-service/review