TOUGH TONGUE AI
  • Home
    LogoTOUGH TONGUE AI

    RESOURCES

    Loading...

    HomeLibrarySD Mock · Design a Notification System

    SD Mock · Design a Notification System

    SD Mock · Design a Notification System

    Overview

    Design a notification system that sends push, SMS and email at scale on a live architecture board — drag components, wire them up, and defend your design to an expert interviewer who watches every move.

    Your Instructions

    Design a notification system

    A 20-minute mock system design interview. You drive the pace. Jump to the board when you are ready; skip capacity math if you want. The interviewer grades your thinking, not a template match.

    The happy path here is short: a service asks, a vendor delivers. The signal lives in what happens around it: a vendor outage, a retry that sends twice, a marketing blast that buries a password reset, a user who opted out. Naming "Kafka plus workers" is not a design.

    Two shared surfaces (only one is on screen at a time; use the panel arrow to switch):

    • Notepad. Shared notes. Requirements, capacity math, schema, and end-of-session feedback live here. You can type in it too.
    • Architecture board. Your design canvas. Drag typed components, wire them, label edges, mark scaled tiers as distributed. If it is not on the board, it is not in your design.

    Build incrementally while you talk. Trace one notification end to end through your diagram, including the one sent while the SMS vendor is down. Argue the tradeoff, not "industry standard."

    Design choices interviewers probe

    Read this before you go in. These are the decisions, and why they matter.

    You never talk to the phone

    Delivery always goes through a provider: APNs for iOS, FCM for Android, an SMS vendor (Twilio, Vonage and similar), an email service (SES, SendGrid, Postmark). Your system's job is everything before the hand-off: who to reach, on which channel, with what text, whether they agreed to it, and what to do when the provider says no. Draw the providers as third-party boxes at the edge of the board.

    Accept fast, deliver later

    Callers (billing, orders, social, a campaign tool) should not wait on a vendor. The notification service validates, records the request, queues it and returns 202 with an id. Workers do the slow part. A single server that calls vendors inline is a fine first sketch, then name its three problems: a single point of failure, vendor latency tying up the box that accepts requests, and no way to scale the parts separately.

    One queue or one per channel

    With one shared queue, an SMS vendor outage or a slow email provider backs up every channel behind it. A queue (and a worker pool) per channel turns a vendor outage into a backlog for that channel only. Some designs go further and split by priority too, so a marketing blast never sits in front of a one-time passcode.

    Delivery: at least once, deduped

    Queues redeliver after a crash or a lost acknowledgement, so a worker can send twice. Exactly-once delivery is not available; exactly-once effect is. Give each notification an id and have the worker atomically claim it (a set-if-absent with a TTL, or a unique row) before calling the vendor. "Check the log, then send" is a race: two workers both see "not sent".

    Retries, and when not to

    Retry timeouts, 429s and 5xx with exponential backoff and jitter, under a budget; then a dead-letter queue someone watches and can replay. Do not retry a rejected payload. When APNs or FCM says a device token is no longer registered, delete the token instead of retrying it forever.

    Settings, templates and caps

    • Opt-in lives per user, channel and category (marketing, social, security). Check it before queueing, not after sending. Security codes and receipts usually cannot be opted out of; marketing needs consent, and SMS and email carry legal rules.
    • Templates are versioned per channel and locale; callers send a template id and parameters, never raw text.
    • Two kinds of rate limit. A per-user cap protects people from noise. A per-provider cap respects vendor throughput; past it, more workers only collect rejections.

    Tracking

    Every attempt lands in a notification log (status, attempts, timestamps). Delivery receipts, opens and clicks flow to analytics. Those numbers decide which templates to kill and catch a silent provider failure early.

    Reference solution

    One complete design you can study, then rebuild in your own words. Do not recite it. In the interview, draw your graph and defend the choices.

    Requirements (lock these or take the defaults)

    • Channels: iOS push, Android push, SMS, email
    • Triggers: internal services call an API; campaigns are scheduled
    • Soft real-time: transactional within a few seconds; marketing may lag minutes. Never lose an accepted notification
    • Users opt out per channel and category; per-user frequency caps
    • ~50M daily active users; one region to start
    • Non-functional: high availability, no duplicates the user notices, isolation between channels, observability

    Capacity

    • 60M push + 5M SMS + 20M email = 85M a day ≈ 1,000 a second average
    • Marketing blast: 30M pushes in 10 minutes ≈ 50,000 a second. The burst, not the average, sizes the queues and the dispatch tier
    • Log: 85M rows × ~1 KB ≈ 85 GB a day, about 8 TB for 90 days of history
    • Devices: 50M users × ~1.5 devices ≈ 75M tokens, small enough for one replicated SQL store
    • SMS costs real money (around a cent a message in the US), so 5M a day is a five-figure daily bill: keep SMS for what needs it

    Components to put on the board

    How the graph works: callers hit a load balancer in front of a stateless notification service. It authenticates the caller, checks opt-in and per-user caps against cached settings, renders the template, records the request and puts one message per channel on that channel's queue, then returns 202. Each channel's worker pool claims the notification id in Redis, calls its provider under that provider's rate limit, logs the attempt, and retries with backoff or dead-letters. Tracking events flow from the log to analytics.

    Service (callers) + Scheduler (campaigns)
        → Load Balancer
        → Service: Notification service (stateless; mark distributed)
            ↔ Cache (settings, templates, device tokens) ← Postgres (users, devices, settings, templates)
            → Kafka / SQS: push queue, SMS queue, email queue (one per channel)
        → Worker pools per channel (mark distributed)
            ↔ Redis (dedupe claims, per-user and per-provider counters)
            → Third-party API: APNs, FCM, SMS vendor, email vendor
            → Cassandra (notification log)  → Data Warehouse (tracking, analytics)
            → Queue: retry with backoff, then dead-letter
    

    Components:

    • Callers and Scheduler. Internal services send transactional notifications through the API; a scheduler releases campaigns and timed sends (9 AM in the user's timezone) in batches.
    • Notification service. Stateless, behind a load balancer. Auth for callers, validation, opt-in and cap checks, template rendering, the 202. It never waits on a vendor.
    • Cache + Postgres. Settings, templates and device tokens are read on every request, so they sit in a cache backed by a relational store.
    • A queue per channel. Buffers bursts and isolates failures; a dead SMS vendor backs up SMS only. Kafka topics or SQS queues both work; a priority split keeps passcodes ahead of campaigns.
    • Worker pools. One per channel, scaled on the age of the oldest message, capped by each provider's limits.
    • Redis. Atomic dedupe claims (notification id, set-if-absent with a TTL) and rate counters.
    • Third-party APIs. APNs, FCM, SMS and email vendors do the last mile.
    • Cassandra + warehouse. A write-heavy log keyed by user and time; tracking events feed analytics.

    Walk one notification: "your order shipped" to a user with an iPhone and email on

    1. The order service calls POST /v1/notifications with the user, template order_shipped, parameters, category transactional and an idempotency key.
    2. The notification service checks the key (a retry returns the first id), reads the user's settings and devices from cache, and applies the per-user cap.
    3. It renders the push and email from their templates, records the request, enqueues one message on the push queue and one on the email queue, and returns 202 with the id.
    4. A push worker claims the id in Redis, calls APNs with the device token, and logs "sent".
    5. An email worker does the same with the email vendor.
    6. If APNs answers that the token is unregistered, the worker deletes the token and logs it; nothing is retried.
    7. Receipts, opens and clicks flow into the log and analytics.

    SMS vendor down for 20 minutes: SMS messages wait in their own queue while push and email keep flowing; workers retry with backoff and the queue drains when the vendor returns. Messages past the retry budget go to a dead-letter queue with an alert.

    A worker dies after sending but before acknowledging: the message comes back; the next worker finds the id already claimed and skips it.

    Schema

    users(user_id, email, phone, timezone, locale)
    devices(device_id, user_id, platform, device_token, updated_ts)
    settings(user_id, channel, category, opt_in)            primary key (user_id, channel, category)
    templates(template_id, channel, locale, version, body)
    notification_log(user_id, created_ts, notification_id, channel, template_id, status, attempts)
    
    • Settings, devices and templates in Postgres (relational, modest size, read through a cache)
    • The log in Cassandra, partitioned by user_id, clustered by created_ts
    • Dedupe claims in Redis with a TTL of about a day

    Scaling and wrap-up

    • The notification service and workers are stateless and scale out; queues absorb blasts
    • First walls at 10x: provider throughput limits, the blast burst, log write volume
    • Spread campaigns over minutes; separate priority classes so a blast never delays a passcode
    • First metrics: oldest message age per channel queue, provider error rate, delivery latency, dead-letter size
    • If time: multi-region, quiet hours by timezone, provider failover for SMS and email, provider credentials and caller auth

    Equally defensible variants

    SQS per channel instead of Kafka topics. A per-user notification inbox for in-app messages. Rendering in the workers instead of the service. Buying a notification platform when the team is small. What matters is that you can argue the tradeoff.

    More in System Design Interview Prep: AI Coach Edition

    • SD Mock · Design Twitter
    • SD Mock · Design Typeahead Suggestion
    • SD Mock · Design Twitter Search
    • SD Coach · Rate Limiting
    • SD Mock · Design an API Rate Limiter
    • SD Coach · Event-Driven Systems and Notifications
    • SD Coach · Async Jobs, Schedulers and Crawlers
    • SD Mock · Design a Web Crawler
    • SD Coach · Distributed Storage
    • SD Mock · Design a Key-Value Store
    • SD Coach · File Sync: Dropbox and Google Drive
    • SD Mock · Design Dropbox
    View the full course (43 sessions) →