Skip to main content
Primitives/Primitive #13
PRIMITIVE #13Core Distributed Systems Component

Trie & Inverted Index

AWS Production Mapping:OpenSearch

1. What It Is & Why It Exists

Relational databases index scalar values with B-Trees, which support exact match and prefix queries (WHERE name LIKE 'app%') in O(logN)O(\log N) time. However, modern search architectures require:

  1. Ultra-Low Latency Autocomplete (<10 ms< 10\text{ ms} at 100k+ QPS100\text{k+ QPS}): Finding top-K suggestions matching a typed prefix regardless of total dictionary size.
  2. Arbitrary Substring & Multi-Term Search (LIKE '%system%design%'): Querying documents containing multiple keywords in any order across billions of web pages. Standard B-Trees cannot perform substring searches without full table scans.

The First-Principles Solution: Specialized Information Retrieval Structures

  • (): A tree data structure where keys are decomposed along characters. Search time is strictly O(L)O(L), where LL is the length of the query prefix, completely decoupled from total dictionary size NN.
  • : An associative data structure that maps every unique dictionary term (word) to a sorted list of integer document identifiers (Posting List), enabling set intersections and full-text relevance ranking in sub-millisecond time.
Interactive Architecture Diagram
Synthesizing vector architecture diagram...

2. Mathematical Foundations & Algorithmic Mechanics

1. The Okapi BM25 Ranking Formula

Modern search engines (, , Lucene) rank matched documents using the Okapi BM25 probabilistic relevance score:

Score(D,Q)=i=1nIDF(qi)f(qi,D)(k1+1)f(qi,D)+k1(1b+bDavgdl)\text{Score}(D, Q) = \sum_{i=1}^{n} \text{IDF}(q_i) \cdot \frac{f(q_i, D) \cdot (k_1 + 1)}{f(q_i, D) + k_1 \cdot \left(1 - b + b \cdot \frac{|D|}{\text{avgdl}}\right)}

Where:

  • IDF(qi)=ln(Nn(qi)+0.5n(qi)+0.5+1)\text{IDF}(q_i) = \ln\left( \frac{N - n(q_i) + 0.5}{n(q_i) + 0.5} + 1 \right): Inverse Document Frequency penalizing ubiquitous terms (e.g. "the", "is").
  • f(qi,D)f(q_i, D): Term frequency of keyword qiq_i in document DD.
  • D/avgdl|D| / \text{avgdl}: Document length normalized against average corpus length.
  • k11.2,b0.75k_1 \approx 1.2, b \approx 0.75: Standard saturation tuning parameters.

2. Posting List Intersection Time Complexity

Given two sorted posting lists of lengths MM and NN (MNM \le N):

  • Linear Two-Pointer Intersection: O(M+N)O(M + N) comparisons.
  • Skip-List Binary Search Jumping: O(Mlog(N/M))O(M \log(N/M)) comparisons using forward skip pointers every N\sqrt{N} elements.
  • Roaring Bitmaps: Hardware SIMD bitwise AND operations executing at >10 GB/sec> 10\text{ GB/sec}.

Part 2: Production Deep-Dive Locked1 Coin = 24 Hours

Unlock Complete Architecture & Production Runbooks

Your Balance:40 Coins

You have explored the free architectural preview (~41%). Spend 1 Coin to unlock the remaining 5 production deep-dive sections for a full 24 hours.

Sections Included in This 24-Hour Pass:
3. Real-World Engine Comparison Matrix
4. Critical Edge Cases & Distributed Failure Modes
5. Production Pitfalls & Anti-Patterns (The "Gotchas")
6. AWS Cloud Service Implementation & Production Patterns
7. Production Sizing Formulas & Operational Runbook
Keeps page unlocked for exactly 24 hoursSpend coins to fund LLM & compute infrastructure