Mahir Shahriar Tamim

AI Researcher · Explainable & Responsible AI · Vision, Language & Agentic Systems

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.

ChannelWho actually delivers itWhat you need to knowGood for
PushApple (APNs) for iPhones, Google (FCM) for AndroidA device token for each phone the user has the app onPayment received, login alerts, offers
SMSAn SMS gateway or aggregator, which talks to the mobile operatorsThe phone numberOTPs, and anything that must reach people without the app
EmailAn email provider (your own mail servers or a sending service)A verified email addressReceipts, statements, long messages
In-app inboxNobody: it’s a row in your own databaseJust the user IDA 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.

  1. Producers (payments, login, marketing) publish an event like payment.received or call the notification API. They never call Apple or the SMS gateway themselves.
  2. 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.
  3. 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.
  4. Workers call the outside provider.
  5. 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.

Event
User

Example rules. Every app sets its own, but they always depend on both event and user.

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?

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.