System design interview guide
Elasticsearch System Design Interview: Building a Distributed Full-Text Search Engine
Short answer
Elasticsearch is a distributed search engine built on Apache Lucene. Its core is the inverted index, which maps each word to the documents that contain it. An index is split into shards, each a complete Lucene index, and each shard can have replicas. Writes go to a memory buffer and to a translog for durability, and a refresh every second makes them searchable. A search goes to every shard, and a coordinating node merges each shard's top results.
Two courses by the author of this page:
770 lessons · 18 free to read
₹1,111 in India · $35 elsewhere, once
Get System DesignYou own this course
219 lessons · 10 free to read
₹1,333 in India · $35 elsewhere, once
Get Generative AI and Agentic AIYou own this course
Save your progress and get the interview checklist PDF
A single logical index in Elasticsearch is really a collection of Lucene indexes spread across shards, and a large cluster can hold thousands of shards across dozens of nodes serving both full-text queries and analytics. Public case studies describe clusters ingesting on the order of millions of documents per second and holding petabytes of data across hundreds of nodes. Exact figures vary by workload and are best treated as estimates, but the shape is clear: search has to be fast on data that is constantly being written.
Elasticsearch is a distributed search engine built on top of Apache Lucene. The core data structure is the inverted index, which maps each term to the list of documents that contain it, so a full-text query becomes a set of postings-list lookups rather than a scan. A logical index is split into shards, each shard is a self-contained Lucene index, and each shard can have replicas for availability and read throughput. Writes go to an in-memory buffer plus a durable transaction log, then a periodic refresh turns the buffer into a searchable Lucene segment, which is why search is near real-time rather than immediate. Reads fan out to every shard, each shard returns its top matches, and a coordinating node merges those partial results. A master node owns cluster state and shard allocation, and quorum-based election prevents split-brain. The interesting design tension is that Lucene segments are immutable and search wants fresh data, so the engine trades a small refresh delay and background segment merges for high indexing and query throughput.
Where it shows up
Asked at Elastic, companies that run large logging and observability platforms, and search teams at product companies like Uber, Netflix, and GitHub. It also comes up as a generic design a distributed search engine or design a full-text search prompt at most large tech firms.
Spec sheetElasticsearch
- 01Documents per index
- Billions (estimate)
- 02Recommended shard size
- 10 to 50 GB per shard
- 03Refresh interval
- 1 second default
- 04Query fan-out
- 1 request to N shards
worked through below, with the maths
in this guide
Design Elasticsearch, part by part
7 parts open to everyone · 3 with a free account · 3 with the course
You can read 7 of 13 parts. A free account opens the deep dive; the course opens all of it.
- Requirementsopen
- Scale estimatesopen
- High-level architectureopen
- Core componentsopen
- Data modelfree account
- Deep dives (7)free account
- Trade-offs to discussfree account
- What the interviewer asks nextwith the course
- The interview scorecardwith the course
- Mock interview on this questionwith the course
- How Elasticsearch actually does itopen
- Frequently asked questionsopen
- Interview readiness checkopen
The hard parts of this design are taught step by step in the System Design course: Database Indexing, Database Sharding and Write-Ahead Logging.
Why this question is asked
This problem forces a candidate to reason from a data structure up to a distributed system. You have to explain how full-text search actually works with an inverted index and a scoring function like BM25, then layer on sharding, replication, and query fan-out, then handle the hard consistency and coordination questions. It rewards people who understand that immutable segments, a write-ahead log, and a refresh interval are not accidental details but the mechanism that lets one engine be both write-heavy and read-heavy. It also exposes whether a candidate can talk about scatter-gather latency, the master and cluster state, and why search is eventually consistent by the refresh interval.
This page is the free part.
The course goes deeper on the Elasticsearch design
₹1,111 in India$35 everywhere elseonce, for the whole course
The System Design course covers the Elasticsearch design across a run of lessons, not one page. These 4 alone are about 133 minutes of step-by-step reading, every one with a quiz.
- Database Indexing
The planner stopped using an index somewhere between 19.7 and 39.8 percent of the table. A query on the second column of a composite index took 37.269 ms against 0.054, and five indexes took the same inserts from 160 ms to 751.
- Database Sharding
Splitting a database across multiple servers, the nuclear option for scaling writes, and the architecture behind Instagram, Uber, and YouTube.
- Write-Ahead Logging
Write changes to a sequential log before applying them, the foundation of database crash recovery.
- Quorum in Distributed Systems
What is quorum in system design? How read and write quorums work, why R + W > N, sloppy quorums, hinted handoff and quorum vs consensus, with a lab.
all part of
System Design Masterclass
770 lessons · about 290 hours · 18 free to read
₹1,111in India, by UPI
$35everywhere else, by card or PayPal
You own this course
Continue with Database Indexingpay once,
yours for life
Live from the course bench
Before you design Elasticsearch, try the questions it rests on.
Real interview questions, live diagrams and measured lab results, pulled at random from the lessons. A new set every time you come back.
Requirements
Always clarify these in the first 5 minutes of the interview. Do not start drawing boxes until both lists are agreed.
Functional requirements
- Index documents (JSON) into named indices and make them searchable
- Full-text search over analyzed text fields with relevance ranking
- Structured filtering, sorting, and pagination alongside full-text queries
- Aggregations for analytics such as term counts, histograms, and metrics
- Near real-time visibility so a newly indexed document is searchable within about a second
- Update and delete documents, including partial updates
- Multi-field mappings with configurable analyzers per field
- Horizontal scale by adding nodes and shards without downtime
- Cluster self-healing: reallocate shards when a node fails
Non-functional requirements
- Low query latency for common searches, typically tens of milliseconds
- High indexing throughput under sustained write load
- Durability so acknowledged writes survive a node crash
- High availability through replica shards and automatic failover
- Horizontal scalability of both storage and query capacity
- Tunable consistency between write acknowledgement and search visibility
- Fault tolerance against node loss and network partitions without split-brain
Back-of-envelope scale estimates
Show your math. Pulling numbers from thin air signals you have not thought about the load.
Documents per index
Billions (estimate)
A single Lucene shard is limited to about 2.1 billion documents (the Java int document id limit). With, say, 20 shards an index can hold tens of billions of documents. Derived from the per-shard cap times shard count.
Recommended shard size
10 to 50 GB per shard
Elastic guidance suggests keeping shards in the tens of gigabytes so recovery and rebalancing stay fast. A 2 TB index therefore wants roughly 40 to 200 primary shards. Derived from total size divided by target shard size.
Refresh interval
1 second default
The default refresh_interval is 1s, which is the source of the near real-time label: a document indexed at time T is searchable around T plus 1s. Published default.
Query fan-out
1 request to N shards
A search hits every shard of the target index. A 50 shard index means the coordinating node waits on 50 partial results before merging, so tail latency of the slowest shard dominates. Derived from the scatter-gather model.
Replica read scaling
Linear with replica count (estimate)
Each replica can serve reads independently, so going from 1 to 2 replicas roughly doubles read capacity for that index at the cost of extra storage and indexing work. Estimate based on the primary-plus-replica model.
Master-eligible nodes for quorum
3 (common choice)
To tolerate one master-eligible node failing while still forming a quorum of (n/2)+1, you need at least 3 dedicated master-eligible nodes. Derived from the quorum formula.
High-level architecture
A client sends an index or search request to any node, which acts as the coordinating node for that request. For a write, the coordinating node hashes the document routing value, by default the document id, to pick the target primary shard, forwards the operation to the node holding that primary, the primary appends the operation to its in-memory buffer and its transaction log, then replicates the operation in parallel to each replica shard before acknowledging. The document is durable at that point but not yet searchable; a background refresh, by default every second, turns the buffered operations into a new immutable Lucene segment and opens it for search. For a query, the coordinating node broadcasts the search to one copy (primary or replica) of every shard in the index. Each shard runs the query against its inverted index, computes relevance scores, and returns its own top K document ids and scores. This is the query phase. The coordinating node merges all the partial top-K lists into a global ranked list, then runs a fetch phase that retrieves the full source documents only for the final results. Meanwhile a master node maintains cluster state, which nodes exist, where every shard lives, and the index mappings, and it drives shard allocation and rebalancing when nodes join or leave.
In a real interview, sketch this on the whiteboard before diving into any single box.
Core components
Walk through each service. The interviewer wants to hear what each one owns, not just the names.
Inverted index (Lucene)
The heart of search. For each term it stores a postings list of the documents that contain that term, plus positions and frequencies. A full-text query resolves to a set of postings-list lookups and a merge, which is why matching is fast even over huge corpora.
Analyzer and mapping
Mapping defines each field's type and which analyzer processes it. An analyzer tokenizes text, lowercases, removes stop words, and applies stemming so that running matches run. The same analyzer runs at index time and query time so terms line up.
Shard
A shard is a complete, self-contained Lucene index and the unit of scale and distribution. An Elasticsearch index is partitioned into a fixed number of primary shards at creation, and documents are routed to shards by a hash of the routing key. Adding shards spreads data and query work across nodes.
Replica shard
A replica is a full copy of a primary shard on a different node. Replicas provide availability, since a replica can be promoted if the primary's node dies, and read throughput, since queries can be served by primary or replica. Writes must reach the primary and its replicas.
Translog
The transaction log is a per-shard write-ahead log. Every indexing operation is appended to the translog before the write is acknowledged, so an operation that has not yet been committed into a Lucene segment can be replayed after a crash. This is what makes an acknowledged write durable.
Coordinating node
Any node can coordinate a request. For writes it routes to the right primary; for reads it fans the query out to all shards, merges the partial results in the query phase, and runs the fetch phase for the final hits. It also handles pagination and aggregation reduction.
Master node and cluster state
One elected master owns the cluster state: node membership, shard allocation, and index metadata. It decides where shards live, drives rebalancing and recovery, and publishes state changes. It does not sit in the data path for normal queries, so it stays lightweight.
Data model
index (logical). A logical namespace for documents. Primary shard count is fixed at creation because routing depends on it; replica count can change at runtime. Mappings define fields…
Every table for Elasticsearch, its keys, and which store fits it and why.
Deep dives
The inverted index and relevance scoring. Full-text search does not scan documents. At index time the analyzer breaks each text field into terms, and Lucene builds an inverted index mapping each term to a…
7 deep dives on the parts that break at scale: The inverted index and relevance scoring; Segments, refresh, and why search is near real-time; The translog and durability.
Trade-offs to discuss
Immutable segments versus in-place updates. Immutability gives lock-free reads, aggressive caching, and safe replication, which is what search needs. The price is that updates and deletes create garbage that a…
6 decisions an interviewer expects you to defend, each with the alternative and why it loses here.
What the interviewer asks next
You need to bulk-load 2 TB into a new index as fast as possible. What do you change?
3 follow-up questions with model answers, the interview scorecard for this question, and a mock interview on Design Elasticsearch with the AI tutor.
How Elasticsearch actually does it
Elasticsearch is built directly on Apache Lucene, and most of the deep behavior here, the inverted index, immutable segments, per-segment search, and BM25 scoring, is Lucene's, wrapped by Elasticsearch with sharding, replication, and cluster coordination on top. Elastic's own documentation describes the near real-time model and the refresh, and the translog and flush mechanism for durability. The cluster coordination layer was rewritten in version 7 to a quorum-based consensus that removes the old minimum_master_nodes footgun and lets the cluster decide its own quorum, which is documented in Elastic's discovery and quorum guides. The original Elasticsearch: The Definitive Guide remains the clearest narrative source for how a document becomes searchable and how distributed search fans out and merges.
Lessons to study before this interview
If any of these topics are fuzzy, the interviewer will catch it. Each lesson is 15 to 60 minutes with diagrams, code, and a quiz.
Frequently asked questions
interview readiness
Are you ready for Design Elasticsearch?
Three questions from this guide. Answer them without scrolling up, the way you would have to in the room.
Go deeper
This guide is built on these 5 lessons. Each one teaches one piece of the Elasticsearch design above, step by step.
- Database IndexingSystem Design · database fundamentals · 26 min
- Database ShardingSystem Design · database fundamentals · 35 min
- Write-Ahead LoggingSystem Design · consistency models · 17 min
- Quorum in Distributed SystemsSystem Design · distributed systems core · 55 min
- Split-BrainSystem Design · distributed systems core · 43 min
Practice with 770 system design lessons
Lifetime access for ₹1,111 in India or $35 elsewhere. Interactive diagrams, quizzes, and 20 capstone projects to practise on.
This one question is not enough for the interview.
Get all 200 questions in the System Design and Distributed Systems pack
Each question has why it is asked, a full answer, what the interviewer listens for, the follow-ups, the common mistakes and a diagram (268 diagrams in all). A PDF you keep, junior to staff level.
Pay by UPI, cards or netbanking through Razorpay. Pay by card or PayPal, in US dollars. Download at once from My packs.
NEWSystem Design Hands-On
Included in the System Design course: real systems, built live
Postgres Sharding: Complete Hands-On (PgBouncer + Citus). 2 h 36 min and 20 chapters: one PostgreSQL loaded until it breaks, then four shards behind a router you write, PgBouncer and Citus, with the 139-page slide deck. The first 15 minutes are free to watch.


