Indexing
Storage:
Only one main api
Search API
GET /serach?q={query text}&cursor={}
response:
{
results[] => arrray of document data : title, url, snippet,
nextCursor => next document id
}
For our system we have two seperate architect, one handling the search, the other handling crawl and indexing pages
API Gateway
Load Balancer
Query Service
Retrieval Service
Distributed Index - Shards
shard 1 - 0 - 10000 doc
shard 2 - 10001 - 20000 doc
etc
Ranking Service
Crawl/Indexing Architect
Web crawler:
Kafka
Indexing pipeline:
We dont have traditional relational database for this system, rather we have:
Object storage like S3 -> Document storage
KV store like Cassandra -> Document crawl metdata
doc_id {
url,
content_hash,
langauge
last_crawled_at,
next_crawl_time,
crawl_status,
metadata
}
Distributed inverted index
"restuarnats" : [doc1, doc2]
"toronto" [doc2, doc3, doc4]
Now we will deep dive into the following topics:
How would querying work when using multiple shards
Replication
Index segments
New documents
│
▼
Build Segment
│
▼
Publish Segment
Shard 1 -> Segment A
Segment B
Segment C
Periodically
A + B + C -> merged to become segment D
If use segments then what about updated document?
BM25/Lexical Scoring
Shards -> Find matching doc -> Apply BM25/Lexical score -> return top K documents
Additional ranking:
ML Ranking
Failure Handling
Why multi-stage ranking i.e, cheap first, expensive later?