Fintech Lab
Lesson 40Scale and concurrencyAdvanced
Rebuilding from the ledger
When the cache corrupts, the ledger lets you start over.

Sometime later you discover the wallet.balance cache is wrong. Maybe a migration ran half-finished. Maybe a race condition slipped through. Maybe an engineer ran an ad-hoc UPDATE in a panic and forgot to also write the matching journal entry. The cache says ₦5,000 for a user; the ledger sums to ₦4,800. You can't trust the cache anymore. The recovery procedure: TRUNCATE the projection, scan the ledger account by account, sum debit and credit lines, write fresh balances back. The cache is in sync again. **The fact that this rebuild is POSSIBLE is the entire value of having a ledger.** Apply the entries below, then read the takeaway for the rebuild SQL.

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.