Design an Inventory Reservation System

System Design
Medium
Amazon
72.4K views

Design a service to temporarily reserve limited inventory (e.g., seats, products) during a high-traffic checkout process. Focus on time-based expiration and rollback.

Why Interviewers Ask This

Interviewers at Amazon ask this to evaluate your ability to design distributed systems that handle high concurrency and data consistency. They specifically want to see how you manage race conditions when multiple users attempt to reserve the same limited inventory simultaneously, and how you implement time-based expiration without blocking the checkout flow.

How to Answer This Question

1. Clarify requirements: Define scale (requests per second), latency targets, and specific failure scenarios like network partitions or payment timeouts. 2. Model the core entity: Define the Inventory Item with fields for total stock, reserved count, and a unique reservation ID with an expiration timestamp. 3. Design the API: Create endpoints for 'reserve' and 'release', ensuring idempotency to prevent double-charging if retries occur. 4. Address concurrency: Propose using Redis with atomic operations (like INCR/DECR) or database optimistic locking to handle simultaneous requests safely. 5. Implement expiration: Suggest using Redis keys with TTL or a background cron job to automatically release expired reservations back to available stock. 6. Handle rollbacks: Detail how to trigger a rollback if the user abandons the cart after the timeout window, ensuring stock is never permanently lost due to ghost reservations.

Key Points to Cover

  • Demonstrating understanding of race conditions in high-concurrency environments
  • Proposing atomic operations (like Lua scripts or optimistic locking) to ensure data integrity
  • Leveraging Redis TTLs for automatic, efficient expiration of temporary reservations
  • Designing a clear rollback strategy to restore inventory upon timeout or failure
  • Balancing performance with durability through async writes and caching layers

Sample Answer

To design this system, I would first clarify that we need to support flash sales where thousands of users hit the checkout button simultaneously. The core challenge is preventing overselling while minimizing latency. I p…

Common Mistakes to Avoid

  • Ignoring race conditions by suggesting simple database updates without locks or atomic transactions
  • Failing to define a specific expiration mechanism, leading to permanent inventory loss
  • Over-engineering the solution by using complex databases instead of appropriate in-memory caches for temporary states
  • Not addressing what happens when the payment gateway times out or the user navigates away unexpectedly

Sound confident on this question in 5 minutes

Answer once and get a 30-second AI critique of your structure, content, and delivery. First attempt is free — no signup needed.

Try it free

Related Interview Questions

Browse all 190 System Design questionsBrowse all 184 Amazon questions