Bird
0
0
LLDsystem_design~12 mins

Concurrency considerations in LLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - Concurrency considerations

This system manages multiple tasks running at the same time without interfering with each other. It ensures data stays correct and the system stays fast even when many users or processes work together.

Architecture Diagram
User
  |
  v
Load Balancer
  |
  v
API Gateway
  |
  v
+-------------------+       +----------------+
|   Worker Service   |<----->|  Message Queue  |
+-------------------+       +----------------+
        |  ^                        |
        v  |                        v
+-------------------+       +----------------+
|  Shared Database   |<----->| Distributed Lock|
+-------------------+       +----------------+
        ^
        |
      Cache
Components
User
client
Initiates requests to the system
Load Balancer
load_balancer
Distributes incoming requests evenly to API Gateway instances
API Gateway
api_gateway
Routes requests to appropriate worker services and handles authentication
Worker Service
service
Processes tasks concurrently, manages business logic
Message Queue
queue
Queues tasks for asynchronous processing to avoid blocking
Shared Database
database
Stores persistent data accessed by multiple workers
Distributed Lock
lock_service
Coordinates access to shared resources to prevent conflicts
Cache
cache
Stores frequently accessed data to reduce database load
Request Flow - 13 Hops
UserLoad Balancer
Load BalancerAPI Gateway
API GatewayWorker Service
Worker ServiceDistributed Lock
Distributed LockWorker Service
Worker ServiceCache
CacheWorker Service
Worker ServiceShared Database
Worker ServiceMessage Queue
Message QueueWorker Service
Worker ServiceAPI Gateway
API GatewayLoad Balancer
Load BalancerUser
Failure Scenario
Component Fails:Distributed Lock
Impact:Multiple workers may access shared resources simultaneously causing data corruption or race conditions.
Mitigation:Use a highly available distributed lock service with failover and retries. Implement optimistic concurrency controls in the database as backup.
Architecture Quiz - 3 Questions
Test your understanding
Which component ensures that multiple workers do not update the same data at the same time?
AMessage Queue
BCache
CDistributed Lock
DLoad Balancer
Design Principle
This architecture uses distributed locks and message queues to safely manage concurrent access and asynchronous processing, ensuring data consistency and system responsiveness under multiple simultaneous tasks.