System Design – Google Search with certain restrictions
Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2022-03-11
Problem Statement
Design a simplified version of Google Search. The system should allow users to enter queries and return ranked results from a massive dataset of web pages. However, certain restrictions are applied to narrow the scope and make the problem more tractable in an interview setting.
Functional Requirements
1.Crawling (Restricted)
•System crawls and indexes only a limited set of websites (e.g., 1M pages instead of the entire internet).
•Support scheduled crawling for freshness.
2.Indexing
•Build an inverted index for fast keyword lookups.
•Store metadata: page rank, last updated time, domain authority (restricted ranking factors).
3.Search Query Handling
•Parse user queries into tokens.
•Perform lookup in inverted index.
•Rank results using a restricted ranking model (e.g., TF-IDF or BM25, not full-scale PageRank).
4.Result Display
•Return Top-K results (e.g., top 10).
•Show snippets (restricted: no dynamic previews, just page title + description).
5.Admin Features
•Support re-indexing triggers.
•Monitor search query traffic.
Non-Functional Requirements
•Scalability: Handle millions of search queries per day, but restricted compared to real Google scale.
•Low Latency: Return results in <200ms for queries.
•Freshness: Crawling updates restricted to every 24 hours.
•Storage Efficiency: Optimize index size (compression, stopword removal).
•High Availability: Fault-tolerant search service.
Restrictions to Consider
•Dataset restricted (e.g., only 1M–10M web pages).
•Ranking simplified to TF-IDF/BM25, no full-scale ML models.
•Crawl frequency limited (e.g., daily instead of continuous).
•Advanced features like personalization, knowledge graph, ads, autocomplete → not included.
Design Considerations
•Crawling: Distributed crawlers → URL frontier + politeness policy.
•Indexing:
•Inverted index stored in distributed key-value store (e.g., Elasticsearch, Lucene).
•Precompute term frequency & IDF.
•Query Processing:
•Tokenizer + Normalizer (lowercase, stemming, stopword removal).
•Fetch document IDs from inverted index.
•Rank & return top K results.
•Caching: Popular queries cached in Redis.
•Sharding: Shard index by terms or documents.
•High Availability: Replication for index servers.