โ Back to AWS Lambda and serverless
๐งโ๐ณ AWS Lambda and serverless: cheat sheet
๐จ The analogyA kitchen with no cooks waiting around: each order gets a station, and you pay only while it cooks.
๐ The regular explanationAWS Lambda runs your function in managed execution environments in response to events, scales by adding environments per concurrent request, and bills per request and per millisecond of duration at the memory you configure.
- A customer at the counter hands in an order. A cook at a station makes the dish from your recipe and hands it straight back.
- The bill gets one line for that dish, with the minutes the station spent cooking it.
- A delivery is left at the back door. That's an order too, so a station cooks it and the bill gets another line.
- At nine o'clock the kitchen clock rings for the morning bread. The clock can order dishes too.
- Then nobody orders for an hour. No dishes, no new lines on the bill, nothing to pay.
- The first order of the day, and no station is ready. Someone unpacks the knives and lights the stove first, so this dish is slow. That's a cold start.
- The cook fetches what's needed from the pantry, finishes the dish and hands it over.
- The next order goes to the same station. The stove is still hot, so the dish comes out quickly.
- The cook left some chopped onions on the counter. The next order here might find them, but nobody promises that.
- After a quiet spell the station is cleared away, onions and all. Anything worth keeping belongs in the pantry.
- Three orders arrive at once. A station cooks one dish at a time, so the head chef sets up two more stations.
- This recipe may use three stations at most. A fourth customer is told "not right now, try again in a moment".
- Those three stations are also kept for this recipe, so a busy neighbour's recipe can never take them.
- For a rush you know is coming, you pay to keep stations set up with stoves lit. Orders start cooking straight away.
- A customer at the counter waits for the dish, and would find out straight away if it went wrong.
- A delivery driver drops a ticket in the tray. The kitchen says "got it" at once, and the driver leaves.
- The cook starts, but the kitchen timer rings before the dish is ready, so it goes in the bin.
- Because it came from the tray, the kitchen tries twice more, with a pause before each try. Both fail.
- Out of tries, the ticket goes in the failed box you put out, so someone can look at it later. Without a box it would be thrown away.
- While the station is set up, the cook clips on a badge that lists the pantry, and gets the pantry door ready, just once.
- An order arrives. The cook fetches from the pantry, which the badge allows, and hands back the dish.
- The recipe also asks for something from the wine cellar. The badge doesn't list it, so that door stays shut.
๐งฉ Key questions
- The recipe says to light the stove at the start of every dish. Why is that a poor recipe?
- A station that stays set up keeps its stove hot, so lighting it once at setup saves time on every later dish. The next ticket usually goes to the same station, so setup work done once pays off again and again.
- The cook keeps a tally of orders written on the station's counter. What goes wrong?
- Busy times use several stations, and stations get cleared away, so each tally is partial and can vanish. Anything worth keeping belongs in the pantry, not on a station's counter.
- Your recipe may use three stations at most, and all three are busy. What happens to a fourth customer at the counter?
- They're told not right now, and have to ask again. The set-aside number is also a ceiling, and a customer at the counter isn't put in the tray.
- A ticket from the tray keeps failing because the timer rings. Why should the recipe check the ticket number before cooking?
- The kitchen tries again, and a dish that was half done before the timer may be made twice. Tray tickets get two more tries, so the same ticket can reach a cook more than once.