Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Cluster Anatomy and Mappings  ›  Lesson

Shards, Replicas and the Split-Brain Problem

Primary Shards 15 minAn index is split into primary shards and copied into replica shards that never share a node with their primary, and a majority vote of master-eligible nodes prevents split brain.

Shards, Replicas and the Split-Brain Problem

The books index grows past what one machine can comfortably hold, and the shop cannot afford for search to vanish when one server dies. Elasticsearch solves both problems by cutting every index into shards and copying them.

The rule

Primaries split the data; replicas copy it; never on the same node.

  • A primary shard holds one slice of an index's documents. Each document lives in exactly one primary, chosen by hashing its ID. Spreading primaries across nodes spreads storage and work.
  • A replica shard is a full copy of a primary. It protects against a node dying and can also answer searches, adding read capacity. Elasticsearch never places a replica on the same node as its own primary — a copy on the same machine would die with it.

In version 8 a new index gets 1 primary and 1 replica by default. You can set both:

PUT /books
{
  "settings": { "number_of_shards": 3, "number_of_replicas": 1 }
}

That gives 3 primaries + 3 replicas = 6 shards. The replica count can change at any time; the primary count is fixed at creation (changing it means split, shrink or reindex into a new index).

Cluster health reports the result: green — every shard placed; yellow — all primaries placed but some replicas are not; red — at least one primary is missing. A single-node cluster with default settings is yellow: there is nowhere legal to put the replica.

Split brain is the cluster-level danger. If a network fault cuts a cluster in two and each half elects its own master, both accept writes and the data diverges. Elasticsearch prevents it by requiring a majority of master-eligible nodes to elect a master. With three master-eligible nodes, the side with two can elect one; the side with one cannot, so it stops accepting changes. That is why production clusters use at least three master-eligible nodes.

The shortcut

Count shards as primaries × (1 + replicas), and predict health by asking "can each copy find a node without its twin?"

2 primaries, 1 replica, on 2 nodesStep 1 of 3
  1. Count

    2 × (1 + 1) = 4 shards: P0, P1, R0, R1.

Drills

Answer fast — trust the rule.

quick drill

An index has 4 primary shards and 2 replicas. How many shards in total?

quick drill

A single-node cluster holds books with default settings. What is its health?

quick drill

Which of these can you change on an existing index with a simple settings update?

quick drill

A network split leaves one master-eligible node on one side and two on the other. What happens?

Remember

  • Primaries split the data; replicas copy it; never on the same node.
  • Total shards = primaries × (1 + replicas); replicas change freely, primaries do not.
  • A majority of master-eligible nodes must agree — use at least three to avoid split brain.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainSurvive a node failure

The books index has 3 primaries and 1 replica on a 3-node cluster. Explain how many shards exist, how they could be placed, what happens to health and data when one node dies, and why the cluster has three master-eligible nodes instead of two.