Skip to content

Elasticsearch Architecture Diagram: Nodes, Shards, Replicas and the Write Path

An Elasticsearch architecture diagram explained: node roles, the master quorum, primary and replica shards, routing, the write path, translog, refresh and shard sizing.

· Founder & developer

Published

Diagram: an indexing app sends document 42 to a coordinating-only node, which routes it to primary P0 on Data node 1; P0 replicates it to R0 on Data node 2. Three master nodes sit above, and each data node holds one primary and one replica.

An Elasticsearch cluster usually appears on architecture diagrams as one box labeled "Search". That box hides the decisions behind most production incidents: how many primary shards an index has, which nodes can become master, where the replicas live, when a write counts as done, and why a document you just indexed is not in search results yet.

This post draws a self-managed Elasticsearch cluster with the parts that matter: node roles, the elected master and its quorum, primary and replica shards, routing, the write path, the translog and refresh cycle, and shard sizing, with a diagram you can copy.

Clusters, nodes and node roles

A cluster is a set of nodes that share one cluster state. An index is a logical collection of documents, split into shards; each shard is a Lucene index on one node. What a node does depends on node.roles in elasticsearch.yml. Without it, a node gets every role except voting_only (node roles).

Role node.roles value What it does
Master-eligible master Can be elected master: creates and deletes indices, tracks nodes, allocates shards
Data data, or a tier: data_content, data_hot, data_warm, data_cold, data_frozen Holds shards; runs indexing, search and aggregations
Ingest ingest Runs ingest pipelines that transform documents before indexing
Coordinating-only [ ] Routes requests, merges search results, spreads bulk requests
# Dedicated master-eligible node
node.roles: [ master ]

# Data node for the hot and content tiers
node.roles: [ data_hot, data_content ]

# Coordinating-only node
node.roles: [ ]

Every node coordinates: it accepts a request, sends it to the shards involved and merges the answers. A node with an empty list does only that. The docs warn against adding too many: the elected master waits for every node to acknowledge each cluster state update.

The master node and the cluster state

The elected master owns the cluster state: the nodes in the cluster, every index's settings and mappings, and the routing table that says which shard copy lives on which node. It decides where shards go and tracks the in-sync copies of each shard. Every node holds a copy of the cluster state, so any node can route a request without asking the master, and the master stays off the normal write and search path.

Elections and cluster state updates need a majority of the voting configuration, the master-eligible nodes whose votes count (quorum-based decision making). With three master-eligible nodes the majority is two, so the cluster survives losing one, the same majority rule as Raft's quorum-based leader election; stopping half or more of the voting nodes at once makes it unavailable. Hence the rule: high-availability clusters need at least three master-eligible nodes, at least two of them not voting-only.

Once a cluster has more than a handful of nodes, make the master-eligible nodes dedicated, so a heavy aggregation cannot slow down cluster state updates. Set cluster.initial_master_nodes only for the first start of a new cluster, then remove it.

Shards and replicas

An index has a fixed number of primary shards, index.number_of_shards (default 1), set at creation. Each primary has index.number_of_replicas copies (default 1), a number you can change at any time (clusters, nodes and shards). Every document lives in one primary and in each of its replicas. Replicas are promoted when a primary's node fails, and they serve searches.

Elasticsearch never assigns a replica to the same node as its primary, so a single-node cluster with replicas stays yellow. To keep copies out of the same zone too, set a node attribute such as node.attr.zone and list it in cluster.routing.allocation.awareness.attributes (allocation awareness).

Cluster health Meaning (docs)
Green Every primary and replica is assigned
Yellow Every primary is assigned, some replicas are not
Red Some primaries are unassigned, so searches and writes on them can fail

Routing: which shard gets a document

The routing docs give shard_num = hash(_routing) % num_primary_shards, where _routing defaults to the document's _id. Indices created before Elasticsearch 9.4.0 use a legacy variant that takes the hash modulo index.number_of_routing_shards and scales it down to the primaries; either way, the primary count decides the shard.

That modulo is why the primary count is fixed: add one primary and almost every document belongs on a different shard. To change it, use the split API to increase it or the shrink API to reduce it; both write a new index and need a write block on the source first. Otherwise, reindex. Consistent hashing moves only a fraction of keys instead, and the database sharding diagram compares shard key strategies.

Custom routing, such as a tenant ID, keeps one tenant's documents on one shard, and a search with the same routing value hits only that shard. The risk is a hot shard when one tenant dwarfs the rest; index.routing_partition_size spreads each routing value over a group of shards.

The write path, step by step

The reading and writing documents page splits every index, update or delete into stages:

  1. Coordinating: the node that receives the request finds the shard with the routing formula and the routing table, and forwards the operation to the node holding the primary.
  2. Primary: the primary validates the operation, executes it locally and forwards it, in parallel, to every replica in the in-sync set.
  3. Replica: each in-sync replica executes the operation and responds.
  4. Acknowledgement: once all in-sync copies have responded, the primary acknowledges to the coordinating node, which answers the client.

The master keeps the in-sync set: the copies that hold every acknowledged operation. If a replica fails an operation, the primary asks the master to remove it and acknowledges only after the master confirms; the master then builds a new copy. If the primary fails, the operation waits, by default up to one minute, for a replica to be promoted. This primary-backup model, based on Microsoft Research's PacificA paper, stays fault tolerant with two copies, unlike quorum systems (database replication compares the models); the price is that one slow replica slows writes to its shard.

wait_for_active_shards defaults to 1: the write waits only for the primary to be active. A higher value is checked before the write starts, so it is not a guarantee; the _shards section of the response says how many copies succeeded.

PUT /orders
{
  "settings": {
    "index.number_of_shards": 3,
    "index.number_of_replicas": 1
  }
}

PUT /orders/_doc/42?refresh=wait_for
{
  "customer_id": "c-1001",
  "total": 129.90
}

From translog to searchable segment

A Lucene commit is too expensive to run per operation. Instead, each shard copy appends every operation to its translog, and with the default index.translog.durability: request, Elasticsearch reports success only after the translog is fsynced and committed on the primary and every allocated replica (translog). The document waits in an in-memory buffer, invisible to search.

Step What happens Default
Index Operation goes into the buffer and the translog Translog fsynced before each acknowledgement
Refresh Buffer becomes a searchable segment in the filesystem cache Every 1 s, on indices searched in the last 30 s
Flush Lucene commit and a new translog generation At the latest when the translog reaches 10 GB
Merge Small segments merged into larger ones Background

An acknowledged write is durable but becomes searchable only at the next refresh, which makes search near real-time. A get by _id is real-time by default. When a request must see its own write, use refresh=wait_for rather than refresh=true on every write, and raise index.refresh_interval during large bulk loads. The async durability mode fsyncs every 5 seconds and can lose acknowledged writes in a crash.

The read path

The node that receives a search coordinates it. It picks one copy of each shard, primary or replica, with adaptive replica selection, which weighs past response times and each node's search queue (search shard routing). Each shard runs the query on one CPU thread and returns its best hits; the coordinating node merges them, then fetches the documents for the final page.

If every copy of a shard fails, the response can still be 200 OK with partial results, so check the _shards section. Many small shards make each search use many threads, and a search with a routing value touches one shard instead of all. For per-keystroke autocomplete, a typeahead service avoids this fan-out by reading a precomputed top-k list for each prefix from memory.

Sizing shards and nodes

The shard sizing guide recommends:

  • Shards between 10 GB and 50 GB, with fewer than 200 million documents each.
  • At most 1,000 non-frozen shards per node, the default cluster limit.
  • Fewer than 3,000 indices per GB of heap on master nodes.

Say a product catalog holds 600 GB of primary data. At about 40 GB per shard that is 15 primaries; one replica makes 30 shard copies and 1.2 TB. On three data nodes, each holds 10 copies and about 400 GB. If one node fails, the other two rebuild its copies and hold about 600 GB each, so size their disks for that plus headroom.

For logs and metrics, write to a data stream and let ILM roll over at max_primary_shard_size: 50gb instead of guessing a count. Older indices can move through the data tiers: hot, warm, cold, and frozen, which holds only partially mounted searchable snapshots.

The Elasticsearch architecture diagram

Diagram: an indexing app sends document 42 to a coordinating-only node, which routes it to primary P0 on Data node 1; P0 replicates it to R0 on Data node 2. Three master nodes sit above, and each data node holds one primary and one replica.

18 components · 4 connections

Open in Archboard
Diagram contents
  • Indexing app
  • Coordinating-only node
  • Master 1 (elected)
  • Master 2
  • Master 3
  • Data node 1
  • Data node 2
  • Data node 3
  • P0: shard 0 primary
  • R2: shard 2 replica
  • R0: shard 0 replica
  • P1: shard 1 primary
  • P2: shard 2 primary
  • R1: shard 1 replica
  • 1. index _id 42
  • 2. shard 0
  • 3. replicate
  • cluster state
A self-managed Elasticsearch cluster: three dedicated masters, a coordinating-only node and three data nodes holding three primary shards with one replica each. The orange path follows one document to P0 and its replica R0.

How to read it:

  • Top row: three dedicated master-eligible nodes. The dashed purple edge is the cluster state the coordinating node routes with; the master stays off the write path.
  • Left: the indexing app sends document _id 42 to a coordinating-only node.
  • Middle: three data nodes, each with one primary (dark blue) and one replica (light blue) of a different shard.
  • Orange path: _id 42 routes to shard 0. P0 on Data node 1 indexes it, replicates it to R0 on Data node 2, then acknowledges through the coordinating node.
  • Markdown block: the write path, refresh and flush, and the index settings.

Drawing Elasticsearch diagrams clearly

  • Draw shard copies, not just nodes. The primary and replica layout explains failover and yellow health.
  • Name each node's roles: master-eligible, data with its tier, ingest, coordinating-only.
  • Keep the masters in their own row, off the data path, with their count visible.
  • Write the index settings next to the index: primaries, replicas, refresh interval and any routing key.
  • Give ingestion its own diagram. Beats, Logstash or Kafka in front of the cluster belong in a data pipeline or observability diagram.

Common mistakes are a replica on its primary's node, two master-eligible nodes, client traffic sent to the masters, and one "Elasticsearch" cylinder with no shard count.

Build it in Archboard

  1. Sign in with Google or GitHub and create a diagram.
  2. From the C4 Model pack, add a Container for the indexing app, with the client in its technology field.
  3. From the Network pack, add a Server for the coordinating-only node and three more Server nodes in a top row for Master 1 to Master 3, with a purple accent.
  4. Add three Frame nodes from the Core pack, Data node 1 to Data node 3, each holding two Box nodes: a primary in dark blue and a replica of another shard in light blue.
  5. Draw the orange path from the app through the coordinating node to P0 and R0, with numbered labels, and a dashed purple edge from Master 1 to the coordinating node.
  6. Add a Markdown block from the Core pack with the write path and settings, and three Core Text notes.

If your cluster layout lives in a Mermaid flowchart, the Mermaid converter turns it into a first draft. The example uses 15 diagram nodes, the most the Free plan allows in one diagram.

FAQ

How many master nodes does an Elasticsearch cluster need? At least three master-eligible nodes for high availability, so a majority of two survives one failure. Make them dedicated once the cluster grows beyond a handful of nodes.

Why is a document not searchable right after indexing? It becomes searchable at the next refresh, every second by default on indices searched in the last 30 seconds. Use refresh=wait_for when a request must see its own write.

Can I change the number of primary shards? Not in place. Split to increase it or shrink to reduce it; both create a new index and need the source made read-only first. Or reindex. For data streams, change the index template.

Does this apply to Elastic Cloud Serverless? Not fully. Serverless uses a stateless architecture: index data and the translog live in object storage, indexing and search run on separate nodes, and you do not configure node roles. Its refresh interval defaults to 5 seconds, also the minimum (index settings).

Start free — one seat, no credit card.

Related posts

← Back to blog

Open a canvas in a minute

Sign in with Google or GitHub. Free for a single seat. Upgrade when the team joins.