Scaling Nextdoor’s Datastores: Part 3
Nextdoor replaced pickle-style byte serialization of Django ORM objects in its Redis/Valkey look-aside cache with MessagePack, so cache entries stay readable across code releases and schema migrations. Pickled objects are tied to runtime and package versions; deserialization failures after a deploy or migration turn into mass cache misses and a thundering herd on the database. With MessagePack, older code ignores unknown new fields (forward compatibility) and newer code fills missing fields with required defaults (backward compatibility); field removals go through Django's SeparateDatabaseAndState. MessagePack was slower than pickle in isolation but had no noticeable effect on request latency, produced smaller payloads, and each value carries a 10-byte header (2-byte format metadata plus 8-byte object version) to support future changes such as compression.
Related posts
- Caching Without Marshal Part 2: The Path to MessagePack
Shopify Engineering mediumAdeptShopify replaced Ruby's Marshal with MessagePack as the Rails cache format for its core monolith so that code changes would stop breaking cached payloads on deploy. MessagePack only encodes types it knows about. Ruby types are added through registered extension types such as Date, Time, BigDecimal and a custom ActiveRecordCoder, which serializes records with their loaded associations and uses an instance tracker to handle circular references. The migration ran both formats side by side for about six months: payloads were prefixed with a version byte, the client fell back to Marshal when MessagePack raised NoMethodError, and each failure was logged to find missing extension types. Record payloads shrank up to 13x, total memcached usage fell by more than 25%, and decode errors from renamed classes are now treated as cache misses.
- Faster schema changes for large SQLite databases
Turso mediumAdeptSQLite re-parses the entire sqlite_schema table after every ALTER TABLE, so schema changes cost time proportional to total schema size even when only one table is touched. Turso, a Rust rewrite of SQLite, adds dedicated bytecode instructions (RenameTable, DropColumn, AddColumn, RenameColumn) that mutate the in-memory schema directly and update only the affected table's indexes in batch. Initial schema loading is also sped up by replacing the lemon-generated parser with a handwritten one, while the in-memory schema is shared across connections so later connections skip parsing entirely.
- Scaling Nextdoor’s Datastores: Part 5
Nextdoor Engineering mediumAdeptNextdoor 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.
- Tulip: Schematizing Meta’s data platform
Meta Engineering mediumAdeptTulip is Meta's binary serialization protocol for analytics logging, built on Thrift's TCompactProtocol. It replaces the positional Hive Text Delimited and JSON formats, which broke when columns were inserted or deleted and offered no forward or backward compatibility. Engineers declare only field names and types, and the platform assigns field IDs in a transactionally updated serialization schema. IDs are never removed, so a type change gets a new ID and a rename is treated as a delete plus an add. Compared with the legacy formats, Tulip uses 40–85% fewer bytes and 50–90% fewer CPU cycles to (de)serialize.
- 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.