Design a Push Notification Delivery Service
System DesignModel answerLast updated
Design a scalable backend service that reliably delivers push notifications to millions of mobile and web users with low latency.
Background
You are a backend engineer at a mid-sized consumer app (think a social or e-commerce product). The product team wants to send push notifications — new messages, order updates, promotional alerts — to users across iOS, Android, and web browsers.
Today the app has 10 million registered users, roughly 2 million daily active users, and expects to send up to 5 million push notifications per day with occasional spikes of ~50,000 notifications per minute during flash sales.
What You Are Asked To Do
Design a push notification delivery service from scratch. Walk through:
- Requirements & scale — clarify functional and non-functional requirements, back-of-envelope numbers.
- API design — what endpoints or interfaces does the service expose internally?
- Data model — what tables or documents do you need?
- High-level architecture — components, their responsibilities, and how they connect.
- Deep dives — at least two: delivery guarantees and handling third-party provider failures.
- Trade-offs — discuss at least one key design choice you made and why.
You do not need to design the client SDK. Focus on the backend service.
Hints
Hint 1
What state do you need to store per user, per device? A user may have multiple devices.
Hint 2
Push notifications ultimately go through Apple APNs, Google FCM, or browser Web Push — how does your service interact with these, and what happens when they are slow or unavailable?
Hint 3
Think about what 'at-least-once' vs 'at-most-once' delivery means for notifications — a duplicate promotional alert is annoying; a missing order confirmation is worse.
Model answer
Easy Try it yourself first — then compare your approach, complexity and edge cases.
1. Requirements & Scale
Functional
- Send a push notification to one user, a segment of users, or all users (broadcast).
- Support iOS (APNs), Android (FCM), and web (Web Push).
- Track delivery status: queued, sent to provider, delivered, failed.
- Allow callers to schedule notifications for a future time.
Non-functional
- P99 latency from API call to handoff to provider: < 5 seconds.
- At-least-once delivery with deduplication on retry.
- High availability (99.9% uptime target).
- No strict ordering required between different users.
Back-of-envelope
- 5 million notifications/day ≈ 58/sec average; spike ≈ 50,000/min ≈ 833/sec.
- Each notification payload ≈ 1 KB → 5 GB/day write volume, very manageable.
- Device token records: 10M users × ~1.5 devices avg = 15M rows, fits in a single relational DB with proper indexing.
2. API Design (Internal)
Send notification — called by other backend services (order service, messaging service, etc.)
POST /v1/notifications
{
"recipient": { "user_id": "u_123" }, // or segment_id / "all"
"template_id": "order_shipped",
"params": { "order_id": "o_456" },
"priority": "high" | "normal",
"schedule_at": "2024-06-01T10:00:00Z" // optional
}
→ 202 Accepted { "notification_id": "n_789" }
Get status
GET /v1/notifications/{notification_id}
→ { "status": "delivered", "sent_at": "...", "failed_devices": 0 }
Callers get an immediate 202; delivery is asynchronous.
3. Data Model
devices table — one row per device token
| Column | Type | Notes |
|---|---|---|
| device_id | UUID PK | |
| user_id | UUID | FK, indexed |
| platform | ENUM(ios, android, web) | |
| token | TEXT | APNs/FCM token |
| token_updated_at | TIMESTAMP | Tokens rotate; keep fresh |
| active | BOOLEAN | Set false on provider 410/404 |
notifications table — one row per send request
| Column | Type |
|---|---|
| notification_id | UUID PK |
| recipient_type | ENUM(user, segment, broadcast) |
| recipient_ref | TEXT |
| template_id | TEXT |
| params | JSONB |
| status | ENUM(queued, processing, done, failed) |
| schedule_at | TIMESTAMP |
| created_at | TIMESTAMP |
notification_attempts table — one row per device per attempt
| Column | Type |
|---|---|
| attempt_id | UUID PK |
| notification_id | UUID |
| device_id | UUID |
| status | ENUM(sent, delivered, failed, unregistered) |
| provider_message_id | TEXT |
| attempted_at | TIMESTAMP |
4. High-Level Architecture
Caller Services
│ POST /v1/notifications
▼
[Notification API] ──writes──▶ [notifications table]
│
└──publishes──▶ [Message Queue (e.g. Kafka topic: notif-jobs)]
│
┌─────────▼──────────┐
│ Fanout Workers │ (expand segment → device list)
└─────────┬──────────┘
│ one message per device
┌─────────▼──────────┐
│ Delivery Workers │ (read device token, call provider)
└──────┬──────┬──────┘
│ │
[APNs] [FCM / Web Push]
│ │
┌──────▼──────▼──────┐
│ Status Writer │ (update notification_attempts)
└────────────────────┘
Component responsibilities:
- Notification API: validates, persists the job, publishes to queue. Stateless, horizontally scalable.
- Fanout Workers: resolve
user_id → [device_id, ...]or expand segments. For broadcast, pages through the devices table. Emits one delivery message per device. - Delivery Workers: the hot path. Pull from queue, look up fresh token, call the appropriate provider SDK, write result. Scaled to handle the spike (833/sec requires only a handful of workers given provider round-trip of ~200ms each).
- Scheduler: a lightweight cron-like process that polls
notificationswhereschedule_at <= now()andstatus = queued, then publishes to the queue.
5. Deep Dives
Delivery Guarantees
The queue provides at-least-once semantics. A Delivery Worker acks the message only after writing a successful attempt to the DB. On crash before ack, the message is redelivered — this may cause a duplicate send to the provider.
To avoid sending the same promotional push twice: before calling the provider, the worker does an idempotency check on (notification_id, device_id) in notification_attempts. If a sent or delivered row already exists, skip and ack.
Order confirmations are marked priority: high and get a dedicated higher-priority queue partition with no batching delay.
Handling Provider Failures (APNs / FCM)
Providers fail in two ways:
-
Transient errors (5xx, timeout): Retry with exponential backoff (1s, 2s, 4s, cap at 60s) up to 5 attempts. After max retries, mark status
failedand emit a metric alert. -
Token invalidation (APNs 410, FCM
NotRegistered): The device has uninstalled the app. Immediately setdevices.active = false. Never call the provider for that token again until a fresh token is registered by the client. This keeps your provider account in good standing and avoids wasted quota.
Add a circuit breaker per provider: if error rate exceeds 50% over a 30-second window, stop sending to that provider and queue messages in a holding area for up to 5 minutes before retrying. This prevents cascading retries from overwhelming a struggling provider.
6. Key Trade-off: Push vs Pull Fanout
Choice made: fan out to per-device messages inside the pipeline (push fanout), rather than letting each Delivery Worker look up devices itself.
- Pro: Delivery Workers stay simple and stateless; each handles exactly one device.
- Con: For a broadcast to 10M users, the Fanout Worker produces 15M queue messages. This is fine at this scale (Kafka handles it), but for much larger scales you would shard fanout by user_id range.
An alternative is storing the segment resolution lazily and doing per-device lookup inside the Delivery Worker — this reduces queue depth but creates hot spots on the devices table during large campaigns.
At 10M users the push-fanout approach is simpler to reason about and operate.
Common Mistakes to Avoid
- Storing only one token per user — users have multiple devices; model this from day one.
- Synchronous provider calls in the API handler — APNs/FCM latency will cascade into your callers; always go async via a queue.
- Ignoring token rotation — tokens expire or change; failure to update them leads to growing silent failures and eventual provider throttling.
- No status tracking — without
notification_attempts, debugging delivery failures is nearly impossible.