| Scale | Users | Search Queries/Second | Metadata Size | System Changes |
|---|---|---|---|---|
| Small | 100 | 10 QPS | Few MBs | Single server, simple DB, no caching |
| Medium | 10,000 | 1,000 QPS | GBs | DB indexing, caching layer, load balancer |
| Large | 1,000,000 | 50,000 QPS | TBs | Distributed search engine, sharded DB, CDN for metadata |
| Very Large | 100,000,000 | 5,000,000 QPS | Petabytes | Multi-region clusters, advanced sharding, heavy caching, streaming updates |
Search and metadata in HLD - Scalability & System Analysis
Start learning this pattern below
Jump into concepts and practice - no test required
At small to medium scale, the database query performance for metadata and search indexing breaks first. This is because search queries require fast lookups and metadata updates increase load. The DB struggles with high QPS and large index sizes.
- Horizontal scaling: Add more search nodes and metadata DB replicas to distribute load.
- Caching: Use in-memory caches (e.g., Redis) for frequent metadata and search results.
- Sharding: Partition metadata and search indexes by user or content to reduce single node load.
- Distributed search engines: Use systems like Elasticsearch or Solr that scale horizontally.
- CDN: Cache static metadata and search results closer to users to reduce backend load.
- Load balancing: Distribute incoming search requests evenly across servers.
Assuming 1M users generate 50K QPS search queries:
- Each query ~1 KB data -> 50 MB/s bandwidth needed.
- Metadata storage ~1 TB with indexes.
- DB handles ~10K QPS per instance -> need ~5 DB replicas.
- Search nodes handle ~5K QPS each -> need ~10 search nodes.
- Cache memory ~100 GB to hold hot metadata and results.
Start by clarifying scale and data types. Discuss bottlenecks in DB and search indexing. Propose caching and horizontal scaling. Mention sharding and distributed search engines. Always justify why each solution fits the bottleneck.
Your database handles 1000 QPS. Traffic grows 10x to 10,000 QPS. What do you do first?
Answer: Add read replicas and implement caching to reduce DB load before scaling vertically or sharding.
Practice
Solution
Step 1: Understand metadata role
Metadata provides information about data, like tags or descriptions.Step 2: Connect metadata to search
Search engines use metadata to quickly find relevant data without scanning everything.Final Answer:
To describe data and make search faster -> Option CQuick Check:
Metadata = Data description for search [OK]
- Confusing metadata with user data
- Thinking metadata stores passwords
- Assuming metadata manages network
Solution
Step 1: Identify metadata examples
Metadata describes content, like titles, tags, or dates.Step 2: Check each option
title = 'Introduction to Cats'shows a title, which is metadata describing content. Others are config or sensitive data.Final Answer:
title = 'Introduction to Cats'-> Option AQuick Check:
Title is metadata for search [OK]
- Choosing config values as metadata
- Confusing sensitive data with metadata
- Ignoring descriptive fields
"apple" if metadata contains {"title": "apple pie", "tags": ["fruit", "dessert"]}?Solution
Step 1: Understand search with metadata
Search looks for matches in metadata fields like title and tags.Step 2: Check if "apple" matches metadata
"apple" matches the title "apple pie", so the item is returned.Final Answer:
Returns item with title "apple pie" -> Option BQuick Check:
Search matches title containing "apple" [OK]
- Ignoring title field in search
- Returning unrelated tags only
- Assuming no results if exact match missing
Solution
Step 1: Identify cause of search failure
If metadata is stale, search index won't reflect latest data.Step 2: Evaluate options
Only Metadata is not updated after data changes relates to metadata and search correctness; others are unrelated.Final Answer:
Metadata is not updated after data changes -> Option DQuick Check:
Stale metadata breaks search results [OK]
- Blaming UI or network for search logic errors
- Ignoring metadata update process
- Confusing unrelated system issues
Solution
Step 1: Understand scalability needs
Millions of users require fast, distributed search to avoid bottlenecks.Step 2: Evaluate options for scalability
Use distributed indexing with metadata shards and update indexes asynchronously uses distributed indexing and async updates, which scales well and keeps search fast.Final Answer:
Use distributed indexing with metadata shards and update indexes asynchronously -> Option AQuick Check:
Distributed indexing + async updates = scalable search [OK]
- Scanning all data centrally causes slow search
- Relying on local device metadata limits scale
- Disabling metadata removes search efficiency
