Part 1 of Building a Notification Service
What a notification service actually does
Module 1 · 4 min read
What a notification service actually does
TL;DR
- Push, SMS, email and the in-app inbox are four different pipes, each with its own provider, cost and contact data.
- Other services say what happened. The notification service picks channels, owns the wording and queues one job per channel.
- Delete tokens the provider rejects. “Sent” only means the provider accepted it.
Four channels
“Send the user a notification” is really four jobs, each through a different outside company.
| Channel | Who actually delivers it | What you need to know | Good for |
|---|---|---|---|
| Push | Apple (APNs) for iPhones, Google (FCM) for Android | A device token for each phone the user has the app on | Payment received, login alerts, offers |
| SMS | An SMS gateway or aggregator, which talks to the mobile operators | The phone number | OTPs, and anything that must reach people without the app |
| An email provider (your own mail servers or a sending service) | A verified email address | Receipts, statements, long messages | |
| In-app inbox | Nobody: it’s a row in your own database | Just the user ID | A history the user can scroll back through |
Push is free but needs the app and permission. SMS reaches almost everyone, at a price per message. Email is cheap but read late. The inbox is only seen when the app is opened.
Who is “the user”?
- Device tokens. The app gets one from Apple or Google on startup and sends it to the backend, and a user may have several (phone, tablet). Tokens change, and after an uninstall the provider rejects the old one. Delete invalid tokens, or you keep paying to send into the void.
- Phone numbers and emails, usually owned by the user profile service and read or cached here.
- Preferences (marketing off, push off, and opt-outs regulators may require for promotional SMS), checked on every send.
The shape of the system
Most people end up close to Alex Xu’s design.
- Producers (payments, login, marketing) publish an event like
payment.receivedor call the notification API. They never call Apple or the SMS gateway themselves. - The notification service validates the request, looks up contacts and preferences, picks channels, fills in the template (“You received $5 from Alex”) and queues one job per channel.
- One queue per channel. Channels slow down and fail on their own, so a slow SMS gateway never holds up push, and each channel scales its own workers.
- Workers call the outside provider.
- A notification log records each job’s result (sent, failed, delivered) for retries, support tickets and metrics.
The queues let the payment service say “done” in milliseconds while the slow outside world catches up. Module 2 picks the queue.
Which channels for which event?
Routing rules are the heart of the service, and easy to get subtly wrong. A login OTP goes by SMS, never email. A payment goes by push and inbox, with SMS only if there’s no working push token. A campaign respects marketing opt-outs.
Templates instead of strings
The payment service sends facts (template name, amount, sender), never finished text. The notification service owns the wording for each language and channel, like a short push title and body, a length-limited SMS (long ones get split and cost more), or an email subject and HTML. So rewording never needs a payment-service deploy.
One rule I keep coming back to. Services that cause notifications only say what happened. Who hears about it, how and in what words is decided in one place. Otherwise nobody can rate-limit a user across services, apply opt-outs consistently, switch SMS provider in one place, count the cost, or say how many messages a user got today.
Quick check
Apple starts rejecting one user’s device token as invalid. What should the service do?
The app was probably uninstalled or the token replaced, so retries waste work. Remove that one token (the user may have others), and fall back to SMS or the inbox if the message matters.
Q&A
Does “sent” mean the user got it?
No, only that the provider accepted it. SMS gateways confirm later with a delivery receipt. Apple and Google don’t confirm push delivery, though the app can report opens. So the log tracks accepted, delivered, opened and failed separately.
Is the in-app inbox a notification too?
Yes, and the easiest, since it’s a row in your own database. It’s also the safety net. If a push is lost, the user finds the message next time they open the app.