Building a Reliable Multi-Channel Alert Pipeline With Safe Retries
System DesignModel answerLast updated
Design an alert platform that never silently drops a message, tolerates retries and reordering, and keeps users from seeing repeats across push, email, SMS and in-app channels.
Reliable Alert Delivery Platform
Your company runs many internal services (orders, payments, social features) that need to alert end users through mobile push, email, SMS and an in-app inbox. You are asked to design the shared platform that does this.
Required guarantees
- Once the platform accepts an alert, it must eventually be delivered or explicitly moved to a failure store. Nothing may vanish silently.
- Users should not experience duplicates, even though the platform retries internally.
- A stale alert must not appear after a newer one about the same entity (for example, "Order shipped" must not show up after "Order delivered").
Scale assumptions (adjust if you justify it)
- About 1 billion users and 10 billion alerts per day, with roughly 5x peak over average.
- Accept latency in the tens of milliseconds; high-priority delivery within a few seconds at p99.
What to cover
- The interface producers use to submit alerts, including how they identify a logical alert so retries are safe.
- The interface a channel worker implements, and when it acknowledges a queue message.
- Deduplication keys, and at which layers duplicates can enter.
- Retry policy with exponential backoff, error classification and terminal handling.
- How to cope with out-of-order arrival.
- What the user sees: how you keep the experience duplicate-free despite at-least-once internals.
- Scaling, storage choices and the main trade-offs.
Hints
Hint 1
Begin by stating what is and is not achievable over unreliable networks and third-party providers. This points you toward at-least-once delivery combined with idempotent handling.
Hint 2
List every place a duplicate can originate: producer retries, queue redelivery, a worker crashing after calling the provider but before recording success, and the client display. Give each its own key or mechanism.
Hint 3
For ordering, attach a monotonically increasing version per entity and keep the highest version already delivered per user and entity, so late arrivals can be recognized and dropped or folded in.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Core principle
Exactly-once delivery is not attainable across networks and third-party providers (APNs, FCM, SMS gateways, email relays). The realistic target is at-least-once delivery plus idempotent handling, which yields "effectively once" for the user. I would say this first, then show where duplicates arise and neutralize them at every layer.
Requirements and scale
- Functional: multi-channel sends, no silent loss, no visible duplicates, no stale-after-fresh display.
- Numbers: 10B/day is about 115k/s average and roughly 600k/s at peak.
- Durability: once the producer sees
ACCEPTED, the alert survives a single node or zone failure. - Dedup window of 24-48 hours: about 10B keys/day at ~100 B each is around 1 TB/day, so a sharded key-value store with TTL (Bigtable, Spanner, Redis Cluster, DynamoDB).
Producer interface
POST /v1/alerts
{
"idempotency_key": "orders:order-123:shipped",
"user_id": "u_42",
"type": "ORDER_STATUS",
"entity_id": "order-123",
"entity_version": 7,
"channels": ["push", "inbox"],
"priority": "HIGH",
"payload": {...},
"expires_at": "..."
}
-> 202 { "alert_id": "a_abc", "status": "ACCEPTED" | "DUPLICATE" }
- The producer retries until it receives a 2xx, always reusing the same
idempotency_key. - Ingest performs an atomic insert-if-absent on
(producer_id, idempotency_key). Only the winner persists and publishes; a loser getsDUPLICATEwith the originalalert_id. - Producers that emit from a database transaction use a transactional outbox: the alert row commits with the business change and a relay publishes it, closing the "committed but crashed before sending" hole.
Worker interface
Result handle(DeliveryTask t) // idempotent
Result = ACK | RETRY(after) | DROP_STALE | FAIL_PERMANENT
The worker acks the queue message only after the outcome is durably recorded. A crash before the ack causes redelivery, which is what at-least-once means, and idempotent handle makes it harmless.
Architecture
Producers -> Ingest API (dedup insert) -> alerts store
-> durable log partitioned by user_id
-> fan-out (preferences, devices, rate limits)
-> per-channel topics: push | email | sms | inbox
-> channel workers -> providers
|-> retry tiers (5s, 30s, 5m, 1h) -> DLQ + alerting
Partitioning by user_id keeps most per-user events ordered, but retries reorder things anyway, so ordering is handled explicitly.
Data model
| Store | Key | Notes |
|---|---|---|
| dedup | (producer, idempotency_key) | maps to alert_id, TTL 48h |
| alerts | alert_id | payload, status |
| deliveries | (alert_id, channel, device) | state, attempts, lease_until, next_attempt_at, provider_msg_id |
| entity_state | (user_id, entity_id) | highest version delivered |
| inbox | (user_id, alert_id) | upsert target |
Deduplication at each layer
- Producer retry: the idempotency key at ingest.
- Queue redelivery: the delivery row keyed by
(alert_id, channel, device). The worker does a compare-and-set PENDING to IN_FLIGHT with a lease. If SENT, ack and skip. If IN_FLIGHT with a live lease, skip. If the lease expired, assume a crash and take over. - Provider: pass a stable identifier so the provider collapses repeats (APNs collapse id, FCM collapse key, email Message-ID).
- Client: keep a small recent-ID cache and drop repeats. The inbox write is an upsert on
alert_id.
The unavoidable window
A worker may call the provider successfully and crash before marking SENT. The retry then sends again, and no server-side protocol can fully close this gap. Layers 3 and 4 absorb these rare duplicates. Stating this honestly is the key insight.
Retries
delay = min(cap, base * 2^attempt) * random(0.5, 1.0), e.g. base 1 s, cap 1 h.
- Jitter prevents synchronized retry storms after a provider outage.
- Classify errors: retry on 5xx, timeouts, 429 (honor
Retry-After); fail permanently on invalid or unregistered tokens and deactivate the device. - Never sleep in a worker. Re-enqueue into delay tiers or a table indexed by
next_attempt_atthat a scheduler scans, so partitions are not blocked. - Stop after a max attempt count or when
expires_atpasses; send to the DLQ, record the failure, and alert on DLQ growth. Provide a replay tool for the DLQ. - Add per-provider circuit breakers and rate limiters so a failing provider does not exhaust workers.
Out-of-order handling
- Each alert carries
entity_idand a monotonicentity_version. - Before sending or rendering, compare with
entity_state.max_version_delivered. If the incoming version is lower, returnDROP_STALE(or write it to the inbox history without a push). - Update the max with a conditional write so concurrent workers cannot regress it.
- If producers lack versions, fall back to event timestamps from the source of truth, accepting some clock-skew risk.
- Some alerts (e.g., "message received") are not supersedable; only apply version checks to types that declare an entity.
User-facing idempotency
- Stable
alert_idflows end to end, so the inbox is an upsert and the client dedups on it. - Collapse keys let a newer push replace an older undelivered one.
- Per-user rate limits and digesting reduce noise from bursts.
Scaling and trade-offs
- Shard everything by
user_id; scale partitions and workers independently per channel. - Separate priority lanes so bulk campaigns cannot starve transactional alerts.
- Multi-tenant fairness: per-producer quotas and per-tenant queues or weighted scheduling.
- Trade-off: a longer dedup window costs storage; a shorter one risks duplicates from very late producer retries.
- Trade-off: strict per-user ordering (single in-flight per entity) lowers throughput; version checks give most of the benefit cheaply.
- Observability: end-to-end latency, retry rate, DLQ depth, duplicate-suppression counts, and provider error rates by class.
Common mistakes
- Claiming exactly-once delivery.
- Acking the queue message before the side effect is recorded (causes loss).
- Retrying without jitter or a cap.
- Sleeping inside workers.
- Retrying permanent errors forever.
- Relying only on partition ordering and ignoring retry reordering.
- Having only one dedup layer.