Mahir Shahriar Tamim

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

Part 5 of Building a Notification Service

Watching it run, and sizing it

Module 5 · 4 min read

Watching it run, and sizing it

TL;DR

  • This service fails quietly. Watch delivery rates and OTP latency, split by provider and type, because “accepted” proves little.
  • Record every state change as an event with a trace ID.
  • SMS is where the money goes. At scale the limits are the gateway contract and log storage, and Kafka is rarely the problem.

“Is it working?” is a hard question

Nothing crashes when the SMS gateway starts delivering only 70% of messages, push tokens slowly go stale, or OTPs take 40 seconds instead of 4. Users just stop getting messages, and the first sign is a support ticket. So the service has to watch itself, and the questions are different from a normal web API.

The numbers that matter

MetricWhat it tells youAlert when
Consumer lag per topicHow far each channel’s workers are behindOTP lag above a few seconds; bulk lag not shrinking
End-to-end latencyTime from the event happening to the provider accepting the message (p50, p95, p99)OTP p95 above your target
Provider success rateShare of calls each provider acceptsA sudden drop for one provider
Delivery rate (DLRs)Share of accepted SMS that actually reached a phoneA drop, even while “accepted” looks fine
Expired before sendOTPs that were too late to be usefulAnything above zero, sustained
Dead-letter countMessages that gave upGrowth
Invalid tokens and numbersHow stale your contact data isA spike after an app release
Cost per day per channelMoneyAn unexpected jump (bug or fraud)

Split every metric by provider and by notification type, because “SMS success 97%” can hide “OTP through gateway B: 60%”. If I had to pick one dashboard to build first, it’s OTP latency and delivery rate per provider. A slow OTP is what users notice first, and it locks them out of the app.

Tracking the life of a message

I record each state change as an event,

queuedsentdeliveredopened

with side exits to failed, expired and dead-lettered. Providers report delivery later (SMS delivery receipts, email bounce webhooks), and the app reports “opened” when a user taps a push. As events in Kafka, these feed per-campaign open rates. They also let support answer “did user X get the OTP at 10:42?” in seconds, by following one trace ID carried from the original payment event through every hop, instead of grepping five services.

SMS is where the money goes

Push is close to free and email is cheap. SMS is billed per message, and long messages per part. Accented or non-Latin text needs Unicode encoding, which fits far fewer characters per part, so the same text can cost two or three times as much. A few habits help.

  • Use push and the inbox when the app is installed, and SMS only when needed.
  • Keep SMS templates short, and check their length in each language when they’re written. The bill is a bad place to find out.
  • Deduplicate and rate-limit (module 4). A retry bug at scale is a very expensive bug.

Sizing it, a worked example

Say, with illustrative numbers, 5 million daily active users, about 4 notifications each per day, 10% by SMS, and a peak of 10× the average rate. That’s 20 million notifications a day, about 230 a second on average (a day has 86,400 seconds) and 2,300 at peak. Kafka handles that easily. The real limits are elsewhere.

  • 230 SMS a second at peak must fit the gateway contract, with room left for OTPs.
  • At roughly 500 bytes a row, the log grows about 10 GB a day, close to a terabyte over 90 days. It needs date partitioning and a plan for old data.
Every input is an assumption, and so is the 500 bytes per log row. Multiply honestly, then look for the number that hurts.

Scaling each part

  • Workers scale out per channel. Kafka’s partition count caps how many consumers can share a topic, so give busy topics enough partitions up front.
  • Providers don’t scale just because you want them to. Know your contracted rates and build the limits in.
  • Lookups of preferences and device tokens happen per message, so cache them near the workers and invalidate on settings changes.
  • Campaigns are the peak. Traffic follows people (salary day, festivals, evenings), but one campaign decision creates millions of messages at once, so spread sends out on purpose. Planning for the average is planning to fall over.

Quick check

The SMS gateway reports 99% of requests accepted, but users say OTPs never arrive. Which metric would have caught this?

Q&A

Can I know whether a push notification was delivered?

Not reliably. Apple and Google accept the message but don’t confirm delivery. The app can report when a notification is received or opened, which gives you a lower bound. One more reason to keep the in-app inbox.

Where should the notification log live?

Anywhere that handles lots of writes and lookups by ID. A relational database partitioned by date works for moderate volumes, a wide-column store for very high ones. Keep recent data fast and move old data to cheaper storage.