KatInterview

Design a High-Scale Event Streaming and Analytics Pipeline

System DesignModel answer
HardModel answerSystem Designstream-processingdata-pipelineanalytics

Last updated

Design an end-to-end pipeline that ingests millions of user interaction events per day, handles duplicates and late arrivals, and serves both real-time dashboards and raw session queries.

Context

A SaaS platform used by thousands of enterprise customers wants to understand how users interact with its product. Every time a user loads a page, completes a workflow step, triggers an error, or clicks a significant control, the application should record that event. The collected data will power three things:

  • Internal product dashboards showing adoption trends, funnel conversion, and daily/monthly active user counts — updated within one minute of events arriving.
  • Per-session and per-user audit trails that enterprise customers can request, for compliance and support investigations.
  • Ad-hoc exploration by analysts who want to query raw events across arbitrary dimensions.

Your task is to design the full system: the client-side SDK and ingest API, the data pipeline, the storage layer, and the query path.

Scale to Design For

DimensionValue
Enterprise tenants10,000
Daily active users5 million
Events per user per day~100
Total events per day~500 million
Average event payload1 KB
Average throughput~6,000 events/sec
Peak throughput (4× burst)~25,000 events/sec / ~25 MB/sec
Raw event retention90 days hot, then cold archive
Aggregate retentionIndefinite

Requirements

Functional

  • A client SDK and HTTP ingest API that collect structured events from web and mobile apps.
  • Client-side buffering and retry so events are not lost on flaky connections; deduplication so retries do not inflate counts.
  • Real-time aggregations (DAU/MAU, top actions per tenant, conversion funnels) with data freshness under one minute.
  • Raw event queries: retrieve the full chronological event trace for a given user, session, or time window.
  • Strict data isolation between tenants — one tenant must never be able to read another's events.

Non-functional

  • Ingest API p99 latency under 50 ms.
  • Dashboard query latency under 1 second.
  • 99.99% ingest availability; no event loss after the server acknowledges receipt.
  • Horizontal scalability to handle ingestion spikes and growing data volume.

What Your Answer Should Cover

  1. SDK and API design — event schema, client-side buffering, retry and deduplication strategy, offline persistence.
  2. End-to-end pipeline architecture — ingestion tier, message bus, stream processing, persistence, and archive layers.
  3. Storage trade-offs — justify your choice(s) among columnar OLAP, wide-column stores, time-series databases, and object storage for raw vs. aggregate data.
  4. Data integrity — how you handle duplicate events from retries, out-of-order events, and device clock skew.
  5. Multi-tenancy — how isolation is enforced at every layer.
  6. Honest trade-offs — where your design makes simplifying choices and what you give up.

Hints

Hint 1

Start with the math: 500M events/day × 1 KB is 500 GB/day uncompressed. Work out what that means for Kafka retention, hot storage, and cold archive before picking any technology. Numbers anchor every trade-off that follows.

Hint 2

The hardest constraint is 'no event loss once acknowledged.' Think about what the ingest gateway must do before it returns 202 — and what happens if the downstream message bus is briefly unreachable.

Hint 3

For storage, the raw-event workload (fetch all events for user X in session Y) and the aggregate workload (count distinct users per tenant per day) have very different access patterns. Consider whether one engine can serve both, and if so, what table layout makes it work.