Why Can Two People Buy the Last Item at the Same Time?
Two customers click "Buy Now" on the last item in stock at almost the same moment — who gets it? Why transactions and row-level locking, not payment processing, are the hardest part of checkout.
- System Design Explained
- Concurrency
- Transactions
- Database Architecture
- Distributed Systems
(How Large E-commerce Systems Prevent Overselling)
Imagine there's only one laptop left in stock. Two customers click "Buy Now" at almost the exact same moment.
Both receive the request. Both see "1 item available." So... Who gets it?
If both orders succeed, you've just sold the same product twice. This is one of the hardest problems in large-scale systems.
Not because checking inventory is difficult. Because multiple users are trying to change the same data at the same time.

A simplified flow looks like this:
- 🛒 Customer A and Customer B both place an order within the same moment.
- Both requests reach the Order Service.
- The database processes the inventory update as an atomic transaction.
- The first successful transaction reserves the last item.
- The second transaction sees updated inventory and fails gracefully.
Notice what happened.
The application didn't solve the problem. The database guaranteed consistency.
This is why concepts like transactions, row-level locking, optimistic concurrency, and inventory reservation exist.
They're not just database features. They're what prevent real-world business failures.
One lesson that's changed how I think about system design: Reading data is easy. Changing shared data safely is where architecture becomes difficult.
The next time you buy the last item online, remember...
The hardest part wasn't processing your payment. It was making sure no one else bought that same item.
What's another real-world system where concurrency creates surprising challenges?
Keep reading
Why Doesn't Instagram Crash When Millions of People Open It at the Same Time?
It's not one incredibly powerful server — it's thousands of systems sharing the work. How load balancing, caching, and horizontal scaling keep Instagram responsive.
Why Your UI Sometimes Shows "Old" Data on Purpose
A brief flash of stale data after a refresh isn't always a bug — it's often eventual consistency at work. Why modern frontends favor a responsive UI with a background refresh over waiting for perfect freshness.
Why Can't You Just Add Another Database?
Reading data and writing data are two very different scaling problems. Why most large-scale systems separate read replicas from a single write primary instead of just adding another database.