KatInterview

Event Ingestion Pipeline with Semi-Structured Payloads

System DesignModel answer
MediumModel answerSystem Designdata-pipelineskafkaanalytics

Last updated

Design a fault-tolerant pipeline that ingests 50k heterogeneous JSON events per second and serves both per-user lookups and 90-day aggregate analytics.

Background

A digital media platform tracks user interactions across its web and mobile clients. Every interaction — reading an article, completing a quiz, watching a video — produces a JSON event. Each event shares a common header:

{
  "event_id": "uuid",
  "timestamp": "2025-01-15T10:23:45Z",
  "user_id": "u_9821",
  "event_type": "video.play",
  "source": "android",
  "schema_version": 2,
  "payload": { ... }
}

The payload field contains feature-specific metadata that varies by event_type and changes frequently as product teams ship new features.

What You Need to Design

Ingestion (50k events/s, spikes to ~150k/s) Describe how you accept events from client SDKs, buffer them durably, and hand them off to downstream consumers — all while keeping acknowledgement latency under 50 ms p99.

Schema flexibility Product teams add, rename, and restructure payload fields regularly. Explain how to store and query the payload without blocking feature development behind a rigid migration process.

Storage for two distinct access patterns

  • Investigative queries: fetch the last 10 events for a specific user_id in under 100 ms.
  • Analytical queries: compute daily active users (DAU) and per-feature adoption rates over a rolling 90-day window, returning results in seconds.

Data lifecycle and cost control Raw event volumes compound quickly. Outline a tiering strategy that moves data to progressively cheaper storage as it ages while keeping long-term trend queries possible without full scans of raw data.

Discussion Points

  • How does your design handle schema evolution — specifically field additions, renames, and type changes — without breaking existing consumers?
  • How would you deduplicate events given that client SDKs retry on failure?
  • What are the concrete trade-offs between a columnar analytical store (e.g., ClickHouse, BigQuery) and a key-value / operational store (e.g., DynamoDB, Cassandra) for the two access patterns above?
  • How do you prevent a slow analytics query from affecting ingestion throughput?

What a Strong Answer Looks Like

A concrete architecture with named components, back-of-envelope sizing that motivates your choices, clear storage trade-offs, and a lifecycle plan with specific retention windows. You don't need to design every sub-system in depth, but each major component should have a clear rationale.

Hints

Hint 1

Start with numbers before drawing boxes. Derive daily volume (events/day, GB/day, compressed) and use those figures to justify every technology choice that follows.

Hint 2

Think about which part of the system is on the critical path for ingestion latency. The collector should do as little as possible synchronously — validation, buffering, and enrichment belong in separate stages.

Hint 3

Two access patterns almost always mean two stores. Map each store to its read pattern, then decide how data flows from the buffer into each one.