What is Failover?
Failover is the process of automatically or manually promoting a replica database to primary when the active node fails, ensuring continued availability.
Failover is a fault-tolerance mechanism in database systems that transfers control from a failed primary node to a standby replica. When the active database instance becomes unreachable due to hardware failure, software crash, or network partition, the system or an administrator promotes a designated replica to take over as the new primary. This transition can be automatic, triggered by a health-check timeout or a consensus protocol, or manual, requiring an operator to verify the failure and initiate the promotion.
The process typically involves several steps. First, the failure must be detected, often through heartbeat signals or a distributed consensus algorithm such as Raft or Paxos. Next, the system ensures that any in-flight transactions are either committed or rolled back, and the replica catches up to the last consistent state using a write-ahead log or replication stream. Finally, the replica is promoted, its role is updated in the cluster metadata, and client connections are redirected to the new primary. The time from failure to full read-write availability is called the recovery time objective (RTO).
Failover is a core component of high-availability database architectures, including active-passive clusters, primary-replica replication, and multi-region deployments. It differs from switchover, which is a planned, graceful role reversal. Failover alone does not guarantee data durability; synchronous replication or semi-synchronous replication is often paired with failover to minimize data loss. Common implementations include PostgreSQL streaming replication with Patroni, MySQL InnoDB Cluster with Group Replication, and MongoDB replica sets.
Key facts
- Failover can be automatic (triggered by health checks) or manual (operator-initiated).
- The promoted replica must be consistent with the failed primary, typically via a write-ahead log.
- Recovery time objective (RTO) measures the duration of a failover event.
- Failover does not prevent data loss unless synchronous replication is used.
- Common in clustered databases like PostgreSQL, MySQL, and MongoDB replica sets.
How it works in practice
Related terms
References
More in Databases
ACID
ACID (Atomicity, Consistency, Isolation, Durability) is a set of properties guaranteeing reliable database transaction processing, ensuring data integrity despite concurrent access or failures.
B-Tree Index
A B-Tree index is a self-balancing tree data structure that maintains sorted data for efficient insertion, deletion, and range queries in database systems.
BASE
BASE is a design philosophy for distributed databases that prioritizes availability and partition tolerance over immediate consistency, making it a looser alternative to ACID in NoSQL systems.
CAP Theorem
CAP theorem states that a distributed data system cannot simultaneously provide consistency, availability, and partition tolerance; it can only guarantee two of the three.
Connection Pool
A managed cache of database connections that applications reuse rather than opening and closing a connection for each query, reducing latency and server load.
Foreign Key
A column or set of columns in a database table whose values must match a primary key in another table, ensuring referential integrity between the two tables.
Hash Index
A data structure that maps keys to storage locations using a hash function, providing constant-time equality lookups but no ordered or range scans.
Materialized View
A database object that stores the precomputed result of a query as a table, refreshed periodically or on demand to improve read performance and reduce computational overhead.
NoSQL
NoSQL is a family of non-relational database systems designed for flexible schemas, horizontal scaling, and high-throughput data access that traditional SQL databases cannot easily provide.
Read Replica
A read replica is an asynchronously updated copy of a primary database instance used to offload and scale read-only query traffic without affecting the source database's write performance.