Course contentsShow
← Security
Lesson 904 of 3,05219. Web Security - Business Logic VulnerabilitiesFree lesson

Concurrency Issues in Inventory and Resource Allocation

Understand race conditions in stock management, ticket sales, and limited resource allocation systems.

Concurrency Issues in Inventory and Resource Allocation

What you'll learn: How race conditions create overselling and double-allocation problems in systems managing limited resources like inventory, tickets, or booking slots.

The Core Problem

When multiple users try to purchase the last concert ticket or book the last hotel room simultaneously, your application might sell the same item twice. This happens because of race conditions during inventory checks and allocation.

Think of it like two cashiers at a store. Both check the shelf and see "1 item left." Both tell their customers "yes, we have it!" and ring up the sale. But there was only one physical item—someone's getting disappointed.

Real-World Vulnerable Flow

User A                    Database              User B
  |                          |                    |
  |--Check stock (1 left)--->|                    |
  |                          |<---Check stock-----|
  |<----"Available"-----------                    |
  |                          -------"Available"-->|
  |--Purchase & set stock=0->|                    |
  |                          |<---Purchase--------|
  |                          | (stock now -1!)    |

Both users passed the availability check before either completed their purchase. The system oversold by one unit.

Common Vulnerable Scenarios

  • Stock management: Multiple buyers purchasing the last few items
  • Ticket sales: Concert or event tickets during high-demand releases
  • Reservation systems: Hotel rooms, rental cars, or appointment slots
  • Limited promotions: First 100 customers get a discount code
  • Resource pooling: Database connections, API rate limits, license seats

Why This Happens

Applications typically use a check-then-act pattern without atomic operations:

  1. Read current inventory count
  2. Verify count > 0
  3. Create order
  4. Decrement inventory

Between steps 1 and 4, another transaction can slip in.

Key Takeaway: Race conditions in inventory systems occur when concurrent requests check availability simultaneously before any updates complete, leading to overselling, double-booking, and resource exhaustion—all exploitable as business logic vulnerabilities.