-> Storage:
Suggest API
GET /suggest?q=
res {
query,
suggestions[]
}
Store user query for index building and trending updates
POST /query
req {
query,
timestamp,
geolocation
}
Acts as the entry point for all client requests.
Responsibilities:
Distributes traffic across multiple instances of all services to improve scalability and availability.
Typeahead service
Responsbility:
Query Processing service
Responsibility
Kafka
Flink streaming
Responsibility
Query Aggreation store
Responsibilities:
Index builder job
Responsiblities:
Inverted index
Responssibilties
Redis
we dont use relational DB for this, instead we use:
We will now deep dive into these topics:
-> The high level flwo is
User query -> kafka -> Flink streaming -> Query agg store -> index builder job -> inverted index
query: "apple"
it stores:
{
totalCount,
count_last_5min,
count_last_1hr,
trend_score, (uses count last 5min and last 1 hr)
geo_stats:
{
us_score,
canada_score,
uk_score,
}
last_seen_timestamp
}
-> how does it work
Each query is scored using:
score =
w1 * log(frequency)
w2 * trending_score
w3 * recency_decay
w4 * geo_relevance
w5 * personalization_score (optional)
-> how does it work
world → [world news, world cup, world map]
world cup ↑↑ (trend spike)
world → [world cup, world news, world map]
-> If redis misses:
Scaling strategies:
Conflict resolution: