0
0
HLDsystem_design~12 mins

Database replication (master-slave) in HLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - Database replication (master-slave)

This system uses a master-slave database replication setup to improve data availability and read scalability. The master database handles all write operations, while one or more slave databases replicate data from the master and serve read requests.

Key requirements include data consistency from master to slaves, load distribution for reads, and failover handling if the master fails.

Architecture Diagram
User
  |
  v
Load Balancer
  |
  v
API Gateway
  |
  +-------------------+
  |                   |
Master DB <---------> Slave DB(s)
  |                   |
  +-------------------+
Components
User
client
Initiates requests to the system
Load Balancer
load_balancer
Distributes incoming requests to API Gateway instances
API Gateway
api_gateway
Routes requests to appropriate services and manages traffic
Master DB
database_master
Handles all write operations and replicates data to slaves
Slave DB(s)
database_slave
Replicates data from master and handles read requests
Request Flow - 8 Hops
UserLoad Balancer
Load BalancerAPI Gateway
API GatewayMaster DB
Master DBSlave DB(s)
API GatewaySlave DB(s)
Slave DB(s)API Gateway
API GatewayLoad Balancer
Load BalancerUser
Failure Scenario
Component Fails:Master DB
Impact:Write operations fail; slaves continue serving stale read data
Mitigation:Promote a slave to master using failover process; update API Gateway routing
Architecture Quiz - 3 Questions
Test your understanding
Which component handles all write operations in this system?
ALoad Balancer
BMaster DB
CSlave DB
DAPI Gateway
Design Principle
This architecture separates write and read workloads by using a master database for writes and slave databases for reads. It improves read scalability and availability while maintaining data consistency through asynchronous replication.