High-Throughput Alert Delivery Pipeline for Spiky Traffic
System DesignModel answerLast updated
Design a multi-channel alert delivery platform that survives spikes of roughly one million writes per second, with a justified storage engine and protection against duplicate sends.
You are asked to design a platform that sends alerts to end users (think push, email, SMS and an in-app inbox). Upstream services call it whenever something happens that a user should hear about. At peak, the platform has to accept roughly 1 million writes per second, and that load arrives in bursts, not as a steady stream.
The full requirements list is not provided. Either confirm the assumptions below with your interviewer or state your own, and say why they matter.
Given
- Peak write rate is about 1 million writes per second and is spiky.
- Average rate, retention, supported channels and delivery guarantees are unspecified. Ask, or assume and justify.
Questions worth asking
- What exactly is a "write": an upstream request, a per-recipient record, or a delivery-status update?
- Which channels are in scope?
- Is delivery at-least-once with deduplication, or at-most-once? What latency is required, and does it vary by priority?
- Are there user preferences, quiet hours, rate limits or priority tiers (security alerts versus marketing)?
- Can users read past notifications, and for how long?
- What is the peak-to-average ratio, and how long does a burst last?
Part 1: Requirements and scale
List functional and non-functional requirements, estimate throughput, bandwidth and storage from the 1M/s peak, describe the traffic shape, and state which components are sized for peak and which for average.
Part 2: Absorbing bursty writes
Design the ingestion and storage path. Cover a durable partitioned buffer between the API and the workers, partition keys, backpressure, and a data model that avoids hot partitions. If you pick a wide-column store such as Cassandra, explain why its writes are fast and what that costs on the read side.
Part 3: Delivery and deduplication
Design delivery to each channel and ensure a user does not receive the same alert twice when requests or retries are duplicated. Cover idempotency keys, a dedup window and its memory cost, at-least-once processing with idempotent consumers, provider rate limits, retries with backoff, a dead-letter queue, preferences, and priority isolation during bursts.
Hints
Hint 1
Separate acceptance from delivery: the API only needs to durably append the request to a partitioned log and acknowledge, so the burst is absorbed by the log, and workers drain it at a rate downstream providers can tolerate.
Hint 2
A log-structured store turns every write into a commit-log append plus an in-memory table insert, deferring sorting and merging to background flushes and compaction. Think about what that does to read amplification, tombstones and partition design.
Hint 3
You cannot get exactly-once across an external provider, so aim for at-least-once plus idempotency: a deterministic key per (alert, recipient, channel), an atomic set-if-absent check with a TTL, and a durable delivery-state record as the source of truth.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Requirements and estimates
Functional
- Accept alert requests from internal services via API (single and batch).
- Fan out to channels: mobile push, email, SMS, in-app inbox.
- Honor user preferences (opt-outs, quiet hours, per-channel choices) and per-user rate limits.
- Priority tiers: critical (security, OTP), normal (transactional), bulk (marketing).
- Track delivery state (queued, sent, delivered, failed) and expose an inbox read API.
Non-functional
- Durability: once the API acknowledges, the alert is never lost.
- Latency: critical under a few seconds end to end; bulk can lag minutes.
- Availability: ingestion stays up even when providers are down.
- No duplicates visible to the user; at-least-once internally.
- Horizontal scalability and good observability.
Estimates (stated assumptions)
- Peak 1M writes/s, average maybe 100k/s, bursts lasting 1 to 5 minutes (10x ratio).
- Record size about 1 KB: peak ingest is about 1 GB/s. A 5-minute burst is about 300 GB.
- If 1M/s is sustained for a fraction of the day, say 100k/s average, that is about 8.6B records/day, about 8.6 TB/day raw; with 30-day retention and RF=3, roughly 770 TB. This is why retention and TTL must be explicit.
- Size the ingestion tier and log for peak; size workers and providers for something closer to average plus a drain budget, accepting that bulk lags during bursts.
2. Absorbing bursts
Write path: client service, then stateless API (validate, authenticate, assign ID, apply idempotency check), then a durable partitioned log (Kafka-style), then ack. Everything else is asynchronous.
- Buffer sizing: 1 GB/s at RF=3 needs about 3 GB/s of disk write across the cluster. At roughly 100 MB/s useful per broker, that is 30+ brokers; add headroom. Retain at least a few hours so the log can hold a burst plus downstream outages.
- Partitioning: key by recipient user ID so per-user ordering and per-user rate limiting are local. Use enough partitions (hundreds to thousands) for consumer parallelism. Beware one celebrity or one broadcast skewing a partition; split broadcast jobs into batches and fan out inside the pipeline, not at the API.
- Separate topics per priority so a marketing burst cannot starve security alerts. Consumers for critical topics get reserved capacity.
- Backpressure: producers get ack only after replication (acks=all). If the log is near capacity, shed or throttle lowest priority at the API with 429 and a Retry-After, never critical.
Storage (inbox and delivery state): Cassandra or a similar wide-column store.
- Data model: partition key
(user_id, time_bucket), clustering bycreated_at DESC, alert_id. The bucket (for example a day or week) bounds partition size. Delivery-state rows can be keyed by(alert_id)or stored as columns on the same row. - Why writes are fast: a write is appended to the commit log (sequential I/O) and inserted into an in-memory memtable; no read-before-write, no in-place update, no random disk seek. Memtables are flushed as immutable sorted SSTables, and replication is leaderless so any replica can accept writes. Throughput scales linearly by adding nodes. Tunable consistency (for example LOCAL_QUORUM) balances durability and latency.
- What it costs on reads: a row can be spread across the memtable and several SSTables, so reads merge multiple sources (read amplification). Bloom filters and key caches reduce but do not remove this. Compaction consumes disk and I/O in the background and can hurt tail latency if under-provisioned. Updates and deletes create tombstones, which slow reads if TTLs are used carelessly; use time-window compaction for TTL'd data. Ad hoc queries and secondary indexes are poor, so model tables around query patterns (inbox by user, status by alert).
- Sizing: at about 50k to 100k writes/s per node with RF=3, 1M/s peak needs roughly 30 to 60 nodes. Writes from workers can be batched and smoothed, so the DB sees less than the raw spike.
3. Delivery and deduplication
Workers: per-channel consumer groups read from the log, check preferences (cached, with invalidation), apply quiet hours and per-user limits, render templates, and call providers (APNs/FCM, email, SMS gateways).
Provider limits: token-bucket rate limiters per provider and per tenant. When limits bind, consumers slow down and lag accumulates in the log, which is the intended burst buffer.
Retries: exponential backoff with jitter on transient errors; after N attempts, send to a dead-letter queue with the error for inspection and replay. Use circuit breakers to stop hammering a failing provider and fail over to a secondary where possible.
Deduplication
- Callers supply an idempotency key, or the system derives one:
hash(source_event_id, recipient, channel). - At the API: atomic
SET key NX EX ttlin a Redis-style cache. If it exists, return the original response. - Memory: 1M keys/s with a 24-hour window is 86B keys; at about 50 bytes each that is about 4 TB, so shorten the window (for example 10 to 60 minutes: 60M to 3.6B keys, a few GB to about 180 GB), shard the cache, or use a Bloom filter or compact fingerprints. Choose the window from the realistic retry horizon.
- At the worker: before sending, conditionally write delivery state (
INSERT ... IF NOT EXISTSor a compare-and-set) to claim the alert. Cache is an optimization; the durable state is the source of truth. - Exactly-once with an external provider is impossible (the call can succeed and the ack be lost), so use at-least-once plus idempotent consumers, and pass the provider's own idempotency or collapse key (for example the push collapse ID) when available.
Priority isolation: separate topics, consumer pools and provider quotas per tier; critical traffic has reserved capacity and bypasses bulk queues.
Observability: consumer lag per topic, end-to-end latency percentiles by priority, dedup hit rate, provider error rates, DLQ depth, compaction backlog. Alert on lag growth exceeding the drain-time budget.
Common mistakes
- Writing directly from the API to the database, so a burst becomes a database outage.
- Claiming exactly-once delivery without explaining the provider boundary.
- Hot partitions from keying on a low-cardinality field or an unbounded user partition.
- Ignoring dedup memory cost or choosing a window with no justification.
- One shared queue for all priorities.
- Praising Cassandra writes without acknowledging read, compaction and tombstone costs.