LearnSystem design

Search ranking for financial news and documents (with typeahead)

Build search over news stories and company filings for professional users, including autocomplete; freshness matters within seconds of a story breaking.

ML engineering8 parts

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.

  1. RequirementsBuild search over news stories and company filings for professional users, including autocomplete; freshness matters within seconds of a story breaking.
  2. Estimates1B documents, 1M new per day; 2k QPS; p99 300 ms; queries mix tickers, entities and natural language.
  3. API
  4. Data model
  5. 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.
  6. Deep dives
  7. Trade-offsfreshness vs relevance; dense vs sparse retrieval cost; cross-encoder latency; personalisation vs auditability for professional users.
  8. 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

  1. Ticker/entity recognition, spelling correction, intent and filters.

  2. BM25 (hot + cold) and dense ANN run together.

  3. Merge ~200 candidates and extract features.

  4. Ranks ~200 candidates with text, entity-match, recency, authority, source and click features.

  5. Reranks the top 20.

  6. Snippets and entitlement checks, plus overhead and tail headroom.

The budget sums to 300 ms: 20 + 60 + 30 + 20 + 60 + 30 + ~80 ms.Diagram drafted by a local AI model (Inkling 2 Mini) from this page's text and drawn from data. Checked by an independent reviewer.
  • 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

Query path for search rankingThe query enters query understanding, which recognises tickers and entities against the EntityMaster and applies spelling correction, intent and filters. Retrieval runs BM25 and dense ANN in parallel, merges about 200 candidates, then LambdaMART and a cross-encoder on the top 20 produce the final results with snippets.Querytickers, entities, natural languageQuery understandingticker/entity recognition, spelling,intentEntityMasternames, tickers,ISIN, sectorBM25 indexhot + cold,exact ontickers andnamesDense ANNindexpassageembeddings,PQ re-scoringMerge~200 candidatesLambdaMARTtext, entity-match, recency,authority, clickCross-encodertop 20 rerankSnippetshighlights and entitlement checksResultsrequest_id, ranked resultslookupqueryqueryhitshits~200top 20top 201234InputRetrievalRankingOutput
  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.

A query is understood, retrieved in parallel, merged and reranked before snippets and entitlement checks return results.Diagram drafted by a local AI model (Inkling 2 Mini) from this page's text and drawn from data. Checked by an independent reviewer.
Data
Steps
StepTitleWhat happens
1Understand the queryQuery understanding recognises tickers and entities against the EntityMaster, corrects spelling, and sets intent and filters.
2Retrieve in parallelBM25 and dense ANN run in parallel over the hot and cold tiers and return hits to the merge stage.
3Rank and rerankMerge produces about 200 candidates; LambdaMART scores them and passes the top 20 to the cross-encoder.
4Return resultsSnippets and entitlement checks are added, and the ranked results with request_id are returned.

Source: This page's text

Boxes
BoxGroupDetail
QueryInputtickers, entities, natural language
Query understandingInputticker/entity recognition, spelling, intent
EntityMasterInputnames, tickers, ISIN, sector
BM25 indexRetrievalhot + cold, exact on tickers and names
Dense ANN indexRetrievalpassage embeddings, PQ re-scoring
MergeRetrieval~200 candidates
LambdaMARTRankingtext, entity-match, recency, authority, click
Cross-encoderRankingtop 20 rerank
SnippetsOutputhighlights and entitlement checks
ResultsOutputrequest_id, ranked results

Source: This page's text

Flow · 4 stepsFreshness path from feed to searchable story

Freshness path from feed to searchable storyA left-to-right flow shows wires and filings entering Kafka, passing through enrichment (dedup, version chains, entity linking, embeddings), and landing in a hot index with a one-second refresh. A nightly merge moves them to the cold index. A query path runs from query understanding through hybrid retrieval over hot and cold tiers, then ranking and results.Wires / filings feeds1M new docs per dayQueryKafkaQuery understandingticker/entity recognition,spelling, intentEnrichmentdedup, version chains, entity linkingHot indexNRT, ~1 s refreshCold indexhistory, rebuilt in batchesHybrid retrievalBM25 + dense ANN in parallelRankingLambdaMART, then cross-encoderon top 20Resultssnippets, entitlement checksindexnightly mergehot tiercold tier~2001234IngestIndexQuery
  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.

New stories reach the hot index within seconds of publication, then merge into the cold index nightly, while queries read both tiers.Diagram drafted by a local AI model (Inkling 2 Mini) from this page's text and drawn from data. Checked by an independent reviewer.
Data
Steps
StepTitleWhat happens
1IngestWires and filings flow through Kafka into enrichment, which dedups, builds version chains, links entities and computes embeddings.
2Hot indexEnriched documents land in the hot index with a one-second refresh, so a story is searchable within a few seconds of arriving.
3Cold mergeA nightly merge moves documents from the hot tier into the cold index, which holds history and is rebuilt in batches.
4QueryA 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

Boxes
BoxGroupDetail
Wires / filings feedsIngest1M new docs per day
KafkaIngest
EnrichmentIngestdedup, version chains, entity linking
Hot indexIndexNRT, ~1 s refresh
Cold indexIndexhistory, rebuilt in batches
QueryQuery
Query understandingQueryticker/entity recognition, spelling, intent
Hybrid retrievalQueryBM25 + dense ANN in parallel
RankingQueryLambdaMART, then cross-encoder on top 20
ResultsQuerysnippets, entitlement checks

Source: This page's text

Flow · 3 stepsHow typeahead serves suggestions in 50 ms

How typeahead serves suggestions in 50 msA user types a prefix, which hits GET /v1/suggest. The in-memory FST/trie prefix index returns precomputed candidates drawn from EntityMaster, popular queries and user history. A light ranker scores them on popularity, recency and personalisation, preferring entities for short prefixes, and the suggestions return within 50 ms.Prefix typede.g. prefix=vodafGET/v1/suggestp99 ≤ 50 msEntityMasterentities,tickers, aliasesPopularqueries &historyrecency-weighted,personalisedPrefix indexin-memory FST/trie per regionLight rankerpopularity, recency, personalisationSuggestionstickers, companies, queriesprefix lookupentriesentriescandidates123InputComputeMemory
  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.

A typed prefix is looked up in a per-region in-memory prefix index and ranked by a light model, returning suggestions within 50 ms.Diagram drafted by a local AI model (Inkling 2 Mini) from this page's text and drawn from data. Checked by an independent reviewer.
Data
Steps
StepTitleWhat happens
1Type a prefixThe user types a prefix; GET /v1/suggest receives it with session_id.
2Look up candidatesThe in-memory prefix index returns precomputed candidates per prefix.
3Rank and returnA 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

Boxes
BoxGroupDetail
Prefix typedInpute.g. prefix=vodaf
GET /v1/suggestComputep99 ≤ 50 ms
Prefix indexMemoryin-memory FST/trie per region
EntityMasterMemoryentities, tickers, aliases
Popular queries & historyMemoryrecency-weighted, personalised
Light rankerComputepopularity, recency, personalisation
SuggestionsInputtickers, 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 training

Deep 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.

Study material compiled with AI: drafted by a local model (Inkling 2 Mini) from public sources, then checked against those sources by independent AI reviewers (Claude) in November 2026. Not reviewed line by line by a person.