0
0
LLDsystem_design~12 mins

Balance calculation algorithm in LLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - Balance calculation algorithm

This system calculates user account balances by processing transactions efficiently and accurately. It must handle concurrent updates, ensure data consistency, and provide quick balance queries.

Architecture Diagram
User
  |
  v
Load Balancer
  |
  v
API Gateway
  |
  v
Balance Calculation Service <-> Cache
  |
  v
Database
Components
User
client
Initiates balance queries and transaction requests
Load Balancer
load_balancer
Distributes incoming requests evenly to API Gateway instances
API Gateway
api_gateway
Routes requests to the Balance Calculation Service and handles authentication
Balance Calculation Service
service
Processes transactions, updates balances, and serves balance queries
Cache
cache
Stores recent balance data for fast read access
Database
database
Stores all transaction records and persistent user balance data
Request Flow - 10 Hops
UserLoad Balancer
Load BalancerAPI Gateway
API GatewayBalance Calculation Service
Balance Calculation ServiceCache
CacheBalance Calculation Service
Balance Calculation ServiceDatabase
DatabaseBalance Calculation Service
Balance Calculation ServiceCache
Balance Calculation ServiceAPI Gateway
API GatewayUser
Failure Scenario
Component Fails:Database
Impact:New transactions cannot be recorded; balance updates fail. Cached balances can still be read but may become stale.
Mitigation:Use database replication for failover; rely on cache for read-only balance queries until DB recovers.
Architecture Quiz - 3 Questions
Test your understanding
Which component handles user authentication before processing balance requests?
AAPI Gateway
BLoad Balancer
CCache
DBalance Calculation Service
Design Principle
This architecture uses caching to speed up balance queries and a load balancer to distribute requests evenly. It separates concerns by using an API Gateway for authentication and routing, ensuring scalability and reliability.