7/10
Technical Architecture & AI Engineering · 7 min read

System Design: High-Volume Notification and Priority Fanout Service

Design a 20M/day multi-channel notification platform with isolated priority lanes, 24-hour Redis deduplication, user quiet-hours filtering, and per-provider circuit breakers.

Why This Matters at Engineering Leadership Scale

At startup scale, services call SendGrid or Slack directly inline. At 20 million notifications per day across Email, Slack/Teams, Push, and In-App, naive coupling fails badly: weekly digest jobs block 2FA login emails for 40 minutes, retry storms send executives 14 duplicate alerts at 3:00 AM, and a single email vendor outage halts critical security notices.

Engineering leaders design notifications as a priority-isolated multi-channel fanout platform enforcing strict latency tiers, atomic deduplication, and vendor resilience centrally.

Core Mental Model & Architecture

Anchor capacity, priority SLOs, and deduplication memory math upfront:

  • Throughput: 20M notifications/day (~230/sec avg, 2,500 to 3,500/sec peak during digest launches or incident cascades).
  • Priority SLOs: critical (2FA, SEV1 security alerts) <5s; standard (mentions, approvals) <60s; bulk (weekly digests) <15 min.
  • Memory & Storage Math: Storing 24-hour Redis deduplication keys (20M keys * ~64 bytes) requires only ~1.3 GB RAM across Redis Cluster. Delivery audit receipts (20M * 500 bytes) = 10 GB/day (~900 GB/year compressed S3 Parquet + 30d hot ClickHouse).
Design DimensionNaive PatternProduction Pattern (Chosen)Why It Wins
Priority IsolationSingle queue with priority flagSeparate topics + worker pools (critical, standard, bulk)5M bulk emails never delay a SEV1 alert
Channel FanoutOne worker calls Email + Slack + PushPer-channel queues (email, slack, push, in_app)Slack 429 throttling never stalls Email or Push
Vendor FailoverSingle hardcoded SendGrid keyPer-provider circuit breaker (SendGrid -> AWS SES)Critical alerts survive primary vendor outages
DeduplicationTrust upstream not to retryAtomic Redis SET NX EX 86400 on dedup_keyKills duplicate alert storms during retry waves

Step-by-Step Implementation Tutorial

1. Architect Priority-Isolated Ingestion and Channel Fanout

Split urgency upfront, run preferences and deduplication once, and fan out into isolated channel adapter pools.

text
UPSTREAM SERVICES (Auth, Security, Billing, Digest Cron)
  -> Notification API (Schema validation + priority + `dedup_key`)
       -> Isolated Priority Topics:
            [notif-critical]  (High-headroom pool, SLO < 5s)
            [notif-standard]  (Auto-scaling pool, SLO < 60s)
            [notif-bulk]      (Rate-capped pool, SLO < 15m)

PREFERENCE & DEDUPLICATION SERVICE:
  1. Redis `SET notif:dedup:{tenant}:{dedup_key} 1 NX EX 86400` -> Skip if duplicate
  2. Check cached user preferences & timezone quiet hours (`critical` bypasses quiet hours)
  3. Render template & fan out to channel-specific queues:
       -> [Email Pool]  (Separate transactional vs bulk IPs; Circuit Breaker: SendGrid -> AWS SES)
       -> [Slack Pool]  (Per-workspace 1 msg/sec token bucket + 429 backoff)
       -> [Push Pool]   (APNs / FCM batch connections)
       -> [In-App Pool] (Postgres/Redis inbox + WebSocket live badge)

2. Implement Atomic Deduplication and Quiet-Hours Fanout

Keep the core routing handler pure, fast, and deterministic.

typescript
type Priority = "critical" | "standard" | "bulk";

interface NotifReq {
  tenantId: string;
  userId: string;
  dedupKey: string; // e.g., "sev1:alert_9921:user_42"
  priority: Priority;
  channels: Array<"email" | "slack" | "push" | "in_app">;
}

export async function routeNotification(
  req: NotifReq,
  redisSetNx: (key: string, ttlSec: number) => Promise<boolean>,
  getPrefs: (uid: string) => Promise<{ muted: string[]; quietHours: boolean }>,
  enqueue: (topic: string, payload: NotifReq) => Promise<void>
) {
  const fresh = await redisSetNx(`notif:dedup:${req.tenantId}:${req.dedupKey}`, 86400);
  if (!fresh) return { status: "deduplicated" };

  const prefs = await getPrefs(req.userId);
  if (prefs.quietHours && req.priority !== "critical") {
    return { status: "deferred_until_morning" };
  }

  const targets = req.channels.filter((c) => req.priority === "critical" || !prefs.muted.includes(c));
  await Promise.all(targets.map((c) => enqueue(`${c}.${req.priority}`, req)));
  return { status: "enqueued", targets };
}

3. Handle the Minute-25 Curveball: 5M Digest Flood + Simultaneous SendGrid Outage

"Marketing fires a 5M-email weekly digest at 9:00 AM right when an enterprise tenant suffers a SEV1 security breach, AND SendGrid starts returning HTTP 500 across the board."

  1. Zero Priority Starvation: email.bulk and email.critical have separate queues, worker pools, and outbound IP pools. The 5M digest cannot delay a single critical message.
  2. Automatic Vendor Failover: When SendGrid's 10-second 5xx error rate exceeds 20%, the Email Adapter circuit breaker opens: email.critical fails over instantly to pre-warmed AWS SES (keeping SEV1 delivery under 4s), while email.bulk pauses via exponential backoff rather than polluting transactional SES sender reputation.

4. Split Multi-Squad Ownership

  • Notification Delivery Platform Squad (6 engineers): Owns priority queues, Redis deduplication, channel adapters, SendGrid/SES/Slack circuit breakers, bounce suppression, and DLQs.
  • Preferences & Engagement Squad (5 engineers): Owns quiet-hours/opt-in preferences, localized templates, In-App inbox UI, and GDPR/CAN-SPAM unsubscribe compliance.

Worked Production Scenario: Before vs. After

A B2B SaaS platform sent 12M notifications/day through one shared RabbitMQ queue and a single SendGrid account. Monday 8:00 AM digests backed up queues for 42 minutes, causing 2FA login codes to expire before arrival and locking customers out. Separating priority lanes, transactional vs. bulk IP pools, 24h Redis deduplication, and SendGrid -> SES failover eliminated Monday lockouts completely.

MetricBefore (Shared Queue + 1 Vendor)After (Priority Lanes + Failover)Net Impact
Critical 2FA / SEV1 Lag (Monday Peak)42 minutes2.1 secondsMeets <5s SLO 99.98%
Duplicate Alert Tickets / Month320+0 (24h Redis SET NX)Restored customer trust
2-Hour SendGrid Incident ImpactTotal blackout4s failover to AWS SES (critical)Zero missed SEV1 alerts
Slack 429 Workspace Throttles15/month0 (per-workspace token bucket)Clean partner standing

Common Failure Modes & Anti-Patterns

1. Sharing Outbound Email IPs Between Bulk Digests and 2FA Alerts

The trap: Spam complaints on a weekly digest ruin domain IP reputation, sending password resets straight to Spam. The structural fix: Strictly separate sending subdomains and dedicated IP pools (alerts.company.com vs. digest.company.com).

2. Ignoring Slack/Teams Per-Channel Rate Limits

The trap: Firing 500 incident alerts/min into one Slack channel triggers 429 Retry-After and webhook revocation. The structural fix: Enforce per-workspace 1 msg/sec token buckets and collapse >5 identical alerts/min into a single grouped digest card.

3. Continuing to Email Hard-Bounced Addresses

The trap: Bounce rates above 5% trigger automatic AWS SES or SendGrid account suspension. The structural fix: Feed provider bounce/complaint webhooks into a synchronous Global Suppression List checked before every dispatch.

How to Handle Pushback in the Room

Product Manager: "SendGrid has 99.9% uptime. Why spend time maintaining AWS SES as a backup?"

Calm Executive Response: "99.9% uptime still permits 43 minutes of outage per month - during which no customer receives 2FA login codes or SEV1 breach alerts. Maintaining a pre-warmed SES backup strictly for our critical lane costs under $150/month baseline and removes our biggest external single point of failure."

Senior Engineer: "Why store 24h dedup keys in Redis instead of querying our Postgres delivery table?"

Calm Executive Response: "At 3,000 notifications/sec peak, hitting Postgres for dedup checks saturates write IOPS right during bursts. Atomic Redis SET NX EX 86400 handles that surge in under 0.5ms using just 1.3 GB of RAM."

Key Takeaways & This Week's Action Rep

  • Isolate priority lanes physically: Separate critical, standard, and bulk queues, workers, and email IP pools.
  • Deduplicate atomically in Redis: 24h SET NX costs ~1.3 GB RAM at 20M/day and permanently kills duplicate spam.
  • Protect every channel adapter with circuit breakers and rate limits: Fail critical emails from SendGrid to AWS SES and pace Slack per workspace.
  • Enforce global bounce suppression centrally: Protect domain reputation and GDPR/CAN-SPAM compliance automatically.
  • This Week's Action Rep: Verify whether your product's 2FA/security emails currently share a queue or sending IP with weekly digests, and outline the minimal split to isolate your critical lane.