Checkout, behind the Pay button: build it serverless with Nami

Real-world systems
Checkout, behind the Pay button
Nami, cloud architect
Nami
Thank you

You built the checkout with me.

From a tap on a phone to a push notification. You learned:

  • How serverless microservices split an order into small jobs, each with its own function and table.
  • Why a workflow engine, not one big function, runs the steps and undoes them when one fails.
  • How idempotency keys and conditional writes stop double charges and double sales.
  • How events, queues and dead-letter queues keep the slow parts from blocking the order.
  • How to watch it all with one trace id.
Previous: search

    Read this story as text

    Checkout, behind the Pay button: the story, written out

    You tap Pay and a second later it says Order placed. Nami, a cloud architect, builds the serverless AWS setup behind that tap one piece at a time: API Gateway, Lambda, DynamoDB, Step Functions, EventBridge, SQS and SNS.

    1. You tap Pay. What if the card is charged, but the order is lost? Watch how that never happens.
    2. A lot can go wrong in one second. That is what makes it the best service to build.
    3. Three promises are made in there: You won't be charged twice. You won't pay for items that are out of stock. We won't lose your order.
    4. We go serverless, small microservices. Watch what happens when a step fails half way. Scroll.
    5. Someone taps Pay. One tap, four truths at once: right price, milk on the shelf, money on the card, reachable address. Any can change mid tap. Who checks?
    6. A name, an edge and a firewall. Same front door as search, plus AWS WAF first, because payments attract abuse. Then the real gate.
    7. One door, checked at the door. API Gateway checks your sign-in token before any code runs, and limits how fast you can call. No server behind it. Now, the order.
    8. A small service that owns one job. One Lambda, one DynamoDB table. An idle night costs almost nothing. It writes the order as pending, with a key, so a double tap is one order.
    9. Many steps, one workflow. An order is a chain: reserve, charge, confirm. One crash in one function leaves a mess. Step Functions remembers where each order is. Step one: the milk.
    10. Hold the milk. Inventory holds one packet with a single conditional write: two people never win the last one. Ten minutes, then it releases. Now, money.
    11. Charge the card. The payment function calls the gateway with a key on every charge, so a retry never charges twice. But banks are slow.
    12. The answer comes later. 'Paid' arrives seconds later by webhook. The workflow pauses for free, and wakes on a token. But what if the card is declined?
    13. When a step fails. Declined after we held the milk? Every step has an undo, and the workflow runs them backwards. No manual clean-up. The promise, kept.
    14. Say it once, tell everyone. Confirmed. Now warehouse, notifications and analytics all want to know. One event on EventBridge, and each listens on its own.
    15. Never make the warehouse wait. The warehouse is slow at nine pm, so a queue takes orders at its pace. Five failures move an order to a side queue so it never blocks others.
    16. Tell the customer. One event, and SNS sends push, SMS and email. SMS provider down? The push still lands. Orders never wait for messages.
    17. Watch every step. CloudWatch gathers logs, X-Ray follows one order across all functions, and an alarm fires if the dead-letter queue is not empty.
    18. The whole picture. That is one order, tap to push. Trace an order, or open the full diagram.

    More stories on Real-world systems