Read this story as text
Inventory and stock: the story, written out
A tiny label says In stock. Nami, a cloud architect, builds the serverless AWS setup that keeps it true: DynamoDB conditional updates, SQS FIFO, EventBridge, OpenSearch and SNS.
- Two people tap pay on the last packet of milk, at the same moment. Who gets it?
- That tiny label, In stock, is the most trusted word in the app. And the hardest to keep true.
- Three promises to keep: Two people must never get the last packet of milk. A change on the shelf shows up in the app within seconds. A number that is wrong can be found, explained and fixed.
- Stay for the alarm that must never fire. Scroll.
- One number, many hands. One carton of milk. A picker scans it out, a truck scans forty in, a customer adds two. One number, three hands. What could go wrong?
- One row per item, per store. The truth lives in DynamoDB: one row per item, per store. Milk here is not milk there. Now watch two customers arrive together.
- Reserve, but only if there is enough. The trap: read two, write back minus two. Both customers read 'two', both win. So one conditional update: take two only if two are free. The database picks the winner.
- A hold that lets go. A hold that never ends empties shelves without a sale. So holds expire after ten minutes, and a job returns the stock every minute.
- Changes from the shelf, in order. Scans from the shelf repeat and arrive late. A FIFO queue per item keeps each item in order, while different items run in parallel.
- Never just overwrite. Every change also lands in a ledger: who, what, how many, why. Nobody edits it. When the app says three and the shelf says five, the ledger answers.
- Tell everyone else. When a stock row changes, its stream announces: milk, this store, now eleven. Search, feed and alerts just listen. But search has a problem.
- Search without a storm. Updating search on every change means a hundred thousand useless writes. So we update it only when the count crosses zero. In, or out.
- Say it before it runs out. An alert at zero is just a report. So below a limit, SNS tells buyers while there is still milk. One alert, not thirty.
- Trust, but count. Counts drift: theft, misplaced pallets. Every night we count a few shelves, and fix gaps with a new ledger line, never an edit.
- Watch for the impossible. The alarm I promised: stock below zero. Our conditional update forbids it, so if it fires, something broke. I want to know in minutes.
- The whole picture. That is one carton, shelf to screen. Trace a change, or open the full diagram.
More stories on Real-world systems