0
0
HLDsystem_design~12 mins

Cache-aside pattern in HLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - Cache-aside pattern

The Cache-aside pattern helps improve data read performance by using a cache to store frequently accessed data. When an application needs data, it first checks the cache. If the data is missing, it loads from the database and then stores it in the cache for future requests.

This pattern reduces database load and speeds up response times while keeping data consistent.

Architecture Diagram
User
  |
  v
Load Balancer
  |
  v
Application Service
  |
  +-----> Cache
  |         |
  |         v
  |      Database
  |
  v
Response
Components
User
client
Initiates requests to the system
Load Balancer
load_balancer
Distributes incoming requests evenly to application instances
Application Service
service
Handles business logic, checks cache, queries database if needed
Cache
cache
Stores frequently accessed data for fast retrieval
Database
database
Persistent storage of all data
Request Flow - 9 Hops
UserLoad Balancer
Load BalancerApplication Service
Application ServiceCache
CacheApplication Service
Application ServiceDatabase
DatabaseApplication Service
Application ServiceCache
Application ServiceLoad Balancer
Load BalancerUser
Failure Scenario
Component Fails:Cache
Impact:Cache misses increase, causing all requests to hit the database, increasing latency and load
Mitigation:System continues to function by querying the database directly; cache can be restored or replaced without data loss
Architecture Quiz - 3 Questions
Test your understanding
In the Cache-aside pattern, what happens when the requested data is not found in the cache?
AThe cache automatically fetches data from the database
BThe application returns an error to the user
CThe application queries the database and then updates the cache with the data
DThe load balancer retries the request
Design Principle
The Cache-aside pattern improves read performance by letting the application control cache population. It ensures data freshness by loading data from the database only on cache misses, reducing database load and speeding up responses.