---
title: "Scaling Nextdoor’s Datastores: Part 2"
description: "Letting product engineers manually choose replica vs. primary routing in Django broke down as abstractions hid read-after-write dependencies, and the common workaround of wrapping logic in transactions sent everything to the primary, slowly eroding the capacity gained from read replicas."
url: "https://swe.quest/articles/scaling-nextdoor-s-datastores-part-2-3bede3a52d4cf43e"
canonical: "https://engblog.nextdoor.com/scaling-nextdoors-datastores-part-2-513922e4b4b1"
source: "Nextdoor Engineering"
published: "2025-03-19"
difficulty: "medium"
kind: "Case study"
reading_minutes: 4
tags: ["replication","consistency","databases","scalability"]
---

# Scaling Nextdoor’s Datastores: Part 2

A post on [Nextdoor Engineering](https://swe.quest/sources/nextdoor.md), published 2025-03-19, 4 min read, Case study. Original: [https://engblog.nextdoor.com/scaling-nextdoors-datastores-part-2-513922e4b4b1](https://engblog.nextdoor.com/scaling-nextdoors-datastores-part-2-513922e4b4b1)

## Summary

Letting product engineers manually choose replica vs. primary routing in Django broke down as abstractions hid read-after-write dependencies, and the common workaround of wrapping logic in transactions sent everything to the primary, slowly eroding the capacity gained from read replicas. Nextdoor replaced manual routing with ORM-level tracking of which tables a web request has written to, automatically sending subsequent reads of those tables to the primary and everything else to replicas. Because average replication lag (~20ms) was far shorter than request duration, they refined this with a timer that makes tables replica-eligible again after p99.9 replication lag elapses, moving most read queries off the primary.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Replication](https://swe.quest/tags/replication.md) (Distributed systems)
- [Consistency models](https://swe.quest/tags/consistency.md) (Distributed systems)
- [Databases](https://swe.quest/tags/databases.md) (Data & databases)
- [Scaling](https://swe.quest/tags/scalability.md) (Distributed systems)

## Prerequisites

- database read replicas ([easy posts on Databases](https://swe.quest/tags/databases.md?difficulty=easy))
- replication lag ([easy posts on Replication](https://swe.quest/tags/replication.md?difficulty=easy))
- ORM query routing ([easy posts on Maps & geospatial](https://swe.quest/tags/geospatial.md?difficulty=easy))
- transaction isolation levels ([easy posts on Consistency models](https://swe.quest/tags/consistency.md?difficulty=easy))

## Keywords

Django, Nextdoor, read replicas, read-after-write consistency

## Related posts

- [Don't add a read replica until you've read this](https://swe.quest/articles/don-t-add-a-read-replica-until-you-ve-read-this-a990a2b0dc14e87b.md): incident.io · 2026-07-21 · Medium · 18 min read · PostgreSQL, Replication, Consistency models, Go, Scaling
  incident.io moved nearly all Postgres read traffic to a read replica and had to preserve read-after-write consistency without hand-routing each query.
- [Scaling Prisma applications with Neon read-only replicas](https://swe.quest/articles/scaling-prisma-applications-with-neon-read-only-replicas-ac8944ec261965c9.md): Neon · 2023-09-13 · Medium · 3 min read · PostgreSQL, Replication, JavaScript, Scaling
  Neon read-only replicas are independent compute instances that read from the same shared storage as the read-write compute.
- [When to use Read Replicas vs. bigger compute](https://swe.quest/articles/when-to-use-read-replicas-vs-bigger-compute-061db4b923addf0b.md): Supabase · 2026-01-15 · Medium · 12 min read · PostgreSQL, Replication, Scaling, Capacity planning, Cost optimization
  Choosing between vertical scaling and Postgres Read Replicas comes down to diagnosing the bottleneck first, using pg\_stat\_statements, read/write ratio queries, CPU utilization and EXPLAIN ANALYZE.
- [How to Minimise the Impact of Database Latency](https://swe.quest/articles/how-to-minimise-the-impact-of-database-latency-bc4c9682c5942467.md): Neon · 2024-06-07 · Medium · 9 min read · PostgreSQL, Performance engineering, SQL, Serverless
  Database round-trip latency compounds with every sequential query, so co-locating the backend with the database and cutting round trips matters more than raw query speed.
- [Scaling Nextdoor’s Datastores: Part 5](https://swe.quest/articles/scaling-nextdoor-s-datastores-part-5-9c2a55c33ba04857.md): Nextdoor Engineering · 2025-03-19 · Medium · 8 min read · Caching, Consistency models, Event-driven architecture, PostgreSQL, Scaling
  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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
