</> MAANG.io
system design · 201

Intermediate

Master system design interviews with scalable architecture patterns, distributed systems, and real-world design challenges.

0/124 solved 0% complete

Elasticsearch

maang.io System Design Series


Elasticsearch takes Lucene and distributes it: an index splits into shards (each a Lucene index) with replicas, spread across nodes. It adds near-real-time indexing (buffer → refresh → segment, with a translog for durability), scatter-gather query then fetch, and a rich query DSL and aggregations. It's the default answer for full-text search and log analytics at scale.

This deep dive comes in four parts:

  • Foundations & Core Concepts — indices, shards/replicas, and document routing.
  • Internals — the near-real-time model, translog, refresh/flush, and segment merges, with worked numbers.
  • Advanced Internals — node roles, the query/fetch phases, mappings, and doc values for aggregations.
  • Interview — Staff/Principal Q&A: sizing shards, and when not to use it as a primary store.

Elasticsearch — Part 2: Internals & The Near-Real-Time Write Path

maang.io System Design Series


What is this?

Back to the library. In Part 1 we saw the master index that answers "who mentions X?" Now zoom into one branch and watch the librarian actually file a new book. A careless librarian would tear apart the branch's entire index every time a book arrives — reopen it, insert the new terms in the right alphabetical slots, re-stitch it. Unworkable. A clever librarian does something else: they jot the arrival in a daybook (so nothing is ever lost), keep the new book on a small incoming cart that's itself indexed, and periodically bind that cart's worth of arrivals into a small, sealed booklet that gets added to the shelf of booklets. Searches just consult all the booklets. Old booklets are never edited — occasionally several small ones get re-bound into one big tidy one.

That is almost exactly how a single Elasticsearch shard stores data, and it explains its two headline properties: writes are cheap, and a document becomes searchable about a second after you index it — "near real time," not instant, and there's a precise reason why. The sealed booklets have a name — Lucene segments — and the daybook is the translog. Let's build the whole picture from the inverted index up.

The one-line idea: A shard never edits its search index in place. New documents land in an in-memory buffer, get periodically refreshed into a brand-new immutable segment (that's when they become searchable), and are protected in the meantime by an append-only translog. Deletes and updates don't erase anything — they mark old data dead, and background merges reclaim it later. Immutability is the whole trick.


Sign in to continue reading

The rest of this lesson is available with a free account. Signing in with Google or Microsoft is free.

Sign in to read the full lesson

Sign in to MAANG.io

Use your Google or Microsoft account — no password to remember.

Continue with Google Continue with Microsoft

Please accept the terms above to continue.