Notification System Design, Step by Step
Turns one event into push and email after checking preferences, with a queue per channel so one slow channel can't block the rest.
Loading the interactive diagram…
Notification System Design, Step by Step
Turns one event into push and email after checking preferences, with a queue per channel so one slow channel can't block the rest.
Something happens
- Order service
- Service · Hypothetical. One of many services with news for a user: here, "your order has shipped".
Accept and sort
- Notification service
- Service · Hypothetical. Accepts a request, drops duplicates, checks preferences, and queues one job per channel.
- Channel queues
- Queue · Hypothetical. One queue per channel: push, email, SMS.
Deliver
- Push worker
- Service · Hypothetical. Takes push jobs off the queue and hands them to Apple and Google.
- Email worker
- Service · Hypothetical. Takes email jobs off the queue and sends them through the email provider.
Data
- User preferences
- Database · Hypothetical. Per user: which channels are on, quiet hours, language, device tokens and email address.
- Dedup and caps
- Cache · Hypothetical. Remembers recent idempotency keys and how many notifications each user got today.
- Delivery log
- Database · Hypothetical. What was sent, to whom, on which channel, and what happened to it.
Outside services
- Apple / Google push
- External · Hypothetical. Apple Push Notification service and Firebase Cloud Messaging: the only way to reach a phone's lock screen.
- Email provider
- External · Hypothetical. Sends the email, and reports back later whether it was delivered or bounced.
People
- User's phone
- Client · Hypothetical. Where the push finally appears.
Flow: Your order has shipped
The order service is answered at once; checking, queueing and sending happen after. Delivery to the phone is one-way from there.
- Order service → Notification service (Notify u42: shipped). The order service asks for user 42 to be told their order has shipped, with the idempotency key o-981-shipped.
- Notification service → Dedup and caps (Claim o-981-shipped). First, it claims the key in one atomic step: set it only if it isn't there yet, expiring in a minute. Two copies of the same request arriving together can't both get through.
- Dedup and caps → Notification service (Claimed: new). Nobody had it: this is a new request, so carry on.
- Notification service → User preferences (u42 settings?). Which channels does user 42 want for order updates, and is it quiet hours where they live?
- User preferences → Notification service (Push + email, 1 device). Push and email are both on, there's one phone, and it's daytime for them.
- Notification service → Channel queues (Push job, email job). It renders the message in the user's language and puts one job on the push queue and one on the email queue.
- Notification service → Dedup and caps (Mark o-981-shipped done). With the jobs safely queued, the claim becomes a permanent record for a day. Had the service crashed before this point, the one-minute claim would simply expire and a retry would go through.
- Dedup and caps → Notification service (Marked). Any retry of this request will now be recognised.
- Notification service → Order service (202 Accepted). The order service gets its answer now. It doesn't wait for anything to be delivered.
- Channel queues → Push worker (Push job for u42). A push worker picks up the job, usually within a second.
- Push worker → Apple / Google push (Your order shipped). It sends the notification, with the phone's device token, to Apple's or Google's push service.
- Apple / Google push → Push worker (Accepted). The push service accepted it.
- Push worker → Delivery log (Sent via push). The worker records it in the delivery log. The email job goes the same way through its own queue and worker.
- Apple / Google push → User's phone (Your order shipped). The notification appears on the phone's lock screen.
Flow: The same request arrives twice
The order service timed out and retried. The idempotency key catches it, so the user isn't notified twice.
- Order service → Notification service (Notify u42: shipped). The first call's answer got lost in a network hiccup, so the order service sends the same request again, with the same key o-981-shipped.
- Notification service → Dedup and caps (Claim o-981-shipped). The notification service tries to claim the key, as it does for every request.
- Dedup and caps → Notification service (Taken: done 40 s ago). This key was handled 40 seconds ago: its jobs are already queued, and may already be delivered.
- Notification service → Order service (200 Already accepted). Nothing new is queued. The answer says the request was already accepted, so the order service can stop retrying. Without the key, the user would get two identical pushes.
Flow: An email bounces
Sending an email is quick, but the result arrives later through a webhook. Background work: nobody is waiting on it.
- Channel queues → Email worker (Email job for u42). An email worker picks up the email job from the same order update.
- Email worker → Email provider (Send "Order shipped"). It sends the email through the provider's API.
- Email provider → Email worker (Queued for sending). The provider has it. That says nothing yet about whether it will arrive.
- Email worker → Delivery log (Sent via email). The worker records that it was sent.
- Email provider → Delivery log (Bounced: no such mailbox). A few minutes later the provider calls back (a webhook, received by a small endpoint of ours that isn't drawn): the address doesn't exist. After repeated bounces the address is marked invalid in the user's preferences, and email is skipped until they fix it.
Flow: Deliver a push job
The push path on its own, from queue to lock screen. One-way: the worker doesn't wait for the phone, only for the push service.
- Channel queues → Push worker (Push job). A push worker takes the next push job off the queue.
- Push worker → Apple / Google push (Push). It hands the notification to Apple's or Google's push service.
- Apple / Google push → Push worker (Accepted). Accepted for delivery.
- Apple / Google push → User's phone (Notification). The push service delivers it to the phone.
HowItScales is not affiliated with the companies shown. Components marked Assumption or Hypothetical are not confirmed by the company.