Scalable Notification Platform for Large-Scale Event Reminders
System DesignModel answerLast updated
Design a platform that tracks a million active events and reliably emails every registrant about reminders, changes, cancellations and follow-ups, covering scale, delivery guarantees and compliance.
Problem
You are building the backend for a platform where organizers publish events and attendees sign up. The platform must keep at least 1,000,000 events active at the same time and email every registered attendee of an event when something relevant happens: an upcoming-event reminder, a time or venue change, a cancellation, or a post-event thank-you.
Present an end-to-end design. Your answer should cover:
- APIs. Create, modify and cancel an event; register or remove an attendee; schedule an email or send one immediately. Explain how writes stay idempotent.
- Architecture. The services and queue/topic layout that convert one event-level trigger into many per-recipient emails.
- Data and storage. Schemas, indexes, sharding, retention, and where you would choose relational versus NoSQL stores.
- Delivery pipeline. Producers, queues, consumers, fan-out, batching, retries, dedup keys, and handling of bounces and spam complaints reported by an email service provider (ESP).
- Capacity math. Request rates, recipients per event, and peak emails per second, with the arithmetic shown.
- Scaling. Partitioning, autoscaling workers, and backpressure.
- Scheduling. Time-based reminders versus event-driven triggers, a distributed scheduler, and how to avoid load spikes when many reminders share the same instant.
- Throttling and quotas. Limits per tenant, per ESP, and per recipient domain.
- Delivery semantics. At-least-once versus exactly-once, dead-letter queues, and replay.
- Reliability. Backoff, the transactional outbox, and recovery after a regional failure or provider throttling.
- Observability. Metrics, SLOs, tracing, alerts.
- Compliance and abuse. Unsubscribes, suppression lists, double opt-in, CAN-SPAM and GDPR.
- Multi-region and disaster recovery, including the consistency trade-offs.
- Cost. A rough estimate and managed versus self-hosted options.
Finish by walking through one concrete failure (for example, a regional outage or the ESP throttling you) and describing how the system degrades and then recovers.
Hints
Hint 1
Start with numbers: events x average registrants x emails per registrant gives monthly volume, then apply a burst multiplier (round-hour reminders, a mass cancellation) to get peak emails per second. The real challenge is bursty fan-out, not storage.
Hint 2
Separate the pipeline into stages joined by durable queues: trigger -> fan-out (paginated reads of registrants with a checkpointed cursor) -> per-recipient send jobs -> ESP. Use a transactional outbox so the event change and its notification trigger are committed atomically.
Hint 3
Accept at-least-once delivery and make consumers idempotent with a deterministic message key (campaign + registration) and a conditional insert into a send log. Treat cancellations as a high-priority path and reminders as latency-tolerant so they can be jittered and throttled.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Requirements and assumptions
Functional: manage events, manage registrations, send scheduled emails (e.g. 7 days, 24 hours and 1 hour before, plus a follow-up), and send triggered emails (change, cancellation).
Non-functional:
- 1M active events, many tenants.
- A cancellation or change notice must never be lost; an occasional duplicate is acceptable.
- Reminders land within roughly 5 minutes of target time; triggered mail within a few minutes.
- CAN-SPAM and GDPR compliance.
2. Capacity estimates
| Item | Math | Result |
|---|---|---|
| Registrations | 1M events x ~200 average (long tail to 100k) | ~200M rows |
| Emails | ~5 per registration (confirmation, 3 reminders, follow-up) | ~1B per 30-day cycle |
| Average rate | 1B / 30 days / 86,400 s | ~400/s |
| Peak rate | 25-30x average: reminders cluster on the hour, one 100k-seat cancellation | ~10-15k/s |
| Registration writes | 200M / 30 days | ~80/s average, 5-10k/s on-sale spikes |
| Storage | 300 B x 200M registrations; 200 B x 1B send-log rows/month | ~60 GB; ~200 GB/month |
Conclusion: the hard parts are fan-out and burst smoothing, not data volume.
3. APIs
Every mutating call carries an Idempotency-Key. The server stores (tenant, key) -> response for about 24 hours and replays it on retry.
POST /events -> event_id
PATCH /events/{id} (with version; optimistic locking)
POST /events/{id}/cancel
POST /events/{id}/participants {email, consent} -> registration_id
DELETE /events/{id}/participants/{rid}
POST /events/{id}/notifications {template, type, send_at|null, audience} -> campaign_id
GET /notifications/{campaign_id} -> status and counters
4. Data model
- Relational (sharded Postgres / Vitess / Aurora) for
events,registrations,campaigns,outbox. ACID is needed for the event-plus-outbox transaction. Shard byevent_idso fan-out for one event is a single-shard range scan. A separate lookup by email supports GDPR erasure. - Send log (Cassandra or DynamoDB): key
message_id = hash(campaign_id, registration_id); fields for status, ESP id, timestamps. Write-heavy and append-mostly; 90-day TTL, with aggregates archived to object storage. - Suppression list: key-value keyed by
(tenant, hash(email)), cached in Redis, kept indefinitely because it is a legal record. - Scheduler table: due-work rows bucketed by
send_minute.
5. Architecture and pipeline
API -> Event service (DB + outbox) -> CDC relay -> Kafka: campaign-triggers
Scheduler ------------------------------------> Kafka: campaign-triggers
Fan-out workers: page registrants (1k) -> Kafka: email-jobs (keyed by recipient domain)
Send workers: dedup -> suppression -> render -> rate limit -> ESP batch call
ESP webhooks -> feedback service -> suppression + send log
Retry topics (1m, 10m, 1h) -> DLQ
- Outbox. The event update and its outbox row commit in one transaction; a CDC relay publishes to Kafka. This removes the dual-write problem.
- Fan-out. A worker reads registrants in pages and emits batch jobs, checkpointing its cursor in the campaign row so a crash resumes mid-event.
- Send. Compute the deterministic
message_id, do a conditional insert into the send log (skip if present), check suppression, render, then submit to the ESP in batches (often up to ~1,000 per call), passing an idempotency key if supported. - Retries. Retry 429/5xx with exponential backoff and jitter through tiered retry topics so healthy partitions are not blocked. 4xx errors go straight to the DLQ.
- Feedback. Hard bounces and complaints suppress the address immediately; soft bounces retry and then suppress after N failures. Track complaint rate per tenant.
6. Delivery semantics
Exactly-once delivery to an inbox is impossible because ESP and SMTP calls are not transactional. Use at-least-once with idempotent consumers: commit the Kafka offset only after the send-log write, and rely on the conditional write to absorb replays. A small duplicate window remains (crash after the ESP accepts but before the log write); narrow it by marking rows SENDING first and reconciling against ESP events. The DLQ keeps full context and supports replay by campaign or time range; replay is safe thanks to the dedup key.
7. Scheduling
- Time-based: on create or update, compute
send_atinto minute buckets. Scheduler shards own bucket ranges via leases (etcd/ZooKeeper or row locks) and claim due rows each minute withFOR UPDATE SKIP LOCKED. A reschedule rewrites rows and bumps a version; stale triggers are dropped on version mismatch. - Event-driven: cancellations and changes skip the scheduler and flow via the outbox to a high-priority topic with dedicated consumers.
- Thundering herd: many events at 7 pm would all fire reminders at the same instant. Use deterministic per-recipient jitter (about +/-10-15 min), pre-expand large events into a delayed queue ahead of time, and let rate limiters flatten the rest because reminder SLOs have slack.
8. Rate limits and quotas
Hierarchical token buckets in Redis (workers lease tokens in blocks to cut round trips): per tenant (fairness and abuse), per ESP account (provider quota), and per recipient domain (avoid Gmail/Outlook throttling and protect sender reputation). Priority lanes ensure cancellations are never starved by marketing-style traffic.
9. Scalability and backpressure
Partition Kafka by recipient-domain hash or campaign; autoscale send workers on consumer lag. When the ESP slows down, token buckets drain, queues absorb the backlog, and fan-out slows by pausing at its checkpoint. Bound queue depth and shed or delay low-priority traffic first.
10. Observability
Metrics: queue lag, send latency (trigger to ESP accept), delivery, bounce and complaint rates, retry and DLQ depth, scheduler lateness. SLOs: 99% of triggered mail accepted by the ESP within 5 minutes; reminders within 5 minutes of target. Propagate a campaign/message trace ID through every stage. Alert on lag growth, complaint rate over ~0.1%, DLQ growth and ESP error ratios.
11. Compliance and abuse
Double opt-in for new subscribers, one-click unsubscribe with a header link, suppression checks before every send, physical address and sender identity (CAN-SPAM), consent records, data export and erasure (GDPR), and per-tenant sending caps and reputation scoring to stop spammers.
12. Multi-region and DR
Run active-active for stateless services and the send path, with each event homed to one region for writes (avoids multi-writer conflicts). Replicate databases and Kafka asynchronously (e.g. MirrorMaker). Trade-off: a regional failure may lose a few seconds of unreplicated writes, so on failover reconcile via the send-log dedup key, accepting a rare duplicate over a missed cancellation. Suppression data should replicate with the strongest feasible guarantee.
13. Cost
Roughly 1B emails a month; at typical ESP prices of about $0.10 per 1,000 that is on the order of $100k/month, dominating infrastructure cost (storage and compute are tens of thousands at most). Managed services (SES, MSK, DynamoDB) cut operational load; self-hosting Kafka or Cassandra pays off only at larger scale or with a strong platform team. Negotiating ESP volume tiers is the largest lever.
14. Failure walkthrough: ESP throttling plus regional outage
- The primary ESP starts returning 429s. Workers back off, token buckets shrink, and retry topics absorb traffic. Cancellations keep priority; reminders are delayed within their slack.
- If errors persist, a circuit breaker routes new traffic to a secondary ESP (warmed up, with a limited share), with the same
message_idfor dedup. - If a region dies, DNS/traffic shifts to a surviving region. Fan-out jobs resume from checkpoints; the scheduler leases move; the send log's conditional writes prevent mass duplication.
- After recovery, drain the backlog gradually (rate-limited) to avoid a post-outage spike, then reconcile counts per campaign.
Common mistakes
- Doing the DB write and publishing to the queue separately (lost or phantom triggers).
- Claiming exactly-once instead of at-least-once with dedup.
- Firing all reminders at the exact minute, and forgetting per-domain throttling.
- Ignoring suppression and unsubscribe handling, or deleting suppression data on GDPR requests.