---
title: "Don't add a read replica until you've read this"
description: "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."
url: "https://swe.quest/articles/don-t-add-a-read-replica-until-you-ve-read-this-a990a2b0dc14e87b"
canonical: "https://incident.io/blog/dont-add-a-read-replica-until-youve-read-this"
source: "incident.io"
published: "2026-07-21"
difficulty: "medium"
kind: "Case study"
reading_minutes: 18
tags: ["postgres","replication","consistency","go","scalability"]
---

# Don't add a read replica until you've read this

A post on [incident.io](https://swe.quest/sources/incident-io.md), published 2026-07-21, 18 min read, Case study. Original: [https://incident.io/blog/dont-add-a-read-replica-until-youve-read-this](https://incident.io/blog/dont-add-a-read-replica-until-youve-read-this)

## Summary

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. Within a request, a Go context flag is tainted on any write or transaction so later reads go to the primary, a simple SELECT-prefix check classifies queries, and a circuit breaker falls back to the primary if the replica is unreachable. Across async boundaries, 0.1–0.5% of queue messages hit NotFound errors because workers ran faster than replication. The fix stamps each message and each mutating API actor (user or API key) with the primary's WAL LSN and checks pg\_last\_wal\_replay\_lsn() before reading from the replica. Lagging messages are nacked with exponential backoff, which doubles as backpressure, and replica lag is best monitored in bytes rather than time.

Written by swe.quest, not by the author.

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

## Topics

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

## Prerequisites

- PostgreSQL replication basics ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- Go context package ([easy posts on Go](https://swe.quest/tags/go.md?difficulty=easy))
- message queues ([easy posts on Queues & messaging](https://swe.quest/tags/messaging.md?difficulty=easy))

## Keywords

PostgreSQL, LSN, read replica, Write-Ahead Log, Goa, pg\_current\_wal\_lsn

## Related posts

- [Read your writes: WAIT FOR in PostgreSQL 19](https://swe.quest/articles/read-your-writes-wait-for-in-postgresql-19-ead8d2a645bd23c3.md): ClickHouse · 2026-08-25 · Medium · 6 min read · PostgreSQL, Replication, Consistency models
  PostgreSQL 19 adds a top-level \`WAIT FOR LSN\` command that blocks a session until a standby has written, flushed or replayed WAL up to a given LSN, giving read-your-writes consistency on asynchronous replicas without the per-commit cost of \`synchronous\_commit = remote\_apply\`.
- [Introducing Read Replicas](https://swe.quest/articles/introducing-read-replicas-3301ec5316ccd33a.md): Supabase · 2023-12-15 · Medium · 6 min read · PostgreSQL, Replication, Scaling
  Supabase now supports Postgres read replicas in 12 regions, up to two per project, for offloading reads and analytics, serving data closer to users, and redundancy.
- [Scaling Nextdoor’s Datastores: Part 2](https://swe.quest/articles/scaling-nextdoor-s-datastores-part-2-3bede3a52d4cf43e.md): Nextdoor Engineering · 2025-03-19 · Medium · 4 min read · Replication, Consistency models, Databases, Scaling
  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.
- [More load is faster: Tuning Postgres read replicas](https://swe.quest/articles/more-load-is-faster-tuning-postgres-read-replicas-edfe2bbdc0de0a5f.md): ClickHouse · 2026-11-17 · Hard · 9 min read · PostgreSQL, Replication, Performance engineering
  Postgres read replicas fed from archived WAL (rather than streaming replication) show a U-shaped lag curve: idle systems wait up to archive\_timeout (60s) for a 16MB segment to fill, while very high write rates make archive upload fall behind.
- [Patching the PostgreSQL JDBC Driver](https://swe.quest/articles/patching-the-postgresql-jdbc-driver-47e9400eaa77f0d2.md): Zalando Engineering · 2023-11-08 · Medium · 10 min read · PostgreSQL, Replication, Event-driven architecture, Java & JVM, Open source
  Postgres logical replication slots for clients watching low-traffic tables never advance, so the server retains all WAL generated by other tables until disk fills and the node goes read-only.

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)
