Skip to content

Latest commit

 

History

History
9 lines (7 loc) · 736 Bytes

File metadata and controls

9 lines (7 loc) · 736 Bytes

This is a distributed locking system for an e-commerce order processing API using Redis to prevent race conditions when multiple requests try to update the same product’s stock simultaneously.

Flow:

Request arrives → OrderController.ProcessOrder() validates input Lock acquisition → RedisLockService.AcquireLockAsync() tries to set a Redis key with SETNX (set if not exists) with 10-second TTL If lock acquired → Fetch product from database, check stock, simulate processing (2s delay), decrement stock, save Lock release → Lua script atomically checks if the lock value matches before deleting (prevents releasing someone else’s lock) If lock fails → Throws exception (another process is already handling this product)