An Aggregate Is a Function, Not a Sum

2026-11-04 19 min read

647

An Aggregate Is a Function, Not a Sum

Reports Over a Stream of Receipts

The system I work on stores sales receipts. Receipts from every cash register arrive through Kafka, and ClickHouse stores them as documents.

On top of the raw documents sit the reports people actually look at: totals per cashier shift, totals per hour and per day for a store, revenue grouped by a custom field the merchant puts on the receipt.

It looks like a standard ClickHouse use case: insert rows, then aggregate them. It took us four attempts.

What makes it hard is not the volume but three properties of the stream: