โ Back to AWS Step Functions
๐ AWS Step Functions: cheat sheet
๐จ The analogyA relay race through town, run by an official with a course map who records every handover.
๐ The regular explanationAWS Step Functions runs workflows defined as state machines in Amazon States Language, calling Lambda functions and AWS APIs step by step, with built-in retries, error branches, parallelism and a recorded history of every execution.
- The starter fires the pistol with an order on the baton. The official opens a new logbook page and hands back a race number.
- The map says the first leg is checking the order. The official hands the baton to runner 1, who checks it and hands it back.
- Next on the map is payment. The baton goes to runner 2, now carrying a line that says the order was fine.
- Runner 3 packs the parcel. That's the last leg on the map, so the official writes "finished" in the logbook.
- The first runner counts the shelf and writes "3 left" on the note. The baton reaches a fork in the road.
- The official reads the note. There's stock, so the race goes up the road to a side-by-side stretch, and two runners set off at once with a copy each.
- The official waits until both runners are back, then the race crosses the finish line with both results on the note.
- In the next race the shelf is empty. At the fork, the official points down the other road, where a red flag ends the race and writes down why.
- The payment runner sets off, but the card machine is busy and the baton drops. The map says wait one second and try again.
- Second try, same trouble. The official waits twice as long this time, two seconds.
- Third try, and it drops again. The map allowed two extra tries, and both are used up.
- The map shows a detour for this, so the race goes to a station that phones the customer, instead of stopping with a red flag.
- A long race starts. It may take up to a year, and the official writes every handover in the logbook as it happens.
- Each leg is run exactly once, unless the map asks for a retry. You pay per handover.
- A sprint must finish within five minutes. Started and left alone, now and then the whole sprint gets run again from the start, so every runner must spot a baton they've already seen.
- The sprint official keeps no logbook. If you ask, a summary goes to the town records office. You pay by sprints run, how long and how much they carry.
- The official hands the order straight to the order-book shop, which writes it down and says done at once. No runner needed.
- Next the official orders a big cake at the bakery, and stands at the counter while it bakes.
- The cake is ready. The official takes it and the race goes on.
- A big order needs the manager's say-so. The official drops a numbered ticket in the ticket box, and the race pauses.
- Later the manager picks up the ticket from the box and looks at the order.
- The manager hands the ticket back saying approved. The official knows exactly which race it belongs to, and that race starts running again.
- The stockroom sets the parcel aside for this order.
- The till takes the customer's money.
- The courier has no van, even after a couple of tries. The race can't finish, but it can't just stop either.
- The detour runs backwards. First the till gives the money back, checking the order number so it never refunds twice.
- Then the stockroom puts the parcel back on the shelf. Everything is undone, and the official raises the red flag with the reason.
๐งฉ Key questions
- The payment runner took the money but tripped on the way back, so the official sees a dropped baton and has the leg run again. What should the payment runner do?
- Check the order number on the note first, and skip the charge if it's already been taken. A retry re-runs a leg that may already have done its job, so each runner checks whether the work was done.
- A race has to pause for up to two days until a manager says yes to a big order. Which way of running it fits?
- A long race, handing the manager a numbered ticket and waiting for it to come back. Sprints last five minutes at most and can't hand out tickets; a long race can pause for days, and a time limit stops a lost ticket holding it forever.
- The stockroom has set a parcel aside and the till has taken the money, then the courier has no van. What should the map do?
- Take a detour that refunds the money, then puts the parcel back, then raises the red flag. Each finished leg changed something real, so the detour undoes them, last one first, before the race is marked as failed.
- You need millions of tiny races a day, each over in a second, and every runner can safely see the same baton twice. Which kind of race?
- Sprints, paid by how many and how long, with a summary sent to the records office. Sprints are made for huge numbers of short races, and the only price, a race now and then run twice, doesn't matter here.