AWS Lambda
medium 25 minAWS Lambda runs your function when an event arrives and stops charging when it ends.
See it run
Start cold, start warm, count environments, and see who retries when something fails.
Operations
Cold start
No environment exists yet.
Step 1 of 6
Nothing runs
The function exists as code. There is no environment.
Step 1: Nothing runs
def invoke(event): check_permissions_and_limits() env = free_environment() if env is None: env = create() # download, start runtime env.run_init_code() # outside the handler result = env.handler(event) env.freeze() return result- Extra delay
- Under 100 ms to over 1 s
- You pay
- Init and handler time
- Warm start
- no init
Your own init code is usually the largest part, and the part you control.
In the real world
The same aws lambda doing real jobs. Pick one and step through it.
The function scales, the database does not.
Step 1 of 4
Morning
- Connections used
- 20%
Forty environments hold forty connections.
Step 1: Morning
Common mistakes
The bugs interviewers watch for, with the fix beside each.
A client for every call
majorEach request pays for a new connection, and the database fills up.
Wrongdef handler(e, c): db = connect()Rightdb = connect()def handler(e, c): ...Mark done, then work
criticalA crash in between loses the event, because the retry sees the mark.
Wrongmark(event_id)charge(order)Rightcharge(order, idempotency_key=event_id)# or effect and mark in one writeExpecting reserved to be warm
minorReserved concurrency is a share and a cap. Cold starts stay.
Wrongreserved = 10 # "no cold starts"Rightprovisioned = 10No failure destination
criticalAfter the last retry, an asynchronous event is discarded.
Wronginvoke(type="Event")Righton_failure = queue_arn
Interview tips
How to explain it
- Code runs when an event arrives.
- One request per environment, warm if reused.
- Concurrency is rate times duration.
Memory trick
- Ring: a helper.
- Apron: the cold start.
- Full house: 429.
Reach for it when
- Work is short and event-driven.
- Traffic is uneven.
- Nobody wants to run servers.
Be careful when
- Load is steady and high.
- A small database sits behind it.
- One pool serves several teams.