Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

The Last Mango Problem: Race Conditions in a Real Marketplace

Description and use

GleanGrid resolved concurrent checkout races by using transactions with SELECT … FOR UPDATE, ordering locks, summing basket lines, enforcing coupon limits, and locking count queries for pickup slots.

Problem

Concurrent checkout requests can both read the same stock or coupon data before either writes, leading to over‑booking or duplicate coupon usage.

Outcome

Race conditions were eliminated by making all reads that influence decisions locking reads within a single transaction, ordering locks to prevent deadlocks, and enforcing constraints at the database level.

Workflow

  • Start transaction
  • Lock product rows with lockForUpdate
  • Sum duplicate lines per product
  • Check stock and decrement
  • Lock coupon row, assert usability, create redemption, increment used_count
  • Lock pickup slot row, count bookings with lockForUpdate, reject if full
  • Commit transaction

Evidence

Run that from two requests at once and both pass the if before either one saves.

Source

Lock the slot, count the bookings, reject if it's full.

Source

Make the count a locking read too:

Source

  • Record date: 2026-10-01T21:10:54.515Z