Apache Lucene
maang.io System Design Series
Apache Lucene is the engine inside Elasticsearch and Solr. Its heart is the inverted index β a map from each term to the list of documents containing it β built through an analysis pipeline (tokenize, lowercase, stem) and stored in immutable segments. Add BM25 relevance scoring and you have the machinery behind fast, ranked full-text search.
This deep dive comes in three parts:
- Foundations & Core Concepts β the inverted index and the analysis pipeline.
- Internals β segments and merging, the term dictionary (FST), postings, and BM25 scoring, with worked numbers.
- Interview β Staff/Principal Q&A: how search really works and relevance tuning.
Apache Lucene β Part 3: System Design & Interview Mastery
maang.io System Design Series
What is this?
You now know Lucene from the inverted index down to the FST and the BM25 formula. This chapter is where that knowledge earns the offer. An interviewer doesn't want you to recite "Lucene uses immutable segments" β they want to watch you reach for search at the right moment, wire it correctly beside a source of truth, and defend the trade-offs when they push back on freshness, cost, or consistency.
Two things here: first, where Lucene shows up in real designs (almost always wearing its Elasticsearch/Solr clothing), then a mock interview β for each question, what they're really asking, a model answer, and the senior line that signals you've done this for real. We'll keep leaning on the back-of-the-book index whenever it makes an idea land.
The one-line idea: interviewers use search to test whether you can separate the search index from the system of record β feed a rebuildable inverted index alongside your database, accept its eventual-consistency and cost realities, and reason about relevance, freshness, and scale out loud.
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