Real-time aggregation: counting events in time windows
A national weather service publishes rainfall per region every hour. Stations radio in their readings, each numbered and stamped with the time it was taken, and the regional office adds them up per hour. The bulletin goes out a few minutes after the hour and is corrected when a late report turns up. A station that repeats a report it thinks was lost is caught by the number. Insurers, though, settle claims only on the official record, compiled each night from head office's file of every report received.
The readings are events, here impressions and clicks, the stations are the phones that report them, and the radio is the ingest API and Kafka. A reading's number is an ID given once at the source, and the time it was taken is its event time. The office's hourly tally is a stream job's window, publishing a few minutes late is its watermark, and the bulletin is the dashboard. The official record is a nightly batch over the archive of every event received, the only count billing trusts. Interviewers listen for what a count does when events arrive late, twice, or during a crash. The move: count in event-time windows on a stream, write each window's value so a replay is harmless, and let a batch over the raw events have the final word on anything billed.