SDE & MLE Prep

Ad Click Aggregation

Requirements: count clicks per ad per minute in near real time (for billing and dashboards), ~10 B clicks/day, exact (billing!), handle late and duplicate events.

click logs -> Kafka (partition by ad_id) -> stream aggregator (Flink): tumbling 1-min windows,
                                             watermarks for late events, dedupe by click_id
                                                   |
                                                   v
                           aggregated (ad_id, minute, count) -> OLAP store (Druid/ClickHouse/Pinot)
raw events -> data lake (S3) -> nightly batch recomputation -> reconcile with streaming results

Deep dives: exactly-once = Kafka transactions / checkpointed state (Flink) + idempotent sinks; event time vs processing time with watermarks and allowed lateness; hot ads → pre-aggregate with key salting then merge; Lambda vs Kappa architecture (batch reconciliation for billing correctness); top-N ads per minute with a min-heap per window.