Tracing Cache Inconsistencies to Their Root Cause
Nextdoor extended its versioned Valkey ORM cache so every conditional write also atomically stores a short-lived verification key (receipt) recording the operation (fill_on_write or fill_on_miss), writer service, trace ID and replaced version, colocated via a hash tag in the same cluster slot. The CDC-driven reconciler reads receipts for both the checked and cached versions during its two passes, classifying each inconsistency as an expected race, a stale fill, or a missing cache write, and emits one per-model metric. Receipts expire after pass 2 or within minutes, and are skipped where the reconciler never checks. The approach exposed three non-cache bugs: a silent context-cancellation failure in the reconciler, an ORM save() falling back to INSERT and resurrecting deleted rows, and redelivered long-running background jobs writing stale versions.
Related posts
- Cache made consistent
Meta Engineering mediumAdeptMeta raised TAO's cache consistency from six nines to ten nines (99.99999999% of cache writes consistent within five minutes) by treating consistency as a measurement and debugging problem rather than only a protocol problem. Polaris acts as a client that consumes invalidation events and checks cache replicas against client-observable invariants. It uses multi-timescale retry queues and defers expensive cache-bypass database reads, which avoids false positives without overloading the database. A stateful consistency-tracing library logs cache mutations only in the short window after a write, where fills and invalidations race. That gave engineers complete timelines for bugs such as a versioned entry that stayed stale indefinitely.
- Eventually Consistent: How Do We Know the Systems Eventually Agree?
Kogan.com Dev Blog mediumAdeptEventually consistent event-driven order systems need a reconciliation job that starts from the authoritative order store, not from received messages, so orders whose events were lost (like a fraud-hold release that never reached SAP) still surface. Define "eventually" as a concrete deadline with documented exceptions, query overdue orders cheaply via a PostgreSQL partial index on the waiting status, confirm state with the owning service before repairing, and repair through normal paths reusing the original idempotency key or via compensating actions. Track open cases persistently, process them in small batches, and measure overdue counts, oldest-unresolved age and whether the job actually ran rather than relying on CPU or queue metrics.
- The final boss of reliability: formal verification
Turso mediumAdeptTurso, a from-scratch SQLite rewrite, is adding formal verification via Aretta AI's Aristo, which turns natural-language intents annotated on code into formally checked properties, to complement its deterministic simulation testing and Antithesis runs. Aristo found in minutes a durability bug that DST had missed. When Turso acts as a sync replica of a cloud database, it bypasses the page cache, so pages became dirty without the dirty bit being set and were sometimes written to disk without fsync. The case for the approach is that properties like "a commit frame must be fsynced before being reported durable" are cheap to check formally. Runtime testing can miss them, because most runs happen to call fsync for unrelated reasons.
- Birth and death of a row in Turso's MVCC
Turso hardMasterTurso's MVCC, modeled on Hekaton, tracks each row as a chain of versions in a lock-free SkipMap, with begin/end fields holding a TxId while a transaction is active and a commit timestamp once it commits. The walkthrough follows one row from the INSERT bytecode executed by the VDBE, through the commit protocol (timestamp acquisition, first-committer-wins conflict checks, dependency waits, logical-log write and fsync), crash recovery by replaying the logical log, and checkpointing into the SQLite WAL and B-tree. Checkpoints default to a blocking Truncate mode triggered at about 4 MB, with an experimental Passive mode that lets writers proceed. Reads merge the in-memory store and the B-tree with a two-pointer iteration. Deletes set the end field under the version-chain lock, so concurrent writers to the same row get a WriteWriteConflict.
- Slack’s Incident on 2-22-22
Slack Engineering mediumAdeptA Consul agent rolling restart caused Mcrib, Slack's memcached control plane, to replace and flush cache nodes, dropping hit rates during peak traffic. A cache-fronted Group DM membership query hit a Vitess keyspace sharded by user, so every miss became a scatter query across all shards. Database load grew superlinearly, queries timed out, caches couldn't refill, and client retries kept the system stuck in a metastable cascading failure. Recovery required throttling client boots, fetching only missing keys, reading from replicas and later moving the query to a channel-sharded table; Mcrib's very efficiency at replacing nodes increased cache churn and worsened the outage.