---
title: "Designing a reliable unplanned failover"
description: "Neki, PlanetScale's Postgres sharding system, declares a primary dead only when its control plane (Admin) cannot reach it and at least one reachable replica reports broken replication with none contradicting."
url: "https://swe.quest/articles/designing-a-reliable-unplanned-failover-ab0dd731f569d08c"
canonical: "https://planetscale.com/blog/designing-a-reliable-unplanned-failover"
source: "PlanetScale"
published: "2026-11-05"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 10
tags: ["postgres","replication","resilience","distributed-systems","distributed-databases"]
---

# Designing a reliable unplanned failover

A post on [PlanetScale](https://swe.quest/sources/planetscale.md), published 2026-11-05, 10 min read, Deep dive. Original: [https://planetscale.com/blog/designing-a-reliable-unplanned-failover](https://planetscale.com/blog/designing-a-reliable-unplanned-failover)

## Summary

Neki, PlanetScale's Postgres sharding system, declares a primary dead only when its control plane (Admin) cannot reach it and at least one reachable replica reports broken replication with none contradicting. Under ANY 1 synchronous replication, that means the primary can no longer commit. Short TCP keepalives, tcp\_user\_timeout and wal\_receiver\_timeout make crashes, dropped packets and frozen processes all surface as broken replication. Admin then blocks reconnection by prefixing the old primary's hostname in primary\_conninfo with "//", which also freezes WAL positions, and promotes the replica that has replayed through the highest received LSN so the others can follow on the new timeline. The old primary is fenced as TEARDOWN rather than rejoined, since it may hold writes the new primary lacks and is kept for postmortem.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Replication](https://swe.quest/tags/replication.md) (Distributed systems)
- [Resilience](https://swe.quest/tags/resilience.md) (Distributed systems)
- [Distributed systems](https://swe.quest/tags/distributed-systems.md) (Distributed systems)
- [Distributed databases](https://swe.quest/tags/distributed-databases.md) (Data & databases)

## Prerequisites

- Postgres streaming replication ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- WAL and LSNs
- synchronous commit
- network partitions

## Keywords

Neki, PlanetScale, PostgreSQL, synchronous\_standby\_names, pg\_stat\_wal\_receiver, wal\_receiver\_timeout, primary\_conninfo

## Related posts

- [Designing a planned switchover for minimum disruption](https://swe.quest/articles/designing-a-planned-switchover-for-minimum-disruption-c09f9387b5a40465.md): PlanetScale · 2026-10-29 · Hard · 8 min read · PostgreSQL, Replication, Resilience, Deployment
  Neki performs planned Postgres primary switchovers without stopping the old primary.
- [Fencing a Postgres primary that might still be alive](https://swe.quest/articles/fencing-a-postgres-primary-that-might-still-be-alive-67043bdd5aea0f6c.md): ClickHouse · 2026-11-04 · Hard · 10 min read · PostgreSQL, Replication, Resilience, Networking, Cloud platforms
  Before promoting a standby, a managed Postgres control plane must fence the old primary, because promotion and DNS changes alone don't stop writes: async standbys, per-session synchronous\_commit overrides, quorum commit with a remaining standby, and canceled commits already in WAL can all let a still-alive primary accept writes.
- [When failover isn’t safe: Building high-availability PostgreSQL on Kubernetes](https://swe.quest/articles/when-failover-isn-t-safe-building-high-availability-postgresql-on-kubernetes-ee0014d4b5265bb2.md): Datadog Engineering · 2026-06-04 · Medium · 22 min read · PostgreSQL, Replication, Kubernetes, Resilience, Chaos engineering
  A staging gameday simulating zonal network latency left Datadog's Kubernetes-hosted PostgreSQL clusters stuck: with asynchronous replication, every standby exceeded Patroni's maximum\_lag\_on\_failover, so no failover candidate could be promoted safely.
- [Production Postgres on Railway: From First Deploy to High Availability](https://swe.quest/articles/production-postgres-on-railway-from-first-deploy-to-high-availability-70a3bcba84354fc9.md): Railway · 2026-10-15 · Medium · 13 min read · PostgreSQL, Replication, Resilience, Cloud platforms
  Railway Postgres can grow from a single private-networked database to a production setup with volume backups, point-in-time recovery, PgBouncer connection pooling and Patroni-based high availability, demonstrated with an orders API that uses idempotency keys so retries stay safe.
- [Blocking cutovers to save replication slots](https://swe.quest/articles/blocking-cutovers-to-save-replication-slots-d52d9d5fcc4a6789.md): PlanetScale · 2026-09-21 · Medium · 5 min read · PostgreSQL, Replication, Event-driven architecture, Deployment
  PlanetScale Postgres blocks planned cutovers (resizes, parameter changes, maintenance) when logical replication slots aren't synchronized to the replica being promoted, because vanilla Postgres will promote a replica without the slot and silently break CDC consumers.

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)
