Back to Discover
Curiosity

Who Gets the Last Seat? Race Conditions Explained

Concurrent purchase requests are serialized by locks or ordering rules, so the winner is determined by which request first acquires exclusive access—not by who clicked first in human time.

Before you enter

A complete interactive classroom, not just a preview.

Start when you are ready to enter this Stage's 9 scenes and explore, respond, and learn as you go.

9
Scenes
18 min
Estimated
Content language: en-US
Start this Stage
Sign-in may be required to play
What happens inside
  1. 01The Simultaneous Click Problemslide
    Question

    Open with two devices showing the same item in stock, both about to tap 'buy'. Pose the driving question visually.

    • Two users, one item, one millisecond
    • Who gets it? Who decides?
    • Human intuition vs. machine reality
  2. 02Commit to Your Guessquiz
    Prediction

    Ask the learner to predict the rule the system uses before any explanation is shown.

    • Reveal an intuition worth testing
  3. 03Race the Two Requestsinteractive
    Evidence

    A simulation where two 'buy' requests hit an inventory counter at the same moment. The learner runs the race and watches requests interleave.

    • Both requests read stock = 1
    • Without coordination, both write stock = 0
    • Overselling happens every time
  4. 04The Visible Result: Oversellingslide
    Evidence

    Show the timeline of reads and writes overlapping, producing two confirmed sales for one item.

    • Read–modify–write is not atomic
    • Two sellers, one seat
    • Why 'fast' isn't enough
  5. 05Add a Lockinteractive
    Explanation

    Re-run the same race but with a mutex/lock around the inventory check. The learner sees requests serialize and only one wins.

    • Lock blocks the second request until the first finishes
    • Order is now deterministic
    • Loser sees 'sold out'
  6. 06Why the Lock Beats Click Timeslide
    Explanation

    Explain that the system never compares human timestamps; it arbitrates at the moment of the write. Show the lock as a single doorway.

    • No clock compares the two clicks
    • The lock is the arbiter
    • First to acquire the lock wins; order is arbitrary but deterministic
  7. 07When the Lock Breaksslide
    Boundary

    Show what happens when the database and the app server disagree—a brief boundary case to prevent overgeneralization.

    • Locks live in one place; distributed systems need more
    • Optimistic vs. pessimistic locking
    • Atomic compare-and-set as an alternative
  8. 08Apply It: Hotel Bookinginteractive
    Transfer

    Transfer the idea: two guests try to book the last hotel room. The learner toggles locking on/off and predicts the outcome.

    • Same race, different domain
    • Lock on → one guest confirmed, one waitlisted
    • No lock → both confirmed, hotel overbooked
  9. 09The Answerslide
    Resolution

    Directly answer the driving question and close the loop on the opening tension.

    • The system doesn't know who clicked first
    • A lock serializes the requests
    • First to acquire the lock wins; the other sees 'sold out'
    • Fairness is a separate engineering choice, not a default
Discussion

Discussion threads for a Stage aren't available yet.

Where this leads
Explore more

More in Engineering & Systems

See all