Ad clicks
0-day streakReview

Your progress

Level 1

0 XP100 XP to level 2
0day streak
0best streak
0topics started
0cards reviewed
    Review cards

    Progress is stored only in this browser. No account is required.

    Design ad click aggregation: the 60-second story

    Design ad click aggregation

    One ad tap, three readers. Soon, now and exactly.

    Dashboards want the count within a minute, budget pacing within seconds, and the invoice wants every valid click billed exactly once.

    1M/s

    peak, when a cricket final’s ad break airs

    Ten billion clicks a day average 116k a second. Size the job for 2× peak so it can catch up after an outage.

    Kafka stalls. Must the redirect stall too?

    Bad: Write to Kafka first

    A Kafka incident becomes a redirect outage.

    Good: Local spool, then ship

    Group-commit to local SSD, return 302. Spools hold two days of clicks.

    Exactly-once is a chain of four hops

    Messages will arrive twice, so every hop must make a repeat harmless. A click affects the count once, however often it is delivered.

    The job writes “+40 clicks”, crashes, and replays from its checkpoint. The sink gets “+40” again.

    The trick

    Write the running total under the window’s key. A replay overwrites the row: 40 stays 40, not 80.

    Clicked at 12:01:50, arrived at 12:02:40. Which minute?

    Count by when it happened, not when it arrived. 12:01 fires at 3 clicks, and this late click updates it to 4.

    400k/s

    clicks on one IPL sponsor’s ad

    Every click for an ad goes to one task, sized for about 8k a second. Summing per second at each source first cuts that to about 1k records.

    One click definition, run twice

    1. Live: provisional, about a minute old
    2. 02:00 IST: replay yesterday with fraud verdicts
    3. Fraud caught after invoicing becomes a credit
    4. Drift above 0.1% pages someone

    Remember

    Record fast, count each click once at every hop, by when it happened. Live numbers are provisional; billing replays the same code over the log.