Reads hard-wired to a single replica: Whole site goes down when the read replica is rebooted
Reads hard-wired to a single replica debugging lab. We run one primary and one read replica. Ops rebooted the replica for a patch, and for four minutes every page returned 500 even though the primary was healthy.
Practice debugging a reads hard-wired to a single replica in a live, broken production system in your browser, with PostgreSQL. Find the root cause in the logs, terminal and code, fix it, and a load test checks that the fix holds under real traffic.
1. The Incident Context
We run one primary Postgres and one read replica. Ops rebooted the replica for a patch, and for four minutes every page returned 500 — even though the primary was healthy the whole time.
2. Observed Symptoms & Metrics
- Affected Endpoints / Components:
GET /products/:id, the read replica, the primary Postgres.
- Behavior: While the replica is down, every product read returns 500. Writes still succeed. The primary has all the data.
- Error Rate: 100% of reads fail during the outage.
- System Metrics: The primary is idle. The replica's connection pool reports
connection refused or reset connections.
3. Application Logs
02:04:02 catalog service listening on :8080
02:05:11 GET /products/7 500: read tcp 127.0.0.1:6432: connection reset by peer
02:05:12 GET /products/7 500: read tcp 127.0.0.1:6432: connection reset by peer
4. Your Objective
Step into the live environment while synthetic traffic is running, diagnose the root cause, and patch the codebase.
To clear this stack, your fix must satisfy these automated verification checks under a 60-second replica outage:
- Failover: Every read still succeeds while the replica is down.
- Performance: Read p99 stays below 500 ms.
- Data Integrity: All 50 products are still present.
Toolbox: curl localhost:8080/products/7, curl -X POST localhost:9600/down, psql "$DATABASE_URL", the app logs.
Reads are hard-wired to the replica. Health-check it and send reads to the primary while it's down, then back to the replica once it recovers.
Save a file in the editor to rebuild and restart the app. Click Verify when you think it's fixed.
Your account and data
You can browse stacks without an account. To run labs you sign in with your email or Google account. BustedStack uses your email address to
sign you in, and your name and profile picture to show your account and pre-fill certificates. We never access your Gmail, contacts or Drive,
sell your data or run ad trackers.
Privacy Policy · Terms of Service · Browse stacks ·
hello@bustedstack.com
This site needs JavaScript to run labs.