0
0
HLDsystem_design~12 mins

When to use SQL vs NoSQL in HLD - Architecture Patterns Compared

Choose your learning style9 modes available
System Overview - When to use SQL vs NoSQL

This system helps decide when to use SQL or NoSQL databases based on application needs. It guides users by analyzing data structure, scalability, consistency, and query complexity requirements.

Architecture Diagram
User
  |
  v
Load Balancer
  |
  v
API Gateway
  |
  +---------------------+
  |                     |
SQL Service         NoSQL Service
  |                     |
SQL Database       NoSQL Database
  |                     |
Cache               Cache
Components
User
client
Sends requests to decide database type
Load Balancer
load_balancer
Distributes incoming requests evenly
API Gateway
api_gateway
Routes requests to SQL or NoSQL service based on criteria
SQL Service
service
Handles requests needing structured, relational data
NoSQL Service
service
Handles requests needing flexible, scalable data storage
SQL Database
database
Stores structured data with strong consistency
NoSQL Database
database
Stores unstructured or semi-structured data with flexible schema
Cache
cache
Speeds up frequent data reads for both databases
Request Flow - 17 Hops
UserLoad Balancer
Load BalancerAPI Gateway
API GatewaySQL Service or NoSQL Service
SQL ServiceCache
CacheSQL Service
SQL ServiceSQL Database
SQL DatabaseSQL Service
SQL ServiceCache
SQL ServiceAPI Gateway
NoSQL ServiceCache
CacheNoSQL Service
NoSQL ServiceNoSQL Database
NoSQL DatabaseNoSQL Service
NoSQL ServiceCache
NoSQL ServiceAPI Gateway
API GatewayLoad Balancer
Load BalancerUser
Failure Scenario
Component Fails:SQL Database
Impact:SQL Service cannot retrieve or store structured data; cache may serve stale reads
Mitigation:Use database replication and failover; cache serves read requests temporarily; writes are queued or rejected until recovery
Architecture Quiz - 3 Questions
Test your understanding
Which component decides whether to use SQL or NoSQL service?
AAPI Gateway
BLoad Balancer
CCache
DUser
Design Principle
This architecture shows how to route requests to SQL or NoSQL databases based on data needs. It uses caching to improve performance and includes failover strategies for database failures, demonstrating scalable and reliable design.