Scaling Nextdoor’s Datastores: Part 5
Nextdoor closes cache consistency gaps in its look-aside Redis cache by consuming the PostgreSQL change data stream and issuing version-conditional del_if_version deletes whenever writers fail to update the cache. Because deletes are guarded by row versions, changes can be processed out of order and horizontally scaled. A race between cache fills on read misses and missed writes is handled with two reconcilers: one near-real-time, and one delayed slightly beyond the web request timeout to mop up stale refills. The pipeline is pg-bifrost republishing the WAL into Kafka, with a Go consumer that uses a time wheel for the delayed pass.
Related posts
- Tracing Cache Inconsistencies to Their Root Cause
Nextdoor Engineering mediumAdeptNextdoor 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.
- Everyone gets faster writes: We turned off FPW's in Neon
Neon hardMaster
Neon disabled Postgres full-page writes fleet-wide because its stateless compute streams WAL to a Paxos safekeeper quorum and has no local disk pages that can tear. To keep delta chains bounded without FPW images, the pageserver now generates page images itself once a page accumulates more deltas than a threshold, rather than relying on the checkpoint cycle. HammerDB TPROC-C throughput rose up to 4.5x on 32 vCPU, and WAL per transaction fell from 58KB to under 4KB (94%). In production, p99 read latency dropped 30-50%, and the change was rolled out without restarts via the XLOG_FPW_CHANGE WAL record.
- Fan-out from Postgres with Change Data Capture using Debezium and Upstash Redis
Neon mediumAdept
Streaming committed Postgres changes from the write-ahead log via a logical replication slot avoids the dual-write problem, where an application writes to the database and a message broker separately and can leave them inconsistent. LISTEN/NOTIFY doesn't fix this because it is only at-most-once. The guide configures Debezium Server to read Neon's WAL using pgoutput, with an initial snapshot and file-based offset tracking, and to sink change events into an Upstash Redis stream. A Node.js consumer then uses XREADGROUP consumer groups and XACK to get at-least-once fan-out that can resume after restarts.
- 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.
- Keeping it 100(x) with real-time data at scale
Figma mediumAdept
Figma rebuilt LiveGraph, its real-time GraphQL-like subscription service over Postgres, to scale reads and database update load 100x as the database moved from one instance to vertical and horizontal shards. The old design tailed a single globally ordered replication stream into per-server mutation-based caches, which caused excessive fan-in and fan-out, fragmented caches, thundering herds on deploy, and stalled optimistic updates whenever any shard blipped. Two traffic findings drove the redesign: most data is delivered by initial reads rather than live updates, and most queries can be invalidated directly from a row mutation. The result is a three-tier Go system: an edge that expands views, a read-through cache sharded by query hash, and stateless invalidators sharded like the databases that tail the replication streams and send invalidations only to the relevant cache shards.