Overselling

Overselling happens when a system accepts reservations or orders for more units than actually exist in inventory. In this course, concurrent requests can cause overselling when they read the same available stock and decrement it without a database-enforced condition, so guarded updates prevent the stock quantity from becoming negative.

Minimal example

sql
UPDATE stock
SET on_hand = on_hand - 1
WHERE item_id = 42
  AND on_hand >= 1;

Learn this concept

Lesson 8.1 · Optimistic locking for stock

Used in exercises

Exercise 8.2 · Stock reservation service
Prerequisite conceptsOptimistic lockingTransaction