TGViewer
DevOps&SRE Library DevOps&SRE Library @devopslibrary · 19.9K subscribers
Post #7457 2.67K
When failover isn't safe: Building high-availability PostgreSQL on Kubernetes

Gamedays are one of the most effective ways we proactively uncover gaps in our systems and processes. At Datadog, we regularly run a variety of gamedays to intentionally stress our platforms and learn how our systems and teams respond under real-world conditions. These exercises help us surface hidden vulnerabilities, strengthen our operational readiness, and continually raise the bar for our infrastructure.

During one such gameday, a simulated zonal failure introduced targeted disruptions in an availability zone on a staging environment by inducing network latency, which exposed a weakness in our PostgreSQL architecture. Several of our Kubernetes-based PostgreSQL clusters had primary or writer nodes running in the affected availability zone. As network latency spiked, those primaries could no longer communicate reliably with their replicas. Replication lag quickly grew, writes stalled, and applications began serving stale data. Because no replica was sufficiently up to date, failover wasn’t safe and the clusters were effectively stuck.

We rely on PostgreSQL as the backend database for many Datadog products, and this architecture has served us well under normal conditions. But the gameday revealed an uncomfortable truth: In the face of certain network failures, our setup prioritized availability over durability in ways that left us with no safe recovery path.

In practice, this meant the primary continued accepting writes even while replication to replicas was delayed due to elevated network latency. The system remained writable, but replication lag continued to grow, and replicas drifted further behind the primary. As a result, failover candidates could no longer be promoted safely without risking data loss. We were left with only one viable option: wait for latency to subside and for replicas to catch up.

We set out to fix this failure mode. Our goal was to make failover both automatic and safe, without compromising PostgreSQL’s performance characteristics more than necessary. To do this, we rearchitected our PostgreSQL deployment to use synchronous replication for failover candidates, coordinated by Patroni, an open source high-availability manager.

In this post, we’ll walk through how we redesigned our Kubernetes-based PostgreSQL clusters for failover safety, how we balanced durability against latency, and what we learned while validating this approach through benchmarking and failure testing.


https://www.datadoghq.com/blog/engineering/postgresql-ha-kubernetes
More from @devopslibrary
  1. Sep 26, 2026k8s-overcommit Operator The k8s-overcommit Operator is a Kubernetes operator designed to i…
  2. Sep 25, 2026kstack Kstack is a skill pack for Claude Code that helps you perform monitoring, troublesh…
  3. Sep 25, 2026Klarity Klarity is an open-source, enterprise-grade Kubernetes observability dashboard bui…
  4. Sep 24, 2026✨ Как настроить PostgreSQL для продакшен-нагрузок При переходе к продакшен-нагрузкам важно…
  5. Sep 24, 2026IPMan - IPSec Connection Manager for Kubernetes IPMan is a Kubernetes operator that simpli…
  6. Sep 24, 2026Autoscalable GitLab runners on AWS EC2 This article shares our experience of getting rid o…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →