0
0
HLDsystem_design~7 mins

Why database choice impacts architecture in HLD - Why This Architecture

Choose your learning style9 modes available
Problem Statement
Choosing the wrong database can cause system slowdowns, data loss, or inability to scale. For example, a database that cannot handle high write loads will bottleneck the entire application, causing poor user experience and failures under peak traffic.
Solution
Selecting a database that fits the data model, query patterns, and scale requirements ensures smooth operation. The right database supports efficient data storage, fast queries, and reliable transactions, which shapes the overall system design and performance.
Architecture
Application
Database
Query Patterns
──────────────┘
Data Model
─────────────────────────────────────┘

This diagram shows how the application interacts with the database, which depends on the data model and query patterns. The database choice affects storage and retrieval, influencing the entire architecture.

Trade-offs
✓ Pros
Optimizes performance by matching database strengths to workload types.
Improves scalability by choosing databases that handle expected data volume.
Enhances reliability with databases supporting required consistency and durability.
✗ Cons
Wrong choice can cause costly refactoring later.
Some databases have limited query flexibility or transaction support.
Complexity increases when mixing multiple database types.
Use when system requirements include specific data models (e.g., relational, document), query patterns, or scale beyond thousands of requests per second.
When the system is a simple prototype or proof of concept with minimal data and low traffic, complex database choice may be unnecessary.
Real World Examples
Netflix
Uses Cassandra for high write throughput and availability in user viewing history storage, enabling smooth streaming experiences.
Uber
Uses MySQL for transactional data requiring strong consistency, and Redis for fast caching to handle real-time ride matching.
Amazon
Uses DynamoDB for scalable key-value storage to support massive e-commerce traffic with low latency.
Alternatives
Polyglot Persistence
Uses multiple database types specialized for different parts of the system rather than a single database.
Use when: When different data types and workloads require optimized storage and querying beyond one database's capabilities.
In-memory Databases
Stores data primarily in RAM for ultra-fast access, differing from disk-based databases.
Use when: When extremely low latency is critical and data size fits in memory.
Summary
Database choice directly affects system performance, scalability, and reliability.
Matching database features to data and query patterns shapes the overall architecture.
Poor database selection can cause costly redesigns and system failures.