KatInterview

Build a Rule-Based Event Fan-Out Service with Webhook Delivery

System DesignModel answer
HardModel answerSystem Designsystem-designwebhooksevent-streaming

Last updated

Design a platform that takes up to a million fire-and-forget events per second and pushes each one to the webhooks of tenants whose filter rules match, with retries, isolation and security.

You are asked to design a multi-tenant platform that moves events from producers to interested consumers.

Producers push events and do not wait for any matching or delivery to happen. Aggregate ingest can reach 1,000,000 events per second at peak.

Consumers register a rule (a filter over event contents) together with a webhook URL. Each event that satisfies a rule must be sent to that rule's webhook over HTTP.

Your design should cover:

  1. Requirements and capacity estimates. State your assumptions (event size, number of tenants and rules, matches per event, retention) and derive bandwidth, storage and the number of concurrent outbound requests.
  2. APIs. Event ingestion, and subscription create/update/pause/resume/delete, plus anything needed for observability or replay.
  3. Rule language. What can a rule express, what limits do you impose, and how do you make matching fast with a large number of rules?
  4. Architecture and data model. Major components, what is stored where, and how rule changes reach the matching layer.
  5. Webhook delivery. Success criteria, retry and backoff policy, handling of permanently failing endpoints, and request authenticity.
  6. Guarantees. Delivery semantics, ordering, and exactly when a new or changed rule starts to apply.
  7. Backpressure and scaling. How each layer protects itself and how you shard.
  8. Multi-tenancy, rate limiting and security. Prevent a slow or malicious tenant from degrading others.
  9. Operations. Metrics, alerts and failure modes you would plan for.

Be explicit about trade-offs and about where your design would break first.

Hints

Hint 1

Do the arithmetic early: if each event matches about two rules, outbound webhook calls outnumber inbound events, and with a few hundred milliseconds of latency each, hundreds of thousands of requests are in flight at once. Which side is harder to build, ingest or delivery?

Hint 2

Put a durable partitioned log between ingest and everything else. It defines your durability point (the 202 response), lets the matchers lag safely, and makes replay cheap. Then ask how to avoid evaluating every rule for every event, for example by requiring an indexable equality on event type.

Hint 3

Separate delivery from matching and isolate it per tenant and per subscription. Think about per-subscription queues, concurrency caps, circuit breakers for dead endpoints, jittered exponential backoff, a dead-letter queue, and what ordering you can promise without head-of-line blocking everyone.