| Users / Data Size | Key-Value Store | Document Store | Column Store | Graph Database |
|---|---|---|---|---|
| 100 users | Single server, in-memory caching | Single server, simple queries | Single server, small tables | Single server, small graph |
| 10K users | Sharding by key, cache layer | Replica sets, indexing | Partitioning columns, compression | Indexing nodes, caching paths |
| 1M users | Multiple shards, distributed cache | Horizontal scaling, query optimization | Distributed storage, column pruning | Graph partitioning, query parallelism |
| 100M users | Global sharding, multi-region clusters | Multi-region replication, CDN for static data | Massive parallel processing, tiered storage | Advanced graph partitioning, caching hot subgraphs |
NoSQL database types (document, key-value, column, graph) in HLD - Scalability & System Analysis
At small scale, the database server CPU and memory limits are the first bottleneck for all NoSQL types because they handle all queries and data in one place.
As users grow to 10K-1M, network bandwidth and disk I/O become bottlenecks due to increased data movement and query complexity.
For graph databases, complex traversals cause CPU bottlenecks earlier than others because graph queries are compute-intensive.
- Key-Value Stores: Use sharding by key, add distributed caching (e.g., Redis), and replicate data for availability.
- Document Stores: Implement replica sets for fault tolerance, add indexes on query fields, and shard collections by document attributes.
- Column Stores: Partition data by columns, compress data to save space, and use distributed storage systems.
- Graph Databases: Partition graphs into subgraphs, cache frequently accessed paths, and parallelize graph queries.
- Across all types, use load balancers to distribute traffic and CDNs to serve static content.
- At 1M users, assuming 1 request per second per user, total requests = 1 million QPS.
- Single server handles ~5000 QPS, so need ~200 servers for database layer.
- Storage: If average document/record size is 1 KB, 1M users with 100 records each = 100 GB data.
- Network bandwidth: 1M QPS * 1 KB = ~1 GB/s (8 Gbps), requiring multiple network interfaces and data centers.
Start by explaining the NoSQL type and its data model. Then discuss expected load and data size. Identify the first bottleneck logically (usually database CPU or disk). Propose scaling solutions matching the bottleneck. Mention trade-offs like consistency vs availability. Use real numbers to show understanding.
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 load on the primary database. If write load grows, shard data horizontally to distribute writes.
Practice
Solution
Step 1: Understand document database structure
Document databases store data in JSON-like documents that can have nested fields and arrays.Step 2: Compare with other NoSQL types
Key-value stores use simple key and value pairs, column stores organize data by columns, and graph databases focus on relationships.Final Answer:
Document database -> Option AQuick Check:
Nested JSON-like data = Document database [OK]
- Confusing key-value stores with document stores
- Thinking column stores store JSON documents
- Mixing graph databases with document databases
Solution
Step 1: Define key-value store
Key-value stores save data as pairs: a unique key and its associated value, like a dictionary.Step 2: Eliminate other options
Graphs use nodes and edges, column stores use tables with columns, and document stores use nested JSON.Final Answer:
Stores data as simple pairs of keys and values -> Option CQuick Check:
Key-value = key and value pairs [OK]
- Confusing graph databases with key-value stores
- Thinking key-value stores use tables
- Mixing document stores with key-value stores
Solution
Step 1: Understand graph database query output
Graph queries return nodes and edges; friends of 'Alice' are nodes connected by 'friend' edges.Step 2: Compare with other data formats
Key-value pairs, tables, and JSON documents are typical of other NoSQL types, not graph databases.Final Answer:
A set of nodes connected to 'Alice' by edges labeled 'friend' -> Option BQuick Check:
Graph query = nodes and edges [OK]
- Expecting JSON documents from graph queries
- Thinking graph data is tabular
- Confusing key-value pairs with graph edges
Solution
Step 1: Understand column store query requirements
Column stores require specifying columns in queries; missing columns causes errors.Step 2: Analyze other options
Nested JSON is for document stores, key-value pairs are for key-value stores, and edge traversal is for graph databases.Final Answer:
Used SQL SELECT syntax without specifying columns -> Option AQuick Check:
Column store queries need columns specified [OK]
- Using document store syntax on column stores
- Trying graph traversal in column stores
- Confusing key-value pairs with columns
Solution
Step 1: Identify the data need for mutual friends
Finding mutual friends requires exploring relationships between users efficiently.Step 2: Match data need to NoSQL type
Graph databases specialize in storing and querying relationships like friendships quickly.Step 3: Evaluate other options
Document stores handle nested data but not relationship queries efficiently; key-value stores are simple but not optimized for relationships; column stores focus on columnar data.Final Answer:
Graph database, because it efficiently handles relationships -> Option DQuick Check:
Relationship queries = Graph database [OK]
- Choosing document DB for relationship queries
- Assuming key-value stores handle complex queries
- Confusing column stores with relationship handling
Ready to prove it?
Pass the test and this pattern moves unknown
