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.
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?
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.
Cold start = create execution environment + init code. Warm = reuse env. Reserved concurrency = reserve part of the account pool for this function and cap it at that number. It does not preinitialize environments. Provisioned concurrency = keep N envs initialized (you pay). SnapStart = restore initialization snapshots for supported runtimes on published versions. Check support and test how initialization behaves after restore.
3. Vertical diagram
4. How: measure then decide
- 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.
- 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?
Yes. AWS lists Python 3.12 and later, Java 11 and later, and .NET 8 and later among supported managed runtimes. Check the current runtime and Region list. Invoke a published version or its alias, and do not combine SnapStart and provisioned concurrency on the same version. Lambda SnapStart documentation
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
Practice checks run in your browser. They check the answer for this exercise; they do not create resources or connect to your AWS account.
About this scenarioAmravati 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 Explain extra latency on a new environment
Two requests take the same time inside your handler, but the first also includes loading code and starting the runtime. What is that extra startup called?
- Read the situation and identify what you need to decide.
- Work through the relevant concept or calculation.
- Enter only the requested term or number.
- Check your answer, then read the explanation.
Easy Name the reused invocation path
A request runs in an already initialized Lambda execution environment. Is that a warm invocation or cold start? Enter the term.
- Read the situation and identify what you need to decide.
- Work through the relevant concept or calculation.
- Enter only the requested term or number.
- Check your answer, then read the explanation.
Easy Estimate simultaneous executions
A function sustains 50 requests per second and each takes 0.2 seconds. Assuming steady traffic, about how many executions are in flight at once? Enter a number.
- Read the situation and identify what you need to decide.
- Work through the relevant concept or calculation.
- Enter only the requested term or number.
- Check your answer, then read the explanation.
Easy Prepare checkout environments before traffic
Your measured p99 checkout latency is dominated by cold starts. Which paid Lambda setting preinitializes environments for a version or alias?
- Read the situation and identify what you need to decide.
- Work through the relevant concept or calculation.
- Enter only the requested term or number.
- Check your answer, then read the explanation.
Easy List Lambda functions
CLI.
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
Map.
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 Tune CPU for a calculation
A compute-bound handler takes too long. Which Lambda configuration setting also increases its CPU allocation as you raise it?
- Read the situation and identify what you need to decide.
- Work through the relevant concept or calculation.
- Enter only the requested term or number.
- Check your answer, then read the explanation.
Medium Choose a SnapStart configuration
Which is supported when the Region supports SnapStart? Enter 1 for an unpublished Python 3.12 $LATEST version or 2 for a published Python 3.12 version with SnapStart enabled.
- Read the situation and identify what you need to decide.
- Work through the relevant concept or calculation.
- Enter only the requested term or number.
- Check your answer, then read the explanation.
Medium Cap a noisy function without prewarming it
A batch function exhausts shared account capacity. Which Lambda setting can reserve a fixed part of capacity for that function and prevent it exceeding that amount?
- Read the situation and identify what you need to decide.
- Work through the relevant concept or calculation.
- Enter only the requested term or number.
- Check your answer, then read the explanation.
Medium Reuse a client across requests
A function constructs an SDK client on every invocation. Which part of the function should create a reusable client if doing so is safe for the SDK?
- Read the situation and identify what you need to decide.
- Work through the relevant concept or calculation.
- Enter only the requested term or number.
- Check your answer, then read the explanation.
Medium Reduce work before the handler starts
Two ZIP-based Lambda functions run the same code, but one carries many unused dependencies. What build output should the team slim down first?
- Enter the term or setting requested.
- Check your answer, then compare your reasoning with the solution.
Medium Cap YAML
Limits.
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 Check account capacity when a second function slows
An unrelated batch job uses up the shared Lambda capacity pool, and a web function’s new requests throttle. What account quota measures the simultaneous executions available in the Region?
- Enter the term or setting requested.
- Check your answer, then compare your reasoning with the solution.
Hard Identify the idle warm-capacity charge
An alias has preinitialized capacity all night but no traffic. Which Lambda feature keeps incurring a capacity charge while configured?
- Read the situation and identify what you need to decide.
- Work through the relevant concept or calculation.
- Enter only the requested term or number.
- Check your answer, then read the explanation.
Hard Separate network configuration from startup guesswork
A Lambda must reach a private RDS instance. What Lambda configuration should you inspect to see its selected subnets and security groups?
- Enter the term or setting requested.
- Check your answer, then compare your reasoning with the solution.
Hard Stop paying for prewarmed capacity in a finished lab
You keep a function alias for class notes, but no longer need its paid prewarmed environments. What Lambda setting must you remove for that alias?
- Enter the term or setting requested.
- Check your answer, then compare your reasoning with the solution.