Interview questions and model answers
"When would you choose Lambda over containers?"
For event-driven, short-lived work with spiky or low traffic: processing S3 uploads, consuming queues, scheduled jobs, webhooks and glue between AWS services. I get scale-to-zero, per-request billing and no servers to patch. For long-running services, steady high traffic, GPUs or very predictable latency, containers on Fargate or EKS are cheaper and give more control.
"What is a cold start and how do you reduce it?"
When no warm environment is free, Lambda creates one: it downloads the code, starts the runtime and runs the init code before the handler, which adds latency. I reduce it with smaller packages and lazy imports, doing setup once outside the handler, SnapStart for Java, Python and .NET, provisioned concurrency for latency-critical functions, and choosing lighter runtimes where latency matters.
"Explain reserved vs provisioned concurrency."
Reserved concurrency sets aside part of the account's concurrency pool for a function and also caps it, protecting both the function and its downstream systems; it costs nothing extra. Provisioned concurrency keeps a number of environments initialised in advance to avoid cold starts, and is billed for the time it's configured.
"Your Lambda reads from SQS and some messages are processed twice. Why?"
SQS and Lambda give at-least-once delivery. Common causes are a visibility timeout shorter than the processing time, so messages reappear while still being processed, or one failed record causing the whole batch to retry. I'd set the visibility timeout to at least six times the function timeout, enable partial batch responses, add a DLQ with a sensible maxReceiveCount, and make the handler idempotent using the message or business ID with a conditional write.
"A Kinesis-triggered function stopped processing and IteratorAge keeps growing. What's happening?"
A record the function can't process is failing the batch, and stream sources retry the same batch in order, blocking the shard. I'd look at the errors in the logs, then configure bisect on error, a maximum retry attempts or record age, and an on-failure destination so the bad record is set aside and processing continues, and fix the handler for that input.
"How do you deploy Lambda safely?"
Infrastructure as code with SAM, CDK or Terraform; publish immutable versions and point an alias at them; use CodeDeploy canary or linear traffic shifting on the alias with CloudWatch alarms on errors and latency for automatic rollback; and keep configuration and secrets out of code, loaded from Parameter Store or Secrets Manager.
"Hundreds of Lambdas are exhausting our PostgreSQL connections. Fix?"
Put RDS Proxy in front to pool and share connections, open the connection outside the handler so warm invocations reuse it, cap the function with reserved concurrency so it can't exceed what the database handles, and consider moving hot paths to DynamoDB or queueing writes through SQS.
"How do you handle a task that takes 40 minutes?"
Lambda's limit is 15 minutes, so either split it into smaller steps coordinated by Step Functions, for example a distributed map over chunks, or run it as a container task on Fargate or AWS Batch triggered by EventBridge or Step Functions. For an API, accept the request, return 202 with a job ID, and let the client poll or receive a callback.