0
0
HLDsystem_design~12 mins

Write-through and write-back caching in HLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - Write-through and write-back caching

This system demonstrates two common caching strategies: write-through and write-back caching. It shows how data is written and read between users, cache, and database to improve performance and data consistency.

Architecture Diagram
User
  |
  v
Load Balancer
  |
  v
API Gateway
  |
  v
+-------------------+
|   Cache Layer      |
|  (Write-through or |
|   Write-back)      |
+-------------------+
  |
  v
Database
Components
User
client
Sends read and write requests to the system
Load Balancer
load_balancer
Distributes incoming requests evenly to API Gateway instances
API Gateway
api_gateway
Receives requests, routes them to cache or database, and handles caching logic
Cache Layer
cache
Stores frequently accessed data to reduce database load; supports write-through or write-back caching
Database
database
Persistent storage for all data
Request Flow - 8 Hops
UserLoad Balancer
Load BalancerAPI Gateway
API GatewayCache Layer
Cache LayerDatabase
DatabaseCache Layer
Cache LayerAPI Gateway
API GatewayLoad Balancer
Load BalancerUser
Failure Scenario
Component Fails:Cache Layer
Impact:Cache misses increase; system falls back to database for reads and writes, increasing latency and load on database
Mitigation:API Gateway bypasses cache and directly queries database; cache rebuilds after recovery
Architecture Quiz - 3 Questions
Test your understanding
In write-through caching, when is data written to the database?
AOnly when cache is full
BImmediately when data is written to cache
CAfter a delay or periodically
DNever, only cache stores data
Design Principle
This architecture demonstrates how caching strategies affect data consistency and system performance. Write-through caching ensures data is always consistent by writing to cache and database simultaneously, while write-back caching improves write performance by delaying database writes but risks data loss on failure. The system uses a load balancer and API gateway to manage traffic and caching logic, ensuring scalability and reliability.