0
0
HLDsystem_design~25 mins

Why database choice impacts architecture in HLD - Design It to Understand It

Choose your learning style9 modes available
Design: Database Impact on System Architecture
In scope: database types and their architectural impact, data flow changes, scaling considerations. Out of scope: detailed database internals or vendor-specific features.
Functional Requirements
FR1: Explain how different database types affect system design decisions
FR2: Show how database choice influences scalability, latency, and data consistency
FR3: Demonstrate impact on data modeling and query patterns
FR4: Highlight effects on deployment and maintenance
Non-Functional Requirements
NFR1: Focus on common database types: relational, document, key-value, graph
NFR2: Consider typical scale: up to 100K concurrent users
NFR3: Latency target: p99 API response under 200ms
NFR4: Availability target: 99.9% uptime
Think Before You Design
Questions to Ask
❓ Question 1
❓ Question 2
❓ Question 3
❓ Question 4
❓ Question 5
Key Components
Database type (SQL, NoSQL variants)
Caching layers
Data access APIs
Replication and sharding mechanisms
Backup and recovery
Design Patterns
CQRS (Command Query Responsibility Segregation)
Event sourcing
Cache aside pattern
Sharding and partitioning
Polyglot persistence
Reference Architecture
Client
  |
  v
API Layer
  |
  v
+---------------------+
|  Database Layer      |
|  +----------------+ |
|  | Relational DB  | |
|  | Document DB    | |
|  | Key-Value DB   | |
|  | Graph DB       | |
|  +----------------+ |
+---------------------+
  |
  v
Cache Layer (optional)
Components
API Layer
REST/gRPC
Handles client requests and routes to appropriate database or cache
Relational Database
PostgreSQL/MySQL
Structured data with strong consistency and complex joins
Document Database
MongoDB/Couchbase
Flexible schema for semi-structured data, fast reads/writes
Key-Value Store
Redis/DynamoDB
Ultra-fast lookups for simple key-based data
Graph Database
Neo4j/JanusGraph
Efficient handling of complex relationships and traversals
Cache Layer
Redis/Memcached
Reduce database load and improve read latency
Request Flow
1. Client sends request to API Layer
2. API Layer determines data type and query complexity
3. For simple key lookups, API checks Cache Layer first
4. If cache miss, API queries appropriate database type
5. Database returns data to API Layer
6. API Layer returns response to client
7. Writes go directly to database with optional cache invalidation
Database Schema
Entities depend on database type: - Relational DB: Tables with normalized relations (1:N, N:N) - Document DB: Collections with nested documents - Key-Value DB: Simple key and value pairs - Graph DB: Nodes and edges representing entities and relationships Relationships and data models must align with chosen database capabilities
Scaling Discussion
Bottlenecks
Relational DB can become slow with complex joins at scale
Document DB may face consistency challenges with distributed writes
Key-Value stores limited by memory size and network latency
Graph DBs can struggle with very large or deeply connected data
Cache invalidation complexity increases with write volume
Solutions
Use read replicas and sharding for relational DB scaling
Implement eventual consistency and conflict resolution for document DB
Scale key-value stores horizontally and optimize network
Partition graph data and limit traversal depth
Use cache aside pattern and TTLs to manage cache freshness
Interview Tips
Time: Spend 10 minutes understanding requirements and clarifying data needs, 20 minutes discussing database types and architectural impact, 10 minutes on scaling and trade-offs, 5 minutes summarizing.
Explain how data shape and access patterns influence database choice
Discuss consistency vs availability trade-offs
Highlight how database choice affects latency and scalability
Mention caching and replication strategies
Show awareness of polyglot persistence for complex systems