Design a Top-K search words service
LinkedInSoftware Engineer · Technical ScreenLast updated
The question evaluates understanding of scalable, low-latency analytics and search-event systems, including high-throughput event ingestion, Top-K aggregation across all-time and sliding windows, normalization/deduplication trade-offs, and multi-region consistency considerations.
Scenario
Design a service that tracks user search queries and returns the Top-K most searched words/queries.
Requirements
Functional
- API to record a search query event (e.g., user searches "iphone 16").
- API to fetch Top-K queries.
- Support a time window variant:
- (a) all-time Top-K
- (b) Top-K over the last N minutes/hours (trending)
Non-functional
- High write QPS (search events), low latency reads for Top-K.
- Scalable horizontally.
- Reasonable correctness (define whether exact or approximate is acceptable).
Clarifications to address
- What is a “word” vs “query” (full string)?
- Case-folding, normalization, stop words, punctuation.
- Deduping (e.g., multiple searches by same user) or count every event.
- Multi-region and eventual consistency expectations.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.