What is AWS Lambda and when would you use it?
Reviewed by Gurusankar M.
⚡ Short Answer
AWS Lambda is a serverless, event-driven compute service — you upload a function, AWS runs it in response to a trigger (API Gateway, S3, SQS, EventBridge, a schedule), and you pay only for actual invocation time, not idle capacity. Best fit: spiky or infrequent event-driven work under Lambda's 15-minute max runtime; a poor fit for steady, high-throughput, latency-critical, or long-running workloads where a warm always-on server is cheaper and faster.
☕Coffee Chat Question
Concept Made Simple
“What is AWS Lambda and when would you use it?”
🧠Mind Map Answer
Remember It Faster
Lambda is a taxi driver 🚕. You don't own the car or keep it idling in a garage — one shows up when you need a ride (an event), drives, and you pay only for the trip. No passengers, no cost.
Cold start, mechanically: on the first invocation (or after enough idle time that AWS reclaims the environment), Lambda has to provision a fresh execution environment — download the deployment package, start the runtime, run any code outside the handler (imports, SDK client construction, connection pool setup) — before the handler itself runs. That init cost is the cold start; a warm invocation reuses an already-initialized environment and skips straight to the handler. Provisioned concurrency pre-initializes a set number of environments ahead of traffic so requests hit warm environments on demand, at the cost of paying for that reserved capacity whether it's used or not.
Two hard limits shape when Lambda fits: a single invocation can run at most 15 minutes, so anything longer needs Step Functions, Fargate, or a traditional server. And Lambda's memory setting isn't just RAM — CPU and network bandwidth scale proportionally with the memory you allocate, so a CPU-bound function that's slow isn't necessarily under-provisioned on logic, it may just be under-provisioned on memory (raising memory can make a compute-heavy function finish faster and, counterintuitively, cost about the same or less, since you pay for memory × duration and a faster function needs less duration).
Concurrency, not requests-per-second, is the limit that actually throttles Lambda. Every AWS account has a regional concurrent executions ceiling (1,000 by default, raisable by support request) shared across every function in the account unless carved up — one invocation in flight counts as one unit of concurrency for as long as it runs, so a function that takes 5 seconds under sustained load needs roughly 5× the concurrency of one that takes 1 second to sustain the same request rate. Reserved concurrency caps how much of that shared pool one function can consume (protecting other functions from being starved by one noisy neighbor, at the cost of that function throttling once its own reservation is exhausted); provisioned concurrency additionally pre-warms environments within that reservation. Exceeding available concurrency doesn't queue politely — synchronous invocations (API Gateway) return a 429 TooManyRequestsException immediately, while asynchronous invocations (S3, EventBridge) retry automatically and eventually land in a configured dead-letter queue or destination if retries are exhausted.
Java specifically has a worse cold start than Python/Node, and SnapStart is AWS's fix for it. JVM startup plus class loading plus framework initialization (Spring context, DI wiring) routinely pushes Java cold starts into the hundreds of milliseconds to low seconds, versus tens of milliseconds for an interpreted-language runtime with little to no framework overhead. SnapStart takes a different approach than shrinking the package or trimming dependencies: it initializes the function once, takes a Firecracker microVM snapshot of that fully-initialized execution environment (including the already-warmed JVM), and restores from that snapshot on every subsequent cold start instead of re-running initialization from scratch — turning a JVM-startup-sized cold start into essentially a restore-from-snapshot-sized one, at the cost of needing to handle any state that shouldn't be reused across invocations (like a fixed seed used at snapshot time) explicitly via a runtime hook.
⌨️Hands-on Keyboard
Learn by Doing
def handler(event, context):
name = event.get("name", "world")
return {"statusCode": 200, "body": f"Hello {name}"}🔥What If?
Think Beyond the Expected
What is a cold start and how do you reduce it?
The first invocation after idle has to spin up the runtime — that delay is a cold start. Reduce it with provisioned concurrency, smaller packages, and lighter runtimes.
😂Real World
Teams use Lambda for the 'glue' work: resize an image the moment it lands in S3, process a queue message, run a nightly cron, back a lightweight API. It shines for spiky, event-driven jobs where keeping a server running 24/7 would be wasteful.
🎯Interviewer's Expectation
Keywords they're listening for:
⚠️Common Mistakes
- ✗Initializing SDK clients / DB connections inside the handler instead of outside it, paying init cost on every warm invocation
- ✗Sizing memory only for RAM needs and ignoring that it also scales CPU
- ✗Using Lambda for a steady, high-throughput workload where an always-on server would be cheaper
- ✗Not setting a reserved/provisioned concurrency floor for latency-sensitive endpoints that can't tolerate cold starts
✅Best Practices
- ✓Initialize SDK clients and connections once outside the handler, so warm invocations reuse them
- ✓Use provisioned concurrency for latency-sensitive, user-facing endpoints
- ✓Keep deployment packages small and dependencies minimal to shrink cold-start init time
- ✓Treat the function as stateless — persist anything that must survive between invocations externally (DynamoDB, S3, ElastiCache)
🔁Follow-up Questions
- 1What actually happens during a cold start, step by step?
- 2How does provisioned concurrency eliminate cold starts, and what does it cost?
- 3Why does raising a Lambda's memory setting also increase its CPU allocation?
- 4When would a container on Fargate/ECS be a better fit than Lambda?
📚References
Continue Learning with AI
Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly — AI is your learning companion, not a shortcut.
Plain-language foundations
I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner. Topic: Lambda (AWS) Interview question: "What is AWS Lambda and when would you use it?" Please: 1. Explain the core idea in simple, plain language, using an everyday analogy. 2. Define any technical terms you use. 3. Walk through one small, concrete example. 4. Finish with a single sentence I can easily remember. Keep the tone friendly and assume I'm new to this topic.
Was this answer helpful?
⭐ Featured Products
Support our platform by exploring our recommended products.
As an Amazon affiliate, purchases through these links may earn us a small commission — at no extra cost to you. It helps keep Full Stack Interview Guru free.