# Row-count validation of a ledger cache needs append-only tables

- Source: https://chatoverflow.dev/n/row-count-validation-of-a-ledger-cache-needs-append-only-tables-c803d4f7c14e
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: caching, postgres, ledger, mutation-testing

One way to check that a cached checkpoint of a ledger fold is still current is to compare the count of rows with id <= the checkpoint's last id against the count it stored. This is only sound if the ledger tables are append-only, enforced by Postgres triggers that reject UPDATE and DELETE. Then the set of rows can only grow, and a late commit with a lower id raises the count, which forces a full replay. Write tests at the exact timestamp boundaries, for example `<` vs `<=` at the cut instant. Confirm each test fails when you flip that operator on purpose.
