# Why a Running Sum Fails: The Case for Aggregates as Functions

Original title: An Aggregate Is a Function, Not a Sum

> Hacker News story 50382974 · language: en · submitted 2026-11-05
> Web version: https://zeli.app/story/50382974
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 9 · by [alnovis](<https://news.ycombinator.com/user?id=alnovis>) · 💬 3
[original](<https://alnovis.io/blog/aggregate-is-a-function>) · [HN discussion](<https://news.ycombinator.com/item?id=50382974>)

## Summary

Storing sales receipts in ClickHouse seemed straightforward until at-least-once delivery, late documents, and pipeline outages broke every running-sum approach. After four failed designs—double-counted inserts, expensive recomputes, memory-hungry key dictionaries, and slow read-time aggregation—the team landed on a different model: an aggregate is a function of its documents, not a sum of what was inserted. A narrow, correctly sorted table and a dirty-cell journal make recomputation cheap and duplicates harmless.

## Key quote

> A re-delivered document changes nothing. During recomputation the rows of one document are collapsed by document key. Two deliveries become one row; the cell value stays the same. No dictionary, no key table, no memory of what was seen.

---

## Cite

- Page: https://zeli.app/story/50382974
- Date: 2026-11-05
- Source: alnovis.io (https://alnovis.io/blog/aggregate-is-a-function)
- Hacker News: https://news.ycombinator.com/item?id=50382974

## Other languages

- zh: https://zeli.app/zh/story/50382974 · markdown: https://zeli.app/zh/story/50382974.md
- ja: https://zeli.app/ja/story/50382974 · markdown: https://zeli.app/ja/story/50382974.md
- ko: https://zeli.app/ko/story/50382974 · markdown: https://zeli.app/ko/story/50382974.md
- de: https://zeli.app/de/story/50382974 · markdown: https://zeli.app/de/story/50382974.md
- es: https://zeli.app/es/story/50382974 · markdown: https://zeli.app/es/story/50382974.md
- ru: https://zeli.app/ru/story/50382974 · markdown: https://zeli.app/ru/story/50382974.md
