Bird
Raised Fist0
HLDsystem_design~12 mins

Why database choice impacts architecture in HLD - Architecture Impact

Choose your learning style10 modes available
System Overview - Why database choice impacts architecture

This system demonstrates how choosing different types of databases affects the overall architecture of an application. Key requirements include handling data storage efficiently, supporting scalability, and ensuring data consistency based on the database type.

Architecture Diagram
User
  |
  v
Load Balancer
  |
  v
API Gateway
  |
  +--------------------+--------------------+
  |                    |                    |
Relational DB Service  NoSQL DB Service    Cache
  |                    |                    |
Relational DB         NoSQL DB             Redis
Components
User
client
Initiates requests to the system
Load Balancer
load_balancer
Distributes incoming requests evenly to API Gateway instances
API Gateway
api_gateway
Routes requests to appropriate backend services based on database choice
Relational DB Service
service
Handles requests that require relational database operations
NoSQL DB Service
service
Handles requests that require NoSQL database operations
Cache
cache
Stores frequently accessed data to reduce database load
Relational DB
database
Stores structured data with strong consistency and supports complex queries
NoSQL DB
database
Stores flexible schema data optimized for scalability and high throughput
Redis
cache
In-memory cache for fast data retrieval
Request Flow - 16 Hops
User → Load Balancer
Load Balancer → API Gateway
API Gateway → Cache
Cache → API Gateway
API Gateway → Relational DB Service
Relational DB Service → Relational DB
Relational DB → Relational DB Service
Relational DB Service → Cache
Relational DB Service → API Gateway
API Gateway → NoSQL DB Service
NoSQL DB Service → NoSQL DB
NoSQL DB → NoSQL DB Service
NoSQL DB Service → Cache
NoSQL DB Service → API Gateway
API Gateway → Load Balancer
Load Balancer → User
Failure Scenario
Component Fails:Relational DB
Impact:Relational DB Service cannot retrieve or store data, causing failures for requests needing relational data. Cache may serve stale data but writes fail.
Mitigation:Use database replication and failover to standby relational DB instances. Cache serves read requests temporarily. API Gateway can route requests to NoSQL DB Service if applicable.
Architecture Quiz - 3 Questions
Test your understanding
Why does the API Gateway route requests differently based on database choice?
ABecause different databases require different query languages and data handling
BBecause the API Gateway stores all data itself
CBecause users connect directly to databases
DBecause caches replace databases entirely
Design Principle
Choosing a database type affects how the system routes requests, manages data consistency, and scales. Relational databases require structured queries and strong consistency, while NoSQL databases offer flexible schemas and scalability. Caches improve performance by reducing database load. The architecture must adapt to these differences to meet system requirements.

Practice

(1/5)
1. Which of the following is a primary reason why the choice of database impacts system architecture?
easy
A. Database choice only matters for small systems
B. All databases use the same query language
C. Databases do not affect system performance
D. Different databases handle data consistency and scaling differently

Solution

  1. Step 1: Understand database roles in architecture

    Databases store and manage data, affecting how data is accessed and maintained.
  2. Step 2: Recognize differences in consistency and scaling

    Relational and NoSQL databases differ in consistency guarantees and how they scale horizontally or vertically.
  3. Final Answer:

    Different databases handle data consistency and scaling differently -> Option D
  4. Quick Check:

    Database choice affects consistency and scaling [OK]
Hint: Focus on how data handling varies by database type [OK]
Common Mistakes:
  • Assuming all databases behave the same
  • Ignoring scaling differences
  • Thinking database choice doesn't affect performance
2. Which database type is best described by this syntax for creating a table: CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(100));?
easy
A. Document-based NoSQL database
B. Key-value store
C. Relational SQL database
D. Graph database

Solution

  1. Step 1: Identify the syntax style

    The CREATE TABLE statement with columns and types is standard SQL syntax.
  2. Step 2: Match syntax to database type

    Relational databases use SQL and tables with defined schemas.
  3. Final Answer:

    Relational SQL database -> Option C
  4. Quick Check:

    SQL table creation = Relational database [OK]
Hint: Look for SQL keywords like CREATE TABLE [OK]
Common Mistakes:
  • Confusing NoSQL with SQL syntax
  • Assuming all databases use SQL
  • Ignoring schema definitions
3. Consider a system using a NoSQL document database storing user profiles as JSON. Which architectural impact is most likely when scaling this system?
medium
A. Easier horizontal scaling with eventual consistency
B. Strong ACID transactions across multiple documents
C. Rigid schema enforcement for all data
D. Limited ability to shard data across servers

Solution

  1. Step 1: Understand NoSQL document database traits

    NoSQL document stores often allow flexible schemas and scale horizontally.
  2. Step 2: Identify scaling and consistency trade-offs

    They usually provide eventual consistency and support sharding for horizontal scaling.
  3. Final Answer:

    Easier horizontal scaling with eventual consistency -> Option A
  4. Quick Check:

    NoSQL scaling = horizontal + eventual consistency [OK]
Hint: NoSQL means flexible schema and horizontal scaling [OK]
Common Mistakes:
  • Expecting strong ACID transactions in NoSQL
  • Assuming rigid schemas
  • Thinking sharding is limited
4. A system architect chose a relational database but faces performance issues with high write loads. What is a likely architectural mistake?
medium
A. Using eventual consistency instead of strong consistency
B. Ignoring NoSQL options that scale writes better
C. Choosing a key-value store for complex joins
D. Not using SQL queries for data retrieval

Solution

  1. Step 1: Analyze the problem context

    Relational databases can struggle with very high write loads due to ACID constraints.
  2. Step 2: Identify architectural mistake

    Ignoring NoSQL databases that handle high write throughput with eventual consistency is a common error.
  3. Final Answer:

    Ignoring NoSQL options that scale writes better -> Option B
  4. Quick Check:

    High write load needs scalable DB choice [OK]
Hint: High writes? Consider NoSQL for better scaling [OK]
Common Mistakes:
  • Assuming relational DB always best
  • Confusing consistency models
  • Misusing key-value stores for complex queries
5. You are designing a global social media platform requiring fast reads, flexible user data, and eventual consistency. Which database choice best fits this architecture and why?
hard
A. NoSQL document database for flexible schema and horizontal scaling
B. Graph database for user relationships but no horizontal scaling
C. In-memory key-value store only for all data storage
D. Relational database for strong consistency and complex joins

Solution

  1. Step 1: Analyze requirements

    The system needs fast reads, flexible data, and can tolerate eventual consistency.
  2. Step 2: Match database features to needs

    NoSQL document databases provide flexible schemas, scale horizontally worldwide, and support eventual consistency.
  3. Step 3: Evaluate other options

    Relational DBs have strong consistency but less flexible scaling; in-memory stores lack persistence; graph DBs may not scale globally easily.
  4. Final Answer:

    NoSQL document database for flexible schema and horizontal scaling -> Option A
  5. Quick Check:

    Global scale + flexible data = NoSQL document DB [OK]
Hint: Flexible data + global scale? Pick NoSQL document DB [OK]
Common Mistakes:
  • Choosing relational DB despite scaling limits
  • Using in-memory store without persistence
  • Ignoring horizontal scaling needs
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard