Lambda Cold Starts, Concurrency, Provisioned Concurrency and SnapStart
The first customer of the morning waits while the chai stall lights the stove — that wait is a cold start. Later cups are fast on a warm stove. Lambda cold starts, concurrency limits, provisioned concurrency and SnapStart are how you manage that wait without pretending every function should be a always-on server.
What you'll learn in this chapter
- Explain cold vs warm start simply
- Read account and function concurrency
- Decide when provisioned concurrency is worth INR/USD
- Know SnapStart for Java
- Measure before paying
1. Everyday example: morning stove vs lunch rush
Sofia in Sofia (EUR) runs a ticket API. At 03:00 the stall is dark — first invoke pays init. At 12:00 ten stoves stay warm. If a flash sale needs p99 under 200 ms, she may buy provisioned concurrency — like paying rent to keep one stove lit overnight. If traffic is sparse, she measures and skips the rent.
Basics: What Is AWS Lambda? and first Lambda. This chapter is the performance and concurrency pattern layer.
2. Why care?
Why do we need this?
Users feel cold starts as random slowness. Bursts hit account concurrency and throttle. Blindly buying provisioned concurrency burns budget in USD or INR. Architecture means measure, then choose.
What is it?
Cold start = create execution environment + init code. Warm = reuse env. Reserved concurrency = cap a function. Provisioned concurrency = keep N envs initialized (you pay). SnapStart (Java) = snapshot init to speed cold starts.
3. Vertical diagram
4. How: measure then decide
How to do it (step by step)
- Turn on JSON logs or read REPORT Init Duration.
- Separate p50 handler vs p99 with cold starts.
- Check get-account-settings ConcurrentExecutions.
- Set reserved concurrency on noisy neighbors.
- Only if SLO needs it: provisioned concurrency or SnapStart.
- Re-measure monthly — traffic shape changes.
5. Per-concept commands
Account concurrency settings
aws lambda get-account-settings --region ap-south-1 \
--query 'AccountLimit'
Meaning: Shows UnreservedConcurrentExecutions — your shared burst pool.
Function concurrency config
aws lambda get-function-concurrency --region ap-south-1 \
--function-name ticket-api
Meaning: Reserved limit if set; empty means use account pool.
Provisioned concurrency config
aws lambda get-provisioned-concurrency-config --region ap-south-1 \
--function-name ticket-api --qualifier prod
Meaning: Confirms allocated vs available; status READY before trusting latency.
Pull Init Duration from logs (insight query sketch)
aws logs filter-log-events --region ap-south-1 \
--log-group-name /aws/lambda/ticket-api \
--filter-pattern 'Init Duration' --limit 10
Meaning: Cold starts leave Init Duration in REPORT — count them before buying provisioned.
6. Memory, CPU, package size
- More memory = more CPU on Lambda — sometimes faster and cheaper.
- Huge layers/deps extend cold start — trim package.
- VPC ENI attach historically hurt cold starts — understand Hyperplane era still has cost.
- Java: enable SnapStart on published versions; validate uniqueness of entropy.
7. When provisioned is worth it
| Signal | Action |
|---|---|
| SLO p99 user-facing API; cold starts break SLO | Provisioned or keep-warm carefully |
| Async SQS worker; latency soft | Usually skip provisioned |
| Spiky but rare demos | Accept cold or Function URL demo only |
| Every function 'needs' provisioned | Smell: maybe ECS for that workload |
8. Industries
- Fintech (Aisha, Lagos, NGN): authorize path provisioned; batch reports not.
- Ecommerce (Rohan, Pune, INR): checkout warm; recommendations async.
- Healthcare (Mei, Singapore, SGD): appointment book low latency.
- Media (Kenji, Osaka, JPY): thumbnail workers — cold OK.
- SaaS (Priya, Bengaluru, INR): multi-tenant API with reserved per tier.
9. Lab
10. Lab - measure cold starts
Do this in ap-south-1 (Mumbai) unless your org forbids it. Set a budget alert first.
How to do it (step by step)
- Invoke a lab function once after 15+ min idle; note Init Duration.
- Invoke 20 times quickly; note how many lack Init Duration.
- Read get-account-settings; write the unreserved number.
- Estimate monthly provisioned cost for N=2 at your memory size (USD and INR).
Cleanup (stop billing)
- Delete provisioned configs you created for the lab.
- Remove lab function if unused.
11. Same pattern across industries
- Fintech (Aisha, Lagos): payment webhooks → SQS → Lambda; never block the bank callback thread.
- Ecommerce (Rohan, Pune): checkout API on API Gateway+Lambda; inventory fan-out on SNS.
- Healthcare (Mei, Singapore): appointment SMS via SNS; PHI stays in DynamoDB with fine-grained IAM.
- EdTech (Diego, São Paulo): nightly cleanup EventBridge → Lambda on student drafts.
- Logistics (Fatima, Casablanca): package scan events on EventBridge bus; Step Functions for customs saga.
- Media (Kenji, Osaka): S3 upload → Lambda thumbnails; fan-out to moderation + CDN invalidate.
- SaaS multi-tenant (Priya, Bengaluru): Cognito groups + DynamoDB partition per tenant.
- Gov portal (Omar, Amman): strangler fig — peel one PDF form route per sprint to Lambda.
12. Troubleshooting checklist
- Confirm region (ap-south-1 vs us-east-1 for CloudFront/ACM quirks).
- Check CloudWatch Logs for the function name and request id.
- Verify IAM execution role allows the API you call.
- For async: check DLQ depth and SQS age of oldest message.
- For APIs: curl -v and compare status, CORS headers, body.
- For workflows: open Step Functions execution event history.
- Re-read the linked deep chapter before reinventing a service.
- If cost spikes: check concurrency, retries, and provisioned capacity.
13. Common errors and fixes
Each row is a real mistake students and juniors hit. Read the fix before you panic.
| Error / symptom | Fix |
|---|---|
| Throttles with low traffic | Reserved too low or account ceiling shared with noisy fn. |
| Provisioned not READY | Wait for allocation; check permissions and version/alias. |
| SnapStart uniqueness bugs | Do not cache host-specific entropy across snapshot. |
| Cold start worse after VPC | Minimize VPC need; use gateway endpoints; right subnets. |
| Cost spike overnight | Provisioned left on unused alias. |
| p50 fine p99 awful | Cold starts dominate p99 — measure Init. |
| Alias points at $LATEST with provisioned | Provisioned needs published version + alias. |
| Reserved=0 accidentally | Unreserve or set carefully — 0 throttles all. |
| Java still slow with SnapStart | Check dependency init outside snapshot lifecycle hooks. |
14. FAQ
Q. Is provisioned the same as reserved?
No. Reserved caps; provisioned keeps warm capacity you pay for.
Q. Does more memory always help cold start?
Helps CPU; package/VPC may still dominate.
Q. SnapStart for Python?
SnapStart is for Java on Lambda — check current AWS docs for others.
Q. Keep-warm cron?
Fragile and still races; prefer provisioned for true SLOs.
Q. Link?
Lambda intro chapters — then measure here.
15. Interview Q&A (Beginner / Mid / Senior + MNC)
Q. Beginner: cold start?
First invoke pays environment init.
Q. Beginner: warm?
Reuse environment; no full init.
Q. Mid: reserved vs provisioned?
Cap vs paid warm pool.
Q. Mid: when pay?
When measured p99 misses SLO on user path.
Q. Senior: noisy neighbor?
Reserved on abusers; protect critical unreserved headroom.
Q. MNC: cost governance?
Tags, budgets, monthly review of provisioned aliases.
16. Tips in English, Marathi and Hindi
Ravindra Bagale's Tip (EN)
Measure the stove time before you pay overnight rent for fire.
Ravindra Bagale's Tip (MR)
भाडं देण्याआधी स्टोव वेळ मोजा.
Tip (HI)
किराया देने से पहले स्टोव का समय मापो।
Try at home
- Find Init Duration on one function.
- Write if provisioned is justified.
In short
- Start from a real story, then name the AWS services.
- Link existing chapters — do not copy their labs.
- Design for failure: retries, DLQ, idempotency, rollback.
- Measure before you buy provisioned concurrency or multi-region.
17. Architecture decision checklist
- Write the user journey in five bullets with no AWS names.
- Mark each step sync (user waits) or async.
- Name failure mode: retry, DLQ, compensate, or alert-only.
- Name the idempotency key for every write.
- Pick data store from access patterns (link DynamoDB modeling).
- Estimate monthly cost at 1x and 10x traffic (USD and INR).
- Confirm account concurrency and service quotas in ap-south-1.
- Decide auth: Cognito, IAM, Lambda authorizer, or none.
- Name on-call and which CloudWatch alarm pages them.
- Link the deep chapter you will not rewrite.
- Only then open console or IaC.
18. Copy-paste quick commands (read-only first)
# Region and identity
aws configure get region
aws sts get-caller-identity
# Lambda landscape
aws lambda list-functions --region ap-south-1 --max-items 20 \
--query 'Functions[].{N:FunctionName,R:Runtime,T:Timeout,M:MemorySize}' --output table
aws lambda get-account-settings --region ap-south-1
# API Gateway (HTTP APIs)
aws apigatewayv2 get-apis --region ap-south-1 --query 'Items[].{N:Name,Id:ApiId,Ep:ProtocolType}' --output table
# Queues and topics
aws sqs list-queues --region ap-south-1
aws sns list-topics --region ap-south-1 --query 'Topics[].TopicArn'
# Event buses and state machines
aws events list-event-buses --region ap-south-1
aws stepfunctions list-state-machines --region ap-south-1 --query 'stateMachines[].name'
# DynamoDB tables (names only)
aws dynamodb list-tables --region ap-south-1
Run these in a sandbox account. Prefer read-only IAM while learning.
19. More industry and stack stories
- Fintech (Aisha, Lagos, NGN): bank webhooks must return 200 fast — SQS absorbs spikes; ledger Lambda is idempotent on paymentId.
- Ecommerce (Rohan, Pune, INR): Black Friday — API Gateway throttle + SQS order intake; SNS fans inventory, email, analytics.
- Healthcare (Mei, Singapore, SGD): appointment reminders via SNS SMS; PHI only in DynamoDB with condition keys.
- EdTech (Diego, São Paulo, BRL): EventBridge nightly cleanup of draft quizzes; Lambda timeout 30s, not 15 min.
- Logistics (Fatima, Casablanca, MAD): package scans on custom EventBridge bus; Step Functions customs saga.
- Media (Kenji, Osaka, JPY): S3 → Lambda thumbnails; never write thumbs to the watched prefix.
- SaaS (Priya, Bengaluru, INR): Cognito groups + DynamoDB PK tenantId; one Lambda authorizer for all routes.
- Gov (Omar, Amman, JOD): strangler — peel one PDF form route per sprint from the monolith.
- Startup (Sofia, Sofia, EUR): start with Function URL for demos; move to HTTP API when partners need JWT.
- Retail (Luis, Mexico City, MXN): store POS sync via SQS FIFO when order matters; Standard when it does not.
- Python: handlers thin; put domain logic in plain modules for unit tests without Lambda.
- Node: prefer async/await; never block the event loop on sync DNS.
- Java: SnapStart for cold starts; keep dependencies lean.
- .NET: AspNetCoreServer for low-traffic tenants; watch package size.
- Go: single static binary; great for SQS workers.
- PHP: keep Laravel queues on ECS; Lambda for S3/webhooks glue.
20. Glossary (short)
| Term | Meaning |
|---|---|
| Cold start | First invoke pays init; later invokes reuse the env |
| Idempotency | Same request twice → same effect |
| DLQ | Dead-letter queue for failed messages |
| Choreography | Services react to events; no central conductor |
| Orchestration | Central workflow (Step Functions) directs steps |
| Fan-out | One event → many consumers |
| Fan-in | Many branches join before next step |
| Strangler fig | Peel routes from monolith gradually |
| Saga | Distributed tx via steps + compensations |
| Provisioned concurrency | Keep N envs warm; you pay for ready capacity |
21. Practice: explain out loud
- 60 seconds: everyday story for Lambda cold starts and concurrency.
- 60 seconds: sync vs async with a checkout example.
- 60 seconds: when you refuse Lambda.
- 60 seconds: DLQ + idempotency in one breath.
- Record once; cut fillers; record again.
22. Safe lab hygiene
- Tag every lab resource with owner and expiry date.
- Set a monthly AWS Budget alarm in INR or USD before experiments.
- Prefer read-only commands first; mutate in a sandbox account.
- Delete queues, APIs, tables you created — DynamoDB and APIGW leave footprints.
- Never put production secrets in env vars or screenshots.
- Do not enable provisioned concurrency for a hello-world.
23. How this chapter links others
- Compute depth: Lambda.
- HTTP edge: API Gateway.
- Data modeling: DynamoDB.
- Messaging: SQS/SNS.
- Events: EventBridge.
- Workflows: Step Functions.
- Project chapters (build-*): worked assemblies — link, do not paste.
24. Myths to drop
| Myth | Reality |
|---|---|
| Serverless means zero servers | Servers exist; you do not manage them |
| Always cheaper than EC2 | Steady high load can favor EC2/Savings Plans |
| No Ops needed | You own IAM, data, alarms, cost, incidents |
| One Lambda per app is fine | Bounded contexts scale better |
| Queues are optional decoration | Queues are the load leveler and blast-radius wall |
25. Error budget thinking for serverless
If your monthly error budget is 0.1% on checkout, a fan-out that retries aggressively can burn the budget with duplicate emails while money stays correct. Separate business correctness SLOs from notification SLOs.
- Write two SLOs: money-correct and notify-delivered.
- Retries on money path: bounded + idempotent.
- Retries on notify path: best-effort + DLQ.
- Page humans on money DLQ; ticket on notify DLQ.
26. Regional notes (ap-south-1)
- Build labs in Mumbai (ap-south-1) unless your org mandates elsewhere.
- Some services launch first in us-east-1 — check feature availability.
- Data residency for INR fintech may require in-region only.
- Latency to end users in India usually favors ap-south-1.
27. Naming conventions that save incidents
# Suggested prefixes
# Lambda: pay-intake-prod, pay-worker-prod
# SQS: pay-orders.fifo / pay-orders-dlq
# SNS: pay-order-events
# EB bus: pay.domain
# SFN: pay-refund-saga
# DDB: pay-orders-prod
Include env (dev/stage/prod) and domain. Future you grepping CloudWatch will thank present you.
28. Pre-mortems (ten minutes)
- Imagine tomorrow headline: double charge in AED. What broke?
- Imagine DLQ depth 50,000 after a bad deploy. How do you drain?
- Imagine Cognito outage. Do APIs fail closed or serve read-only?
- Write answers in the runbook before go-live.
29. Currency and locale in examples
Rotate currencies in designs: INR, USD, EUR, AED, NGN, BRL, JPY, SGD. Rotate names: Aisha, Rohan, Mei, Diego, Fatima, Kenji, Priya, Omar, Sofia, Luis. This keeps mental models global — not one-country samples.
30. Worked story: Rohan flash sale (INR)
- Checkout Lambda p99 1.8s from cold starts.
- Measured 40% invokes cold in first 2 minutes.
- Provisioned=5 on alias live; p99 220ms.
- Async email worker left on-demand.
31. Anti-patterns
- Provisioned on every function including cron.
- Ignoring account ceiling during load tests.
- Tuning without REPORT metrics.
Revision, interview and comparison cards
Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.








More cards: Ravi Sir's Cards.
Practice Tasks
Amravati Agro Market is a agriculture business in Amravati. Anjali Thakre looks after its IT and cloud work. They count money in INR and run their AWS resources in the ap-south-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.
0 / 16
Easy Cold start = new env — 1
Why: Idea.
What to do: Enter 1 if a cold start means a new execution environment is created.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Easy Warm reuses env — 1
Why: Idea.
What to do: Enter 1 if a warm invoke reuses an existing environment.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Easy Concurrency = parallel — 1
Why: Scale.
What to do: Enter 1 if concurrency is how many executions can run in parallel.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Easy PC keeps warm — 1
Why: Tool.
What to do: Enter 1 if provisioned concurrency keeps environments initialized.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Easy List Lambda functions
Why: CLI.
What to do: List Lambda functions
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Easy Cold knobs YAML
Why: Map.
What to do: YAML: keep_warm: pc, java_help: snapstart.
- Start from the top-level keys the task names.
- Indent child keys with 2 spaces (no tabs).
- Fill in each property with the value from the task.
- Click Check answer. Key order does not matter.
Easy More memory can help — 1
Why: Perf.
What to do: Enter 1 if more Lambda memory also gives more CPU which can cut duration.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Medium SnapStart Java — 1
Why: Tool.
What to do: Enter 1 if SnapStart mainly helps Java cold starts via snapshots.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Medium Reserved concurrency — 1
Why: Cap.
What to do: Enter 1 if reserved concurrency caps one function and protects others.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Medium Heavy init outside handler — 1
Why: Code.
What to do: Enter 1 if heavy SDK clients belong outside the handler when possible.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Medium Smaller package helps — 1
Why: Size.
What to do: Enter 1 if smaller deployment packages often reduce cold start time.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Medium Cap YAML
Why: Limits.
What to do: YAML: protect_others: reserved, parallel: concurrency.
- Start from the top-level keys the task names.
- Indent child keys with 2 spaces (no tabs).
- Fill in each property with the value from the task.
- Click Check answer. Key order does not matter.
Hard Account burst limits — 1
Why: Limit.
What to do: Enter 1 if account burst concurrency can throttle sudden spikes.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Hard PC costs when idle — 1
Why: Money.
What to do: Enter 1 if provisioned concurrency still costs when traffic is idle.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Hard VPC ENI used to hurt — 1
Why: History.
What to do: Enter 1 if VPC attach historically worsened cold starts (Hyperplane improved).
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Hard Delete lab same day — 1
Why: Hygiene.
What to do: Enter 1 if lab-spi-cold should be deleted same day.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.