Why Failover Fails When You Need It, and How to Test It on Every Deploy

A standby region or a second cluster won’t save you if nobody moves traffic to it until the outage. Benjamin Cane makes this case in If you want failover to work well, use it often. An idle failover path decays without anyone noticing.

The fix is to move real traffic on purpose, ideally on every deploy. This post covers why health checks and yearly drills miss the decay, how to start in 30 days, and where the advice costs more.

Table of Contents

Why idle failover breaks

Cane’s example is a warm standby. The app is running, the infrastructure is provisioned and health checks pass. Then it sits idle for months.

While it sits, things change under it. Cane names three. Database connections can go stale when the pool has no idle timeout or maximum lifetime. Firewall rules can change. Credentials can expire. A health check catches none of this unless it uses the same dependencies, network paths and credentials as real traffic.

Active-active has its own gap. When one environment drops out, the rest take its load. Cane says he usually sees this with teams running three or more environments. Their normal failover takes them to two, but sometimes they have to run on one, and that one can’t carry the full volume.

Yearly drills don’t close the gap either. One developer in the discussion worked somewhere with a yearly disaster recovery check. When they really needed it, recovery took about a week. Another watched their team slide from real exercises to tabletop sessions, until DR only existed in strategy documents.

Setup Why it looks ready What breaks on the day
Warm standby Health checks pass Stale connections, changed firewall rules, expired credentials
Active-active Every site serves traffic The surviving site can’t take the full load
Yearly DR drill Last year’s drill passed A year of changes nobody tested
Tabletop exercise Everyone agreed on the steps Nothing actually moved

The missing basic: fail over on every deploy

Cane’s answer is to use failover as part of normal operations. When you release, move traffic away from an environment, deploy and validate, then move it back. That counts as a planned failover, and you learn fast whether it worked.

Frequency pays off twice. The team gets used to the procedure, and nobody wants to repeat a complicated manual procedure every week, so they automate it.

The research points the same way. A 2014 OSDI paper studied 198 user-reported failures in Cassandra, HBase, HDFS, Hadoop MapReduce and Redis. The authors found that most catastrophic failures “could easily have been prevented by performing simple testing on error handling code.” A failover path is error handling at the scale of the whole system.

Martin Fowler’s version is frequency reduces difficulty: if it hurts, do it more often. His argument fits work where the pain grows with the time since you last did it.

Developers in the discussion described the payoff:

  • One company fails over to a different data center every week. A release used to take 8 hours and 10 to 15 engineers. Now it takes 1 to 2 minutes and one engineer.
  • One team saw its monitoring blip for about a minute when failing back. They traced it to firewall state that wasn’t replicating, which would have hit every existing connection. Now they fail over about once a month to patch hosts.
  • One team runs five clusters and weights traffic to one of them as if two clusters had already failed. That proves the survivors can carry the load.

It doesn’t fit every setup, and the thread named the limits.

  • Cane’s own caveat: a planned traffic shift is different from an unexpected failure. If you rely on automatic detection and recovery, test that separately.
  • Cost: one developer’s primary runs on premises while the failover runs in the public cloud. Failing over on each of several daily deploys would add cost they’d have to justify.
  • Boot dependencies: one developer’s config system needed Consul to be up during startup. For them, turning servers off daily added risk and gave nothing back.
  • Human error: at one company with a monthly site switch, a botched switch led the next one to overwrite current data with old data.

I’d read those limits as reasons to automate and to pick a schedule you can afford. They aren’t reasons to skip the practice. If every deploy is too expensive, weekly beats yearly.

How to start in 30 days

This is the schedule I’d suggest for a team that has never switched on purpose.

Week 1: pick one stateless service. Write down the switch procedure. Run a planned switch during business hours, with people watching and a tested way back.

Week 2: check that a failover event pages on-call. As one developer put it, you do have alerts for failover events, right?

Week 3: wire the switch into deploys. Drain one environment, deploy, validate, then move traffic back. Time every step.

Week 4: try one stateful system. For PostgreSQL on Patroni, a planned switch is a switchover, which the docs describe as the command for a healthy cluster. This is the example from the patronictl docs, trimmed:

# planned switchover on a healthy cluster
patronictl -c postgres0.yml switchover batman --leader postgresql0 --candidate postgresql2 --force
# ...
# 2023-09-13 14:15:23.07497 Successfully switched over to "postgresql2"
# + Cluster: batman (7277694203142172922) -+---------+----+-------------+---------+------------+---------+
# | Member      | Host           | Role    | State   | TL | Receive LSN |     Lag | Replay LSN |     Lag |
# +-------------+----------------+---------+---------+----+-------------+---------+------------+---------+
# | postgresql0 | 127.0.0.1:5432 | Replica | stopped |    |     unknown | unknown |    unknown | unknown |
# | postgresql1 | 127.0.0.1:5433 | Replica | running |  6 |   0/4000188 |       0 |  0/4000188 |       0 |
# | postgresql2 | 127.0.0.1:5434 | Leader  | running |  6 |             |         |            |         |
# schedule the switch for a fixed time instead
patronictl -c postgres0.yml switchover batman --leader postgresql0 --candidate postgresql2 --scheduled 2023-09-13T18:00-03:00 --force

Use patronictl failover when the cluster is unhealthy. Check the lag columns before you switch.

Before each stateful switch, answer Cane’s three questions:

  • What happens to data? Will replication delay cause a problem?
  • What happens to in-flight requests? Do clients retry, and are those retries safe? See idempotency keys for money movement.
  • How long does the switch take, and is that acceptable?

After week 4, track switch duration and failed switches the way you track deploys. Then add capacity tests: run the survivors at the load they’d carry if a site dropped.

FAQ

How often should you test failover?

As often as you deploy, if your architecture allows it. Cane suggests using the failover path to move traffic on each release. If that costs too much, a fixed weekly switch is still far better than a yearly drill.

What is the difference between switchover and failover?

In Patroni, a switchover is a planned role change on a healthy cluster with a leader. A failover is for an unhealthy cluster. Practice switchovers often, and test failover separately.

Why do health checks pass when failover fails?

A health check often skips the dependencies real traffic uses. Cane points out that stale connections, changed firewall rules and expired credentials can hide on an idle standby. Only real traffic, or a check on the same paths, finds them.

Is a tabletop disaster recovery exercise enough?

No. In a tabletop exercise people talk through the steps, and no traffic moves. Developers in the discussion described DR plans that passed on paper and then took a week to recover in practice.

Does active-active remove the need to test failover?

No. Active-active avoids most of the stale-standby problems, but the survivors still have to take the extra load. Cane often sees teams that plan to drop to two environments and end up on one.

Does planned failover test automatic failure detection?

No. Cane notes that a planned traffic shift is different from an unexpected failure. If you rely on automatic detection and recovery, test those mechanisms on their own.

Sources

Related posts: