Video in progress

How do you build a product analytics pipeline that gets billions of events a day?

Events go through a light collector into Kafka, from there a stream loads them into a columnar database (ClickHouse, BigQuery and the like), and a raw copy is kept in cheap object storage. Real-time aggregates and exact nightly calculations can be separate layers, but I avoid two separate codebases.

📖 Answer

The math: 2 billion events a day × 1 KB = 2 TB/day of raw data. In a compressed columnar format it's 5-10 times smaller. At peak, 50-100 thousand events per second.

The layers:

  1. Collector. An HTTP endpoint that only accepts and writes to Kafka. No business logic: it takes the most load and must never go down. The mobile client batches events and buffers them when offline.
  2. Kafka is the buffer and the replay source. Retention of a few days: if the downstream system stops, no data is lost.
  3. Raw zone. Events go to object storage as Parquet, partitioned by date. This is the "source of truth", so you can recompute anything later.
  4. Warehouse. ClickHouse or a similar columnar DB, for dashboards and ad-hoc queries. Pre-aggregation with materialized views.
  5. Stream processing (Flink, Kafka Streams) only for what really needs real time: fraud signals, live counters.

Lambda (stream and batch separate) vs Kappa (stream only, recomputation through replay). In Lambda the same logic is written in two places, and the results differ. Where possible I prefer to do both streaming and recomputation with one SQL/one engine.

Things that are often overlooked:

  • Event schema and registry. One mobile version renamed a field, and the monthly report silently broke. Schema validation belongs in the collector.
  • Dedup. The mobile client resends; dedup by eventId.
  • Late events. A phone was offline for 3 days, so store the event time and the receive time separately.
  • Personal data. IP and phone number shouldn't stay in the raw data, or should be hashed; deletion requests (like GDPR) have to be carried out in the warehouse too.