KatInterview

Design an Event Deduplication and Reconciliation Pipeline

System DesignModel answer
MediumModel answerSystem Designstreamingidempotencydeduplication

Last updated

Design a distributed pipeline that deduplicates high-volume event streams, reconciles them against a delayed authoritative source, and produces auditable daily aggregates.

Background

You are building the data backend for a digital platform that must bill clients based on counted events (think clicks, views, or conversions). Two independent data sources feed your system:

  1. Raw Event Logs — emitted by a fleet of distributed servers at high volume (~100k events/second). These logs are noisy: duplicates are common, events can arrive out of order, and a small fraction never arrive at all.
  2. Billing Ledger — a separate, authoritative record that reflects which events are actually billable. It is reliable but slow, typically arriving 1–4 hours after the events it describes.

Your goal is to produce a daily per-client count report that accurately reflects the state of events across both sources. Each event falls into one of these states:

  • Confirmed — present in both the raw logs and the billing ledger.
  • Unverified — present in raw logs only; the ledger has not (yet) confirmed it.
  • Ledger-only — present in the ledger but absent from the raw logs; these are billable and suggest dropped raw events.

What You Need to Design

Describe the end-to-end architecture of this pipeline. Your answer should cover:

  1. Ingestion and storage — how events flow in, where they land, and why.
  2. Deduplication strategy — how you identify and discard duplicate events before counting. Compare at least two approaches (e.g., probabilistic vs. exact) and explain the trade-offs for a billing context.
  3. Late-data handling — how you keep time-bucketed aggregates accurate when both raw logs and ledger records can arrive hours after the fact.
  4. Idempotency — how the pipeline stays safe to re-run; a failed job re-processing the same window must never produce double-counts.
  5. Interface between reconciliation and aggregation — how the component that joins the two sources communicates its output to the component that produces final counts.

Constraints and Assumptions

  • Event volume: ~100k events/second average; ~300k/second at peak.
  • Each event has a globally unique event_id (client-generated UUID or ULID) plus a client_id, timestamp, and a few metadata fields. Event size is roughly 400 bytes.
  • The ledger is always correct when it arrives. If it contradicts the raw logs, trust the ledger.
  • Reports must be auditable: any count on a final report must be traceable to individual event IDs.
  • The system must support restatement: if late data arrives after a day is marked final, the report should be correctable without silently mutating billed numbers.

Expected Output

A structured written answer. No code is required, but pseudocode or schema snippets are welcome. Cover all five areas above. Call out trade-offs and failure modes, not just the happy path.

Hints

Hint 1

Start with the numbers. 100k events/second × 86,400 seconds/day is ~8.6B raw events/day. At 400 bytes each that's ~3.5 TB/day before compression. Let those figures drive your storage and state-sizing decisions before picking any technology.

Hint 2

Deduplication and billing have conflicting tolerances for error. A Bloom filter is space-efficient but can produce false positives — think carefully about what a false positive means when the thing being counted is a billable event.

Hint 3

Separating 'provisional' from 'final' is the key to handling both timeliness and accuracy. Ask yourself: what is the latest the ledger can arrive, and how do I know when it's safe to close a day? Then design your watermark and finalization step around that answer.