Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Datadog Engineering 22 min read Case study mediumAdept

When failover isn’t safe: Building high-availability PostgreSQL on Kubernetes

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. The fix is a hybrid model in which leader-pool standbys replicate synchronously while read replicas stay asynchronous. Patroni is configured with synchronous_mode, synchronous_node_count=1 and synchronous_mode_strict, and PostgreSQL with synchronous_commit=remote_apply, so a failover candidate is always current. pgbench TPC-B benchmarks across synchronous_commit levels quantify the latency and throughput cost of each durability option.

Assumes: PostgreSQL streaming replicationKubernetes basicsleader election with ZooKeeper

Related posts

  • Designing a planned switchover for minimum disruption

    PlanetScale hardMaster

    Neki performs planned Postgres primary switchovers without stopping the old primary. Routers buffer primary-bound queries, the primary is set read-only by default, and every replica except the target is disconnected so its receive_lsn fixes a final WAL position the target must replay through. Preflight checks cover shard state, failover slots and capacity settings such as max_connections, and post-convergence checks cover slots and having at least one synchronous standby attached. If any check fails before promotion, a config reload makes the old primary writable again for a fast rollback. With ANY 1 synchronous replication and synchronous_commit=on, every acknowledged commit is present on the target when it is promoted.

  • Production Postgres on Railway: From First Deploy to High Availability

    Railway mediumAdept

    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. PITR restores into a separate service for validation, and the guide stresses measuring RPO/RTO end to end, including validation and reconnection time. Transaction pooling breaks session settings, LISTEN, advisory locks and named prepared statements, so migrations should use an unpooled URL. In one small planned switchover test (primary, two replicas, etcd, HAProxy), writes were interrupted for about 17 seconds. That is a single observation, not a guaranteed failover time.

  • PostgresBench: Measuring the impact of High Availability on Managed Postgres performance

    ClickHouse mediumAdept

    PostgresBench now measures the performance cost of high-availability configurations across managed Postgres services, comparing shared-nothing designs (ClickHouse Managed Postgres, RDS, Crunchy Bridge) that use streaming standbys with shared-storage forks (Aurora, Neon) that replicate WAL to a storage layer. On a 16 vCPU/64 GB instance with a 500 GB dataset, ClickHouse's NVMe-backed service dropped to 94% of single-node TPS with one async standby and 79% with two synchronous quorum standbys, with p99 latency rising 1.8x and 2.5x. RDS throughput was roughly flat, but its p99 rose to 1.7x with one sync standby and 6.3x (817 ms) with a two-standby quorum cluster. The vendor-run results claim 2-4x throughput advantages for ClickHouse over the other services at matched compute and comparable durability.

  • Designing a reliable unplanned failover

    PlanetScale hardMaster

    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.

  • Managed Postgres on Railway

    Railway mediumAdept

    Railway's managed Postgres now covers the full database lifecycle: private-by-default services with reference-variable credentials, usage-billed vertical scaling, live volume resizing, and one-click PgBouncer pooling with a separate unpooled URL for migrations. HA conversion turns an existing node into the primary of a Patroni-managed streaming-replica cluster with etcd for leader election and HAProxy for routing, so apps keep the same endpoint through failover but still need reconnect/retry logic. Point-in-time recovery uses pgBackRest with continuous WAL archiving (weekly full, daily differential, ~4 weeks retention) and restores into a separate service. Automatic image updates, CVE patching, guided pg_upgrade major upgrades with compatibility checks, pg_stat_statements-based query statistics, and CLI/MCP agent workflows round out the platform.

The quest for software engineering knowledge.

Look:
Layout: