KatInterview

Design a Scalable Real-Time Event Notification Engine

System DesignModel answer
MediumModel answerSystem Designsystem-designpub-subevent-driven

Last updated

Design a robust event delivery platform supporting independent fan-out isolation, classified retry delays, rate limiting, and historical replays.

Problem Statement

Design a robust, multi-tenant event delivery engine capable of handling high-volume real-time event streams (e.g., shipment status changes, driver location updates, order state transitions) and dispatching them to hundreds of downstream internal services and external partner webhooks.

Downstream subscribers exhibit diverse operational characteristics: varying throughput capabilities, different SLA profiles, distinct payload schema requirements, and fluctuating availability. A key architectural goal is ensuring complete consumer isolation so that an outage or performance degradation in one consumer system never disrupts event processing for others.

Requirements

Functional Requirements

  1. Ingestion & Routing: Ingest events via an HTTP API and route them to matching subscribers according to filter expressions and versioning rules.
  2. Consumer Isolation: Guarantee that slow, unresponsive, or failing consumer destinations cannot introduce head-of-line (HoL) blocking or delay delivery for healthy consumers.
  3. Idempotency & At-Least-Once Delivery: Provide at-least-once delivery guarantees. Automatically detect and ignore duplicate incoming events from upstream producers via deduplication keys.
  4. Error Classification & Retry Strategy: Classify downstream delivery failures into transient (e.g., HTTP 503, network timeouts) versus permanent (e.g., HTTP 400, 404, authorization errors). Implement exponential backoff for transient issues and forward non-retryable failures to a Dead Letter Queue (DLQ).
  5. Historical Replays & Auditability: Support administrative replay of historical events for a specific subscriber across a chosen time range. Maintain a complete audit log of every delivery execution attempt and response status.

Non-Functional Requirements

  1. High Throughput & Low Latency: Handle peak ingestion traffic of 50,000 events/second. Deliver events to responsive destinations within 1 second at $p_{99}$.
  2. Backpressure & Flow Control: Rate-limit dispatches on a per-subscriber basis to prevent overwhelming downstream destination endpoints.
  3. Data Retention: Retain raw ingested events for a minimum of 7 days to facilitate system recovery, debugging, and historical replays.

Scale & Capacity Assumptions

  • Ingestion Peak: 50,000 incoming events/sec.
  • Active Subscriptions: ~500 configured downstream consumers.
  • Average Fan-Out: 5 destinations per ingested event (yielding ~250,000 delivery dispatches/sec at peak).
  • Average Event Payload: ~2 KB.
  • Audit Logging: Up to 300 million daily log entries under normal operations (with capacity for burst peaks matching max dispatch rates).

Key Areas to Address

  • API Interfaces: Ingestion, subscription management, and replay execution APIs.
  • Data Model & Storage: Schemas and storage engine choices for deduplication state, subscription rules, raw event streams, and audit histories.
  • System Architecture: Complete system topology covering ingestion endpoints, fan-out compute layers, isolated worker dispatchers, retry backoff mechanisms, and DLQ handling.
  • Failure Modes & Trade-offs: Mitigating head-of-line blocking, managing deduplication storage windows, implementing circuit breakers, and enforcing replay controls.

Hints

Hint 1

Decouple the primary ingestion event log from per-consumer delivery state so write path performance is unaffected by slow consumers.

Hint 2

Store full event payloads in a centralized blob log or main topic, passing reference IDs through fan-out queues to prevent memory and bandwidth amplification.

Hint 3

Use classified retry delay queues combined with circuit breakers to prevent failing endpoints from overwhelming dispatchers or triggering cascading outages.