Kaus · a technical manuscript in motion

Building a search engine from first principles.

Every structure in this book is implemented here, in TypeScript, running in your browser — an inverted index over 28 real documents, BM25 with the arithmetic shown, Levenshtein automata, minimized automata, FSTs with outputs, BKD trees, a byte-level segment format with real checksums, and a cluster you can break.

Nothing on this site is a recorded screenshot. Every number you are about to see was computed when this page loaded, by the same engine the chapters describe.

28 documents462 terms indexed43 chapters13 parts0 UI dependencies
In the can
doc-1Kubernetes Deployment Guide· published$149.99doc-2Docker Deployment Patterns· published$89.50doc-3Kubernetes Service Networking· published$129.00doc-4Kubernetes Kubernetes Kubernetes· draft$10.00doc-5Redis Caching Strategies· published$79.99doc-6Kafka Partitions and Ordering· published$199.00doc-7Kubernets Cluster Setup· draft$39.00doc-8Postgres Index Internals· published$159.00doc-9Lucene Segment Merging· published$0.00doc-10Observability for Search Clusters· published$249.00doc-11Terraform Module Layout· published$119.00doc-12Kubernetes Deployment Rollback· published$99.00doc-13Elasticsearch Query DSL Notes· published$0.00doc-14BM25 Tuning in Practice· published$0.00doc-15Docker Compose for Local Clusters· archived$29.00doc-16Kubernetes Operators Explained· published$179.00doc-17Redis Cluster Resharding· published$139.00doc-18Kafka Consumer Rebalance Storms· published$209.00doc-19Search Relevance Testing· published$0.00doc-20Cloud Cost of Search Clusters· published$299.00doc-21Kubernetes Storage Classes· published$109.00doc-22Deployment Deployment Deployment Deployment· draft$5.00doc-23Trie and FST Term Dictionaries· published$0.00doc-24BKD Trees for Numeric Ranges· published$0.00doc-25Kubernetes Deployment Service Mesh· published$189.00doc-26Nginx Reverse Proxy Tuning· archived$59.00doc-27Kubernetes Autoscaling Deep Dive· published$169.00doc-28Immutable Infrastructure Notes· published$0.00
Director's note
Build the simple version → discover the bottleneck → replace one component → understand why the advanced structure exists.
scene 01 · the two jobs

Build fast structures. Then use them.

A search engine builds structures that make retrieval fast, then uses those structures to find and rank documents. Click any stage to jump to its chapter — hover to see what it does.

now showing · four animated concept breakdowns

How a search engine actually works under the hood

Live animated step-throughs of core algorithms and structures. Watch how raw unstructured text is parsed, how postings lists intersect, how automata prune tries, and how range queries work.

take 01 · analysis pipelinech 03
analysis chain · stage 1/4
01 · Raw Input

Source document text arrives with mixed case, punctuation, and delimiters

KubernetesDEPLOYMENTS&podsrunningonredis-cluster_v2!
input: "Kubernetes DEPLOYMENTS & pods ru..."7 tokens

Text to Terms: Step-by-step tokenization, delimiter expansion, case folding, and stemming before tokens reach inverted index postings.

take 02 · postings intersection & bm25ch 04 · ch 08
postings intersection · AND query"kubernetes" AND "deployment"

Iterators step in docId lockstep. Both posting lists must contain the doc for an AND match.

kubernetes:
doc:0doc:1doc:2doc:4doc:5
deployment:
doc:0doc:1doc:2doc:3doc:4
doc 0 · Kubernetes Deployment Guide
BM25: 3.103

DocId Lockstep & Scoring: Multi-term AND queries advance iterators across sorted posting lists and calculate live BM25 saturation scores.

take 03 · levenshtein trie pruningch 14 · ch 15
automaton trie walk · fuzzy(~2)fuzzy("kubernets")

Shared trie prefixes allow the automaton to eliminate thousands of non-matching terms in one step.

CURRENT TRIE NODE:d=0 (exact)
/k
→
ku... · ka... (kafka)
Action: Step 1: 'k' matches query root. Edit distance remains 0.

Fuzzy Search Without Scanning: The Levenshtein DFA walks the trie and prunes entire subtrees the moment edit distance exceeds the max threshold (d > 2).

take 04 · point index & bkd rangech 20 · ch 22
point index · numeric bkdprice: [100 TO 200]

Numeric ranges don't scan text. Sorted point leaves isolate matching documents in O(log N) time.

$0.00$100.00$200.00$300.00$500.00
Matched: doc-1, doc-8, doc-16, doc-224 documents

Fast Numeric Retrieval: Numbers and dates use 1D/2D spatial trees instead of text terms, isolating target doc ranges in O(log N) time.

scene 02 · the spine

There is not one search data structure

Different questions need different structures. This is the spine of the whole book.

FST is not postings. BKD is not a text dictionary. BM25 does not find documents; it scores candidates.

scene 03 · the manuscript

Thirteen parts, forty-three chapters

II

The First Search Engine

3 chapters

A hash map, a set of document ids, and suddenly you no longer scan every document.

VI

Term Dictionaries

4 chapters

Prefix sharing, then suffix sharing, then outputs. Each step is a measurable size reduction.

VII

Numeric & Spatial Search

3 chapters

Sorting solves one dimension. Two dimensions need you to partition space itself.

XI

Cluster & Operations

3 chapters

Refresh, flush and commit are three different promises. Failure is part of the architecture.

XII

Production Engineering

3 chapters

Optimise in order, size from the workload, and measure the percentiles users actually feel.

XIII

The Kaus Project

3 chapters

The build order, the testing strategy, and the map back to Lucene and OpenSearch.

final scene · the build order

Fifteen stages, one replacement each

Do not skip an intermediate structure merely because you already know the name of the final one — experience the problem first.

StageBuildReplace later withChapter
1documents + tokenizerreal analyzer3
2term → set(docID)compressed postings25
3positionsposition codecs5
4AND/OR/phraseiterator execution6
5toy scoreBM258
6sorted termstrie16
7trieminimized automaton17
8automaton + outputsFST18
9term blocksBlockTree-style dictionary19
10sorted numeric valuesBKD22
11simple filesversioned segment codec24
12file readsmmap reader26
13single nodeshards31
14shardsreplicas / recovery36
15basic metricsproduction observability40

Kaus — building a search engine from first principles. The goal is not to reproduce Lucene line for line; it is to make Lucene and OpenSearch understandable.

Reference documentation: lucene.apache.org · docs.opensearch.org