A reliable notification system
Emails are sent inside web requests today. Add push and SMS, user preferences, and no duplicates or lost messages.
To design a notification system, decouple producers with a durable queue, use separate priority lanes so campaigns cannot delay critical messages, and give each notification an idempotency key so retries never send twice. Check preferences at send time, rate-limit towards providers, and move repeated failures to a dead-letter queue.
The system today: An online store sends order emails directly from the request handler that places the order: the handler calls an email provider and waits. When the provider is slow, checkout is slow, and when it fails the email is simply lost.
What has to change: Design a notification system for email, push and SMS that handles 50 million notifications a day, respects each user's preferences and quiet hours, retries on failure without sending duplicates, and does not slow down the services that trigger notifications.
Questions to ask first
- Which notifications are critical (a password reset) and which can be delayed or dropped (a promotion)?
- Can a user opt out per channel or per type, and how fast must that take effect?
- Do we need scheduled and bulk sends, such as a campaign to a million users?
- What delivery rate do the providers allow, and what do they cost?
Where the interviewer digs in
- A queue between producers and senders, with separate lanes for critical and bulk traffic
- Idempotency keys so retries do not send twice
- Rate limiting towards providers, retries with backoff and a dead-letter queue
What a strong answer covers
- Decouples with a durable queue: services publish an event and return; workers render and send.
- Separates priority lanes so a promotion blast cannot delay a password reset.
- Uses an idempotency key per notification and per channel to make retries safe, and stores status for support and debugging.
- Handles preferences and quiet hours in one place, provider failover, backoff, and a dead-letter queue with alerting.
Common mistakes
- Calling the provider inside the request, or retrying blindly and sending duplicates.
- One queue for everything, so a campaign starves critical messages.
- Forgetting to check preferences at send time rather than at enqueue time.