Contents
Constraints
- 1B documents, 1M new per day
- 2k QPS
- p99 300 ms
- queries mix tickers, entities and natural language
What to cover
Sketch your own design first. A complete answer has these parts; the notes say what each should settle.
- RequirementsBuild search over news stories and company filings for professional users, including autocomplete; freshness matters within seconds of a story breaking.
- Estimates1B documents, 1M new per day; 2k QPS; p99 300 ms; queries mix tickers, entities and natural language.
- API
- Data model
- ArchitectureQuery understanding (entity and ticker recognition, spelling).; Hybrid retrieval (BM25 inverted index + dense embeddings with ANN).; Learning-to-rank (LambdaMART or a cross-encoder for the top 100) with recency and authority features.; Real-time indexing pipeline; typeahead with a trie or prefix index ranked by popularity and personalisation.; Click logging with position-bias handling; relevance judgements by experts.
- Deep dives
- Trade-offsfreshness vs relevance; dense vs sparse retrieval cost; cross-encoder latency; personalisation vs auditability for professional users.
- EvaluationOffline: NDCG@10 on expert-judged sets, recall@100 of retrieval, freshness lag.; Online: interleaving, time to first useful click, query reformulation rate, zero-result rate.
Reference design
One way to answer it, part by part. Open a part once you have your own version of it.
Requirements
Functional: search across news stories and company filings with filters (date, source, document type, ticker, region) and sort by relevance or time; typeahead that suggests tickers, companies, people, topics and past queries; new stories searchable within seconds of publication; highlighted snippets.
Users: professionals (traders, analysts, journalists) who know what they want, value precision and recency, and need predictable, auditable results.
Non-functional: search p99 ≤ 300 ms at ~2k QPS; typeahead p99 ≤ 50 ms per keystroke; indexing lag p99 of a few seconds for breaking news; entitlements per source (licensed newswires).
Query mix: tickers and symbols (“VOD LN”, “$AAPL”), entities (“Bank of England”), and natural language (“why did gilt yields jump today”).
Assumptions to confirm: ~1B documents with ~1M new per day; English first; filings up to hundreds of pages; a small team of expert judges is available for relevance labels.
Estimates
Stack · 6 layersp99 300 ms latency budget
Ticker/entity recognition, spelling correction, intent and filters.
BM25 (hot + cold) and dense ANN run together.
Merge ~200 candidates and extract features.
Ranks ~200 candidates with text, entity-match, recency, authority, source and click features.
Reranks the top 20.
Snippets and entitlement checks, plus overhead and tail headroom.
- Corpus: 1B documents; news averages ~600 words, filings are split into passages. Raw text ≈ 1B × ~5 KB ≈ 5 TB; inverted index ≈ 2 TB, sharded (~100 shards × 3 replicas).
- Dense vectors: 1B vectors (one per story or filing passage) × 768 dims × 1 byte (int8) ≈ 770 GB, or ~64 GB with product quantisation to 64 bytes — PQ plus re-scoring of the shortlist keeps ANN in memory.
- Ingest: 1M docs/day ≈ 12/s average, bursts of hundreds per second at market open and earnings; embedding a story takes ~10–20 ms on a GPU, so a few GPUs keep up with seconds of lag.
- Query load: 2k QPS search; typeahead ≈ 5 keystrokes per query → ~10k QPS suggestions.
- Reranking: assuming ~2k–5k query–document pairs/s per GPU, a cross-encoder on the top 100 at 2k QPS = 200k pairs/s ≈ 40–100 GPUs; on the top 20 after LambdaMART = 40k pairs/s ≈ 8–20 GPUs. That cost difference shapes the cascade.
- Latency budget (p99 300 ms): query understanding 20 ms, sparse and dense retrieval in parallel 60 ms, merge and feature extraction 30 ms, LambdaMART on ~200 20 ms, cross-encoder on top 20 60 ms, snippets and entitlement checks 30 ms, overhead and tail headroom ~80 ms.
API
GET /v1/search?q=…&filters=type:news,source:…,from:…&tickers=…&sort=relevance|time&page=1
→ {request_id, query_interpretation: {entities: [{text, entity_id, ticker}], intent},
results: [{doc_id, title, snippet_html, source, doc_type, published_at, tickers[],
entitled: true}], total_estimate}
GET /v1/suggest?prefix=vodaf&session_id=… (p99 ≤ 50 ms)
→ [{text: "Vodafone Group PLC", type: "company", entity_id, ticker: "VOD LN"},
{text: "vodafone three merger", type: "query"}]
POST /v1/search/events {request_id, events: [{type: "impression"|"click"|"dwell"|"reformulate",
doc_id, position, ts}]}
Entitlement filtering happens in the index query, so unlicensed sources never appear even as counts. sort=time is deterministic, which professional users rely on. Both endpoints return a request_id so clicks join to the exact ranking for training and interleaving analysis.
Data model
- Document: doc_id, type (news | filing | transcript), source, published_at, updated_at, version chain (wire stories are updated repeatedly), language, title, body, passages, entities and tickers (linked to the entity master), authority score, entitlement tags.
- EntityMaster: entity_id, names and aliases, tickers per exchange, ISIN, sector, relationships (subsidiaries); drives query understanding and typeahead.
- Indices: hot tier (last ~7 days, near-real-time refresh) and cold tier (history, rebuilt in batches); BM25 fields with boosts; ANN index on passage embeddings.
- QueryLog / ClickLog: request_id, user, query, interpretation, results with positions, clicks, dwell, reformulations.
- Judgements: (query, doc, grade 0–4, judge, guideline version) from expert assessors.
- SuggestionStore: prefix → ranked suggestions from entities, popular queries (recency-weighted) and the user’s history; trending boosts.
Architecture
Flow · 4 stepsQuery path for search ranking
- Understand the query Query understanding recognises tickers and entities against the EntityMaster, corrects spelling, and sets intent and filters.
- Retrieve in parallel BM25 and dense ANN run in parallel over the hot and cold tiers and return hits to the merge stage.
- Rank and rerank Merge produces about 200 candidates; LambdaMART scores them and passes the top 20 to the cross-encoder.
- Return results Snippets and entitlement checks are added, and the ranked results with request_id are returned.
Data
| Step | Title | What happens |
|---|---|---|
| 1 | Understand the query | Query understanding recognises tickers and entities against the EntityMaster, corrects spelling, and sets intent and filters. |
| 2 | Retrieve in parallel | BM25 and dense ANN run in parallel over the hot and cold tiers and return hits to the merge stage. |
| 3 | Rank and rerank | Merge produces about 200 candidates; LambdaMART scores them and passes the top 20 to the cross-encoder. |
| 4 | Return results | Snippets and entitlement checks are added, and the ranked results with request_id are returned. |
Source: This page's text
| Box | Group | Detail |
|---|---|---|
| Query | Input | tickers, entities, natural language |
| Query understanding | Input | ticker/entity recognition, spelling, intent |
| EntityMaster | Input | names, tickers, ISIN, sector |
| BM25 index | Retrieval | hot + cold, exact on tickers and names |
| Dense ANN index | Retrieval | passage embeddings, PQ re-scoring |
| Merge | Retrieval | ~200 candidates |
| LambdaMART | Ranking | text, entity-match, recency, authority, click |
| Cross-encoder | Ranking | top 20 rerank |
| Snippets | Output | highlights and entitlement checks |
| Results | Output | request_id, ranked results |
Source: This page's text
Flow · 4 stepsFreshness path from feed to searchable story
- Ingest Wires and filings flow through Kafka into enrichment, which dedups, builds version chains, links entities and computes embeddings.
- Hot index Enriched documents land in the hot index with a one-second refresh, so a story is searchable within a few seconds of arriving.
- Cold merge A nightly merge moves documents from the hot tier into the cold index, which holds history and is rebuilt in batches.
- Query A query is understood, then BM25 and dense ANN retrieval run in parallel over hot and cold tiers, followed by LambdaMART and a cross-encoder on the top 20.
Data
| Step | Title | What happens |
|---|---|---|
| 1 | Ingest | Wires and filings flow through Kafka into enrichment, which dedups, builds version chains, links entities and computes embeddings. |
| 2 | Hot index | Enriched documents land in the hot index with a one-second refresh, so a story is searchable within a few seconds of arriving. |
| 3 | Cold merge | A nightly merge moves documents from the hot tier into the cold index, which holds history and is rebuilt in batches. |
| 4 | Query | A query is understood, then BM25 and dense ANN retrieval run in parallel over hot and cold tiers, followed by LambdaMART and a cross-encoder on the top 20. |
Source: This page's text
| Box | Group | Detail |
|---|---|---|
| Wires / filings feeds | Ingest | 1M new docs per day |
| Kafka | Ingest | |
| Enrichment | Ingest | dedup, version chains, entity linking |
| Hot index | Index | NRT, ~1 s refresh |
| Cold index | Index | history, rebuilt in batches |
| Query | Query | |
| Query understanding | Query | ticker/entity recognition, spelling, intent |
| Hybrid retrieval | Query | BM25 + dense ANN in parallel |
| Ranking | Query | LambdaMART, then cross-encoder on top 20 |
| Results | Query | snippets, entitlement checks |
Source: This page's text
Flow · 3 stepsHow typeahead serves suggestions in 50 ms
- Type a prefix The user types a prefix; GET /v1/suggest receives it with session_id.
- Look up candidates The in-memory prefix index returns precomputed candidates per prefix.
- Rank and return A light model ranks candidates on popularity, recency and personalisation, preferring entities for short prefixes, and suggestions return within 50 ms.
Data
| Step | Title | What happens |
|---|---|---|
| 1 | Type a prefix | The user types a prefix; GET /v1/suggest receives it with session_id. |
| 2 | Look up candidates | The in-memory prefix index returns precomputed candidates per prefix. |
| 3 | Rank and return | A light model ranks candidates on popularity, recency and personalisation, preferring entities for short prefixes, and suggestions return within 50 ms. |
Source: This page's text
| Box | Group | Detail |
|---|---|---|
| Prefix typed | Input | e.g. prefix=vodaf |
| GET /v1/suggest | Compute | p99 ≤ 50 ms |
| Prefix index | Memory | in-memory FST/trie per region |
| EntityMaster | Memory | entities, tickers, aliases |
| Popular queries & history | Memory | recency-weighted, personalised |
| Light ranker | Compute | popularity, recency, personalisation |
| Suggestions | Input | tickers, companies, queries |
Source: This page's text
Wires / filings feeds ─► Kafka ─► Enrichment: dedup and version chains, entity
linking (tickers, companies), language, embeddings ─► Hot index (NRT, ~1 s
refresh) ─► nightly merge ─► Cold index
Query ─► Query understanding: ticker/entity recognition against EntityMaster,
spelling correction, intent (navigational vs news vs research), filters
─► Retrieval in parallel: BM25 (hot + cold) and dense ANN ─► merge (~200)
─► LambdaMART with text, entity-match, recency, authority, source and
click features ─► top 20 ─► cross-encoder rerank ─► snippets ─► results
Typeahead: in-memory prefix index (FST/trie) per region, entries from
EntityMaster + popular queries + user history, ranked by popularity,
recency and personalisation; trending terms injected within minutes
Logs ─► click models (position-bias correction) ─► training data
Expert judging tool ─► judged sets ─► offline evaluation and trainingDeep dives
Freshness within seconds. Two-tier index: new documents go to a small hot index with a one-second refresh; embeddings are computed in the streaming pipeline before indexing; a story is searchable within a few seconds of arriving. Ranking learns query-dependent recency: for “VOD” or “gilt yields” the newest relevant story usually wins; for “IFRS 17 transition” relevance dominates. A freshness-intent feature (share of recent clicks for this query in the last hour) lets the ranker switch.
Position bias in clicks. Users click what is on top, so raw clicks reward the incumbent ranker. Estimate propensities with small randomised swaps of adjacent results, train with inverse-propensity weighting, and use interleaving for online comparisons. Expert judgements remain the ground truth for offline gates.
Typeahead. Within 50 ms there is no time for heavy models: precompute candidates per prefix, rank with a light model on popularity, recency and the user’s watchlist, and prefer entities (jumping straight to a company page) for short prefixes.
Trade-offs
- Freshness vs relevance: always boosting recency buries the authoritative analysis; ignoring it shows stale news on a breaking story. Learn the trade-off per query and offer an explicit time sort.
- Dense vs sparse retrieval cost: BM25 is cheap, exact on tickers and names, and easy to explain; dense retrieval helps natural-language questions but costs memory and GPU time. Hybrid retrieval with dense only on passages and the hot tier, or only when query understanding detects natural language, controls cost.
- Cross-encoder latency: best precision, but 200k pairs/s is expensive; restrict it to the top 20 after LambdaMART, and skip it for navigational ticker queries.
- Personalisation vs auditability for professional users: people want to reproduce a search and trust that colleagues see the same results; keep core ranking non-personalised, personalise typeahead and soft boosts (watchlist tickers) visibly, and log everything for audit.
Evaluation
- Offline: NDCG@10 on expert-judged query sets stratified by query type (ticker, entity, natural language) and recency need; recall@100 of the retrieval stage (judged or pooled); freshness lag (publish time to searchable) p50/p99; typeahead mean reciprocal rank and keystrokes saved.
- Online: team-draft interleaving for ranking changes (sensitive with less traffic than A/B); time to first useful click (click followed by long dwell); query reformulation rate; zero-result rate; abandonment.
- Monitoring: indexing lag per source, query latency p99 per stage, entitlement-filter errors (must be zero), click-through by position, spikes in zero-result queries (often a new entity missing from EntityMaster).
What a strong design shows
- Has query understanding that recognises tickers and entities, not just text matching.
- Uses hybrid retrieval and a cost-aware ranking cascade (LambdaMART, then a cross-encoder on a short list).
- Achieves seconds-level freshness with a hot/cold index and learns query-dependent recency.
- Corrects click logs for position bias and relies on expert judgements and interleaving for evaluation.
- Treats typeahead as its own low-latency system and respects professional users’ need for predictable, auditable results.