How does Elasticsearch recover from a quorum that is not unanimous
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Elasticsearch is a distributed search and analytics engine designed for horizontal scalability, resilience, and accuracy. One of its most essential aspects is its recovery mechanisms, which ensure high availability and data integrity. Among these, handling situations where quorum decisions are not unanimous is critical, given Elasticsearch's dependence on consensus for various operations, especially during shard allocation and node failures.
Elasticsearch Clustering and Quorum
In an Elasticsearch cluster, data is spread across multiple nodes. Each piece of data is represented as a shard, and each shard has a primary and potentially multiple replicas. To modify or query the data, operations usually need to reach a consensus, often in the form of a quorum. A quorum is the minimum number of nodes (or shard copies) that need to agree or acknowledge an operation for it to be considered successful.
Typically, a quorum is more than half of the nodes/shard copies. For instance, if a shard has one primary and two replica shards, the quorum size would be 2.
Non-Unanimous Quorum Scenarios
Occasionally, situations arise where the quorum does not reach unanimity. A commonly occurring situation might involve network partitions or temporary node failures—both leading to a lack of full agreement across the cluster. Here’s how Elasticsearch handles such scenarios:
- Write Operations:
- During Partition/Failure: When a node is temporarily unreachable or has failed, write operations will still be successful if the quorum can be achieved. The write succeeds with acknowledgment only from the available quorum despite not reaching all nodes. The unavailable nodes will eventually recover and catch up through a process called replica recovery.
- Post Recovery: Once network issues are resolved or a failed node comes back online, Elasticsearch will initiate a resynchronization of data. It employs a technique known as peer recovery, which ensures that all shard copies are consistent and up-to-date.
- Read Operations:
- Read operations will attempt to contact a sufficient number of nodes to provide a consistent view of the data. If a non-unanimous quorum can confirm the latest data version, the read will proceed successfully.
- Elasticsearch will try to manage inconsistencies by returning data only when it's confident it is correct, often preferring consistency over availability during such split scenarios.
Technical Explanation of Recovery Process
Reconciliation of Data
Upon a node’s re-entry to the cluster after a partition or temporary failure, the following recovery phases are implemented:
- Discovery Phase:
- The rejoining node first updates its view of the cluster’s metadata through the zen discovery module.
- Data Recency Check:
- Metadata version checks enable nodes to compare the data they hold against the master node’s record. Nodes utilize sequence numbers and
primary termsto ensure the right updates are handled meticulously.
- Peer Recovery:
- During the peer recovery stage, eligible shards are recalculated. If a shard held by the recovering node is outdated, data will be transferred from its primary or other up-to-date replica nodes.
- This process involves identifying missing translog (transaction log) operations to bring replicas up-to-date, minimizing data resynchronization overhead.
- Cluster State Updates:
- Once recovery is complete, the cluster state is updated. The master node broadcasts these updates across the cluster, ensuring a consistent state and that all nodes acknowledge it.
Example Scenario
Imagine a 3-node cluster with a single index of primary shard P1 and its replicas R1, R2. Let's see what happens when one node (holding R1) fails:
- Initial Fallback:
P1is still operational to handle writes and certain reads.R2is used to ensure redundancy. - Quorum Write Approval: During
R1's downtime, new writes are acknowledged byP1andR2. - Reintegration of
R1: OnceR1is back, it undergoes peer recovery, updating its data by reapplying missed translog entries since its last synchronization. - Cluster Health: The cluster returns to a green state upon achieving full data synchronization and successful acknowledgment of all shard copies.
Summary
| Key Point | Description |
| Quorum | More than half of nodes in agreement (e.g., majority of primaries and replicas). |
| Resilience | Handles node failures/partitions by allowing write operations with minimum quorum. |
| Recovery Process | Involves node reintegration, metadata updates, and peer recovery for concurrency and data consistency. |
| Consistency Techniques | Uses sequence numbers and primary terms for data integrity. |
| Use of Translog | Minimizes data loss and synchronization overhead by retaining operation logs. |
Understanding how Elasticsearch recovers from non-unanimous quorums helps optimize its performance and improve fault tolerance in distributed environments. The technical underpinnings ensure not only recovery but also real-time adaptability to maintain consistency across the cluster.
Related reading
- How does Erlang's support for transparent distribution of actors impact application design?
- How does etcd propagate writes to non-leader members?
- How does fault tolerance works in a distributed system?
- How does Google file system deal with write failures at replicas?
- How does finding a cycle start node in a cycle linked list work?
- How does Firefox's 'awesome' bar match strings?
- How does gRPC connection work on kubernetes service ClusterIP
- How does High Replication Datastore implement consistent reads

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.