Fintech Lab
Lesson 38Scale and concurrencyAdvanced
The balance projection
Cache the balance as a projection, never as truth. The ledger always wins.

Lesson 24 said never cache running_balance. That's true for STATEMENT generation, recompute on read. But for the LIVE wallet balance the user sees every time they open the app, computing sum(debits) - sum(credits) over 5 years of entries is unviable. Real systems cache the live balance ON the wallet row, updated atomically inside the same transaction as each journal entry. The cache is a PROJECTION of the ledger, not its source of truth. If the cache ever drifts, the ledger wins and the cache is rebuilt (Lesson 40). Apply the entries below, then switch to Statement view: the running balance IS what production caches.

Fintech Lab is a free, interactive lab for fintech engineers. Real ledger, your own sandbox, engineering patterns from production. See all 85 lessons.

Search lessons

Type to find any of the 85 lessons. Press Enter to open.