Bird
Raised Fist0
HLDsystem_design~10 mins

Search and metadata in HLD - Scalability & System Analysis

Choose your learning style9 modes available
Scalability Analysis - Search and metadata
Growth Table: Search and Metadata System
ScaleUsersSearch Queries/SecondMetadata SizeSystem Changes
Small10010 QPSFew MBsSingle server, simple DB, no caching
Medium10,0001,000 QPSGBsDB indexing, caching layer, load balancer
Large1,000,00050,000 QPSTBsDistributed search engine, sharded DB, CDN for metadata
Very Large100,000,0005,000,000 QPSPetabytesMulti-region clusters, advanced sharding, heavy caching, streaming updates
First Bottleneck

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.

Scaling Solutions
  • 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.
Back-of-Envelope Cost Analysis

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.
Interview Tip

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.

Self Check

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.

Key Result
The database query performance for metadata and search indexing is the first bottleneck as traffic grows; adding caching, read replicas, and distributed search engines are key to scaling effectively.