Ad Click Aggregator 00:00:01 The advertiser sees two clicks, but the invoice says one A visitor taps an advert while the network is unreliable. An illustrative aggregation service has to acknowledge a received event quickly and decide its billing meaning later. These are separate jobs with separate clocks. A person follows a signed link. The service checks expiry, target and size limits. Add a trusted receipt timestamp while retaining appropriate original timing information. Write to Kafka on the partition for ad B and this visitor. After the replicated append, redirect. A repeat request keeps the same click ID. The stream and archive read the saved event without delaying the person. Persist event identity, receipt time and the relevant measured event time. A durable acknowledgement says the system can revisit the observation. It does not decide that the click is valid or billable. 00:00:54 The ten-oh-one minute is still changing Assign observations to a minute according to the declared event-time policy. A repeated click and a genuinely late click can arrive side by side in the processing log. One is a duplicate under the stated identity rule; the other can legitimately revise the total. The event occurred four seconds past ten oh one. It belongs to the ten oh one minute, even though processing happens at ten oh three. The key combines ad B, this visitor and the ten oh one minute. Count its first appearance. Add to the total and replace its ClickHouse row every ten seconds. A newly arrived event inside the allowed lateness updates the earlier minute's provisional total. Save keys, totals and log positions together. A restart may replay writes but not add them twice. Define watermark and allowed-lateness behavior. A preliminary result optimized for quick display is allowed to change only under the published correction policy. Durable checkpoints must cover both state and input progress consistently. 00:01:58 A fast dashboard may contain provisional numbers The advertiser asks for a range spanning several aggregation levels. Use a rollup compatible with the requested dimensions and time boundaries. A ten-second cache can save repeated work while making a recent correction briefly invisible. An advertiser asks for a campaign, dates, hour grain, country and device. The service checks ownership. Check a ten-second result cache. On a miss, choose the coarsest prepared table that fits. Read recent totals and older day totals in parallel. Filters skip unrelated rows. Combine groups for the requested dimensions and respect the chosen deduplication or aggregation rule. Cache and send the rows with data time, final status and any quality warning. Return the data timestamp, included dimensions and finality status. A cache hit should not disguise the actual age of the underlying count or a missing partition. 00:02:54 Recount before a charge becomes final At billing time the service has the original observations and more complete information about late or invalid events. Re-run a versioned counting rule over the agreed interval. Which total belongs on a final invoice? The board shows two valid clicks in the ten oh one minute, and one in the ten oh two minute. The same rule reads all raw events, including late ones. Publish a versioned final result with the evidence needed to reconcile it against earlier reports. Preserve both the published provisional figure and the auditable adjustment. The ability to replay needs retained raw evidence, a documented rule and a deterministic billing revision. Recounting from an already truncated dashboard cannot restore lost facts. 00:03:37 A single popular advert overloads its partition One ad appears on the front page. Every event hashes to the same worker when the partition key is only the ad identifier. Adding workers elsewhere does not fix this hot key. Keying only by ad sends all clicks to one worker. Key by ad and visitor. Many workers now share the raw clicks while each visitor stays together. Every ten seconds workers send small partial totals. One merge handles those rows, not all clicks. Distribute the raw workload across compatible subkeys, then combine partial totals for the ad. Keep duplicate identities together where required. Test the hottest ad as well as average throughput before trusting either the dashboard or the bill.