{"canonical_url":"https://engineer.company/glossary/failover/","content_markdown":"# Failover\n\n## What it is\n\nFailover moves responsibility for serving an operation from a component that is\nunavailable to another component that can take over. It can involve changing the\ndatabase that accepts writes, routing a network service to a replacement system,\nor choosing a different provider to send a message. The details follow the\nservice's responsibilities. A replacement has to be ready for the particular\nwork that is being moved.\n\nA failover procedure usually includes detection, a decision about when to\nswitch, the change itself, and a check of the result. In a replicated database,\na standby can already hold a copy of much of the primary's state. Promotion\nmakes it eligible to act as primary. The system also needs a way to prevent the\nformer primary from taking new writes when both sides can be reached again. That\nstep helps preserve a single authoritative history.\n\nFor services that call another provider, failover can choose a different route\nfor an operation. An application sending mail can try an alternate provider when\nthe first becomes unavailable. A timeout can leave uncertainty about whether the\nfirst provider accepted a message. Tracking the operation and its eventual\noutcome is part of this design. The alternate provider needs compatible\ncapabilities and enough working capacity to handle the work being moved.\n\n## Why it matters\n\nA recovery design needs to describe time and data. How long can clients wait for\na working route? How recent must the replacement's data be? What happens to a\nrequest that was active during the switch? An available replacement is only part\nof the answer. The client may still have an old connection, and queued work\nmight need a clear retry or recovery path.\n\nDetection requires care. A slow response can be a failure for an application\nwith a tight deadline, and a missed health signal can reflect a monitoring\nproblem while the primary still serves requests. An automatic decision needs a\ncondition that is meaningful to the system and evidence for resolving\nuncertainty. A manual decision can take longer but can let an operator confirm\nwhat the system has observed before changing authority.\n\nA recovery target should also name the observer. Infrastructure readiness might\nmean that a replacement database accepts connections. The product's recovery\ntime starts and ends around a user operation, including the discovery path,\napplicable client retries and a representative query. If the service has several\nentry points, exercise the critical one that reaches the replacement through\nnormal routing. Record the data that was committed before the interruption and\ncheck which part of that history a recovered client can actually see.\n\nSwitching back can be more involved than switching away. A former database\nprimary can return with an older or diverging history. A provider that responds\nagain may have accumulated delayed operation updates. Write a return procedure\nfor the actual state the system can have after a switch. Practice restoring\nredundancy separately from the initial recovery, because the service can look\nhealthy to users while running with fewer available alternatives.\n\n## What it looks like in practice\n\nEngineer's\n[email delivery case study](/portfolio/built-email-with-failover-and-delivery-logging/)\ndescribes three providers behind one interface with automatic failover. The case\nalso records sends and provider delivery events. Together those records help\ndistinguish getting a request accepted from learning what ultimately happened to\nit. The meaningful drill is to interrupt the preferred route and make sure the\napplication can explain which provider handled a specific message.\n\nAn illustrative test sends a message with a stable operation identifier, makes\nthe initial route fail, and checks the alternate route and recorded outcome.\nTest an ambiguous timeout too. The first provider might have accepted the\nmessage before the application lost the response. Track the operation through\nthe available evidence. Where the external service cannot resolve the ambiguity\nimmediately, the application needs a documented policy for retry, investigation\nor status reporting.\n\nA database failover drill has a different sequence. Record which copy is\nauthoritative, interrupt the primary and observe when a replacement can serve a\nrepresentative read and write. Check which transactions are present and whether\nthe old primary remains fenced on reconnect. Then restore the number of replicas\nthe service should have. Make the results visible to people who will have to\nrepeat the procedure under pressure.\n\n## Where it goes wrong\n\nA common oversight is to test that a standby starts and leave client recovery\nunmeasured. An application can continue using a stale address or rely on a\nsocket whose existing connection is no longer useful. Observe a real request at\nthe normal entry point. Record the start of the interruption, the first\nsuccessful operation after recovery and the data the successful operation\nreturned.\n\nBe wary of failover paths with common dependencies. Two application routes might\ndepend on the same credentials service, network path or storage. An outage can\naffect both even when their software runs on different machines. Exercise the\nshared failure points and make the replacement path easy to inspect. Keep its\nconfiguration current and include its actual capacity in a test.\n\nFinally, require an outcome for work already in flight. The primary may have\ncompleted an operation that the client could not confirm. The replacement may be\nunable to reconstruct that work with the information it has. Stable operation\nidentifiers, durable evidence and a deliberately chosen recovery point help\nresponders keep track. After the drill, state which operations succeeded, which\nrequests should be repeated and which outcomes require review. That record makes\nfailover measurable in the terms users care about.\n\n## Further reading\n\n- [PostgreSQL failover](https://www.postgresql.org/docs/18/warm-standby-failover.html).\n  Describes standby promotion and checks around the former primary.\n- [Azure SQL failover groups](https://learn.microsoft.com/en-us/azure/azure-sql/database/failover-group-sql-db).\n  Documents failover policies and connection behaviour for a managed service.\n- [The etcd operations guide for failures](https://etcd.io/docs/v3.6/op-guide/failures/).\n  Illustrates quorum-dependent availability and recovery choices.\n\n\u003chttps://engineer.company/glossary/failover/\u003e\n","date_modified":"2026-11-25T07:18:46Z","description":"Practise detection, fencing, promotion and client recovery when a standby takes over for a failing primary.","formats":{"gemtext":"https://engineer.company/glossary/failover/index.gmi","gopher":"https://engineer.company/glossary/failover/gophermap","html":"https://engineer.company/glossary/failover/","json":"https://engineer.company/glossary/failover/index.json","markdown":"https://engineer.company/glossary/failover/index.md","pdf":"https://engineer.company/glossary/failover/index.pdf"},"kind":"page","language":"en","title":"What is failover?","url":"https://engineer.company/glossary/failover/","version":1}