Live demo D1 (atomic) Pages Functions In the Frontier case file →

The Hoarder

On a limited drop, bots pile in and oversell the inventory, leaving real customers with cancelled orders. A single atomic write in Cloudflare D1 guards the count, so it can never go below zero.

Try it

Limited drop: 10 in stock.

Buy one at a time, or send a bot stampede of 15 simultaneous buys. The count never goes below zero, and the extra buys come back sold out. No overselling.

10 in stock

Real Cloudflare D1: UPDATE stock SET qty = qty - 1 WHERE qty > 0 is one atomic statement, so concurrent buyers can never race it below zero.