Case study: Notification system

Topic 5 of 15 in Week 7: Classic case studies13 min readIntermediateFree course

Overview

Every product sends notifications: one-time passwords, order updates, chat messages, marketing campaigns. Building that separately in every team leads to duplicated work and spammy, inconsistent experiences. A central notification platform gives one reliable path to push, SMS and email.

Try the exercise first: 45 minutes, then compare.

1. Requirements

Functional

  • Send notifications through push (iOS, Android), SMS and email, to one user or to large segments.
  • Templates with parameters and multiple languages.
  • Respect user preferences (opt-outs per channel and category), quiet hours and frequency limits.
  • Scheduling (“send at 9 a.m. local time”) and delivery status tracking.

Non-functional

  • Reliable: no lost transactional notifications; duplicates minimised.
  • Low latency for urgent messages (OTP within seconds), even during big campaigns.
  • Scales to spikes of a million messages in minutes.
  • Pluggable providers with failover.

2. Estimates

Text
average : 10M / day ≈ 115 / s
spikes  : 1M in ~5 min ≈ 3,300 / s  (provider rate limits matter more than our servers)
storage : status events ~5 per notification × 10M × ~200 B ≈ 10 GB / day

3. API

Text
POST /v1/notifications
{
  "idempotency_key": "order-981-shipped",
  "user_ids": ["u42"], "segment": null,
  "category": "order_updates", "template": "order_shipped",
  "params": {"order_id": "981"}, "channels": ["push", "email"],
  "priority": "high", "send_at": null
}
→ 202 {"notification_id": "n_7f3c…"}

GET /v1/notifications/{id} → status per channel

4. Data model

Text
user_preferences: user_id | category | channel | enabled | quiet_hours | locale | timezone
devices:          user_id | platform | device_token | last_seen
templates:        template_id | channel | locale | version | body
notifications:    notification_id | idempotency_key (unique) | request | created_at
delivery_events:  notification_id | channel | status | provider_id | timestamp

5. High-level design

Notification system. Services from any team call the notification API, which validates and rate-limits requests and checks a preferences store for opt-outs and devices. The API puts work on a push queue, an SMS queue and an email queue. Workers for each queue call the matching provider: APNs and FCM for push, an SMS provider and an email provider, retrying with backoff and sending persistent failures to a dead-letter queue. The platform renders per-language templates, deduplicates by notification ID and respects quiet hours and limits. Delivery is at least once with idempotency keys, and sent, delivered and opened statuses are tracked per notification for analytics.

  1. The API authenticates the calling team, validates the request, stores it with its idempotency key and returns 202 quickly.
  2. It resolves recipients (expanding segments in batches for campaigns), applies preferences, quiet hours and frequency caps.
  3. It enqueues one message per user per channel into channel- and priority-specific queues.
  4. Channel workers render the template in the user’s language, call the provider, and record the outcome.

6. Deep dives

Why separate queues

If SMS and push share one queue, a slow or rate-limited SMS provider delays push notifications too. If campaigns and OTPs share a queue, a 1-million-message campaign delays a login code by minutes. Separate queues per channel and per priority isolate them, and each worker pool scales independently.

Talking to providers

  • Respect each provider’s rate limits with a token bucket per provider.
  • Retry transient errors (timeouts, 5xx, 429) with exponential backoff and jitter; send permanent failures (invalid number, unregistered device) to the status log and clean up bad tokens.
  • Keep a backup provider for SMS and email and fail over when error rates spike.
  • Persistent failures go to a dead-letter queue with alerts.

Deduplication

Queues deliver at least once, and callers may retry. The idempotency key on the API makes repeated requests return the same notification. Workers record (notification_id, channel) as sent (with a unique constraint or a short-lived Redis key) before or atomically with the provider call, and pass a provider-side idempotency key where supported.

Preferences, quiet hours and fatigue

Check preferences at send time, not only at request time (users may opt out in between). Delay non-urgent messages that fall in quiet hours to the user’s morning; urgent categories (security alerts) bypass. Frequency caps (“no more than 3 marketing pushes per day”) use per-user counters.

Campaign spikes

Large sends are expanded by a fan-out job that reads the segment in batches and enqueues messages gradually at a rate the providers accept. Scheduled sends are stored and released by a scheduler at the right local time.

Tracking

Workers emit status events (queued, sent, failed); providers report delivered and opened through callbacks and webhooks. Events go to a log or stream and are aggregated for dashboards and for teams’ GET status calls.

7. Trade-offs and bottlenecks

  • Provider throughput, not our servers, usually limits campaign speed.
  • At-least-once delivery means rare duplicates if a provider call succeeds but the record fails; idempotency keys reduce this.
  • Checking preferences per message adds lookups; cache preferences with short TTLs.

8. Follow-up questions

  • In-app notification inbox? Store notifications per user in a wide-column table; the app fetches and marks read.
  • Real-time in-app delivery? Push over existing WebSocket connections when the user is online.
  • Localization of times and content? Store user locale and timezone; render server-side.

Recap

A notification platform accepts requests through one asynchronous API, applies preferences and limits, and fans messages out into channel- and priority-specific queues. Workers render templates and call third-party providers with rate limits, retries, failover and dead-letter queues. Idempotency keys and per-message records handle duplicates, and status events give teams visibility into delivery.

Exercise

Design it yourself (45 minutes)

Set a 45-minute timer and design a notification platform used by all teams in a company: it sends push notifications, SMS and email; respects user preferences and quiet hours; supports templates in multiple languages; handles 10 million notifications per day with spikes of 1 million in a few minutes for marketing campaigns; and reports delivery status. Use the framework, then compare.

Text
1. Clarifying questions:
2. Functional requirements:
3. Non-functional requirements:
4. Estimates:
5. API:
6. Data model:
7. High-level design:
8. Deep dives (queues per channel, retries, dedupe, priorities):
9. Trade-offs and bottlenecks:

Summary

  • Offer one asynchronous API to all teams; validate, apply preferences and enqueue quickly.
  • Use separate queues and workers per channel and priority so slow providers or campaigns don't delay urgent messages.
  • Workers call third-party providers with retries, backoff, provider rate limits, failover and dead-letter queues.
  • Deliver at least once and deduplicate with notification IDs and idempotency keys.
  • Respect user preferences, quiet hours and per-user frequency caps, and track delivery status.