Video in progress
Design a notification service that sends email, SMS and push. What are the main components?
Other services send events, and the notification service builds the message based on user preferences and a template, puts it on separate queues per channel, and workers send it to the providers with retries and record the result.
📖 Answer
Start by clarifying the requirements: how many messages per day, how many are urgent (OTP) and how many can wait (marketing), and can the user unsubscribe.
The flow:
order-service ──event──▶ [notifications topic]
│
Notification API
(preferences, template, dedup, rate limit)
│ │ │
[email q] [sms q] [push q]
│ │ │
email worker sms worker push worker ──▶ providers
└──────── delivery log (DB) ◀──────┘
Key decisions:
- Channels on separate queues — if the SMS provider slows down, emails shouldn't stop.
- Priority. If OTP and marketing share one queue, an OTP waits 20 minutes behind 1 million promo messages. Put them on separate queues.
- Dedup. If one event arrives twice, the user shouldn't get two SMS messages — a unique record on
eventId + channel. - Retry and fallback. If the provider returns 5xx, retry with backoff; switch to a second provider if needed. For 4xx (wrong number), don't retry.
- User preferences and quiet hours — don't send marketing pushes at night.
- Provider limits — if the SMS gateway accepts no more than 100 per second, rate-limit in the workers.
Store the status (QUEUED, SENT, DELIVERED, FAILED) and the provider's response in the delivery log — when support hears "the SMS never arrived", this is where they look.
Sign up to mark studied questions and save your progress.