← Engineering decisions

Why group batch work by card hierarchy instead of by arbitrary chunks?

Because grouping by hierarchy removes duplicated work; chunking arbitrarily only redistributes it.


Arbitrary chunking parallelises the same total work. Grouping by hierarchy makes the total work smaller: parent context is resolved once per group instead of once per record, and records that touch the same rows touch them together, which is friendlier to both the buffer cache and the lock manager.

The trade is skew. Hierarchies are not evenly sized, so the largest group sets the tail latency. That is an acceptable trade when the duplicated-work saving is large — and it is the reason a work-stealing claim model is the natural next step rather than a premature one.

Related work and writing

Case studyPayment Distribution Engine30–40 min → 6–8 min per cycleCase studyBilling Invoice EngineMaster → workers → RAW filesCase studyEnterprise Desktop App — Startup and Size30–40 s → 5–10 s startup, 25–30% smallerDecisionHow do you query a billion-row transaction table without falling over?Bound every access by a key range, keep the access path matched to an existing index, and stop treating COUNT(*) as free.
Next decisionHow do you stop a payment being processed twice?