Inventory and stock: keep "in stock" true, built serverless with Nami

Real-world systems
Inventory and stock
Nami, cloud architect
Nami
Thank you

You built the stock service with me.

From a scan on the shelf to the word "In stock" on a screen. You learned:

  • Why stock is kept per item per store, with on-hand and held on the same row.
  • How a conditional update lets only one customer win the last carton.
  • How holds expire, and why a scheduled job beats TTL as a timer.
  • How a FIFO queue and a ledger keep scans in order and explainable.
  • How events, a zero-crossing index update, alerts and nightly counts keep everyone else true.
Next: rider dispatch

    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.

    1. Two people tap pay on the last packet of milk, at the same moment. Who gets it?
    2. That tiny label, In stock, is the most trusted word in the app. And the hardest to keep true.
    3. 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.
    4. Stay for the alarm that must never fire. Scroll.
    5. 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?
    6. 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.
    7. 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.
    8. 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.
    9. 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.
    10. 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.
    11. 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.
    12. 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.
    13. 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.
    14. 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.
    15. 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.
    16. The whole picture. That is one carton, shelf to screen. Trace a change, or open the full diagram.

    More stories on Real-world systems