▶What is a cold start and why does it matter?
Cold start = first invoke of a Lambda function takes 50-500ms longer because AWS must provision a container. Warm invocations take 1-10ms. Cold starts matter for: user-facing APIs (aim <200ms), high-latency use cases. Mitigations: reserved concurrency (always warm), provisioned concurrency ($$), choice of runtime (Go/Rust fastest; Java slowest), connection pooling, Lambda Layers for dependencies.
▶How do I avoid vendor lock-in with serverless?
Real lock-in exists: AWS Lambda → SQS → DynamoDB → EventBridge → Step Functions creates tight coupling. Portability options: (1) Containerize with Docker+ECS for multi-cloud (lose serverless benefits), (2) Use Serverless Framework/IaC to abstract providers (partial), (3) Keep business logic cloud-agnostic, push cloud-specific code to edges/adapters. Reality: vendor lock-in is acceptable trade-off for reduced ops overhead. Migration cost is high but rare (<2% of teams move once deployed).
▶When should I NOT use serverless?
Avoid serverless for: (1) Low-latency real-time (<20ms) — network overhead kills you, (2) Long-running processes (>15 min timeout), (3) Constantly-running background workers (cron jobs better on EC2/ECS), (4) Massive compute (ML training, rendering) — container/VM cheaper, (5) HIPAA/PCI compliance (limited attestation), (6) Databases (RDS/Postgres not serverless-friendly, use DynamoDB instead).
▶Edge vs Region — when do I use Cloudflare Workers vs Lambda?
Lambda: centralized compute in one AWS region (us-east-1, eu-west-1), 100ms latency global, rich ecosystem (DynamoDB, SQS, Kinesis), $0.02/1M requests. Cloudflare Workers: runs on edge (150+ locations), 1-10ms latency worldwide, limited to 50ms execution, lightweight (JSON parsing, API proxying, auth), $0.50/1M requests. Use Lambda for business logic; Workers for request routing, auth, caching, edge transformations.
▶How do I estimate serverless costs?
Lambda pricing: $0.20 per 1M requests + $0.0000166667 per GB-second. Example: 1M requests × 256MB × 100ms = $0.20 + $0.417 = ~$0.62/month (cheap). But: data transfer ($0.09/GB), DynamoDB reads/writes ($1.25/$6.25 per 1M), X-Ray tracing, CloudWatch logs add up. Tools: AWS Pricing Calculator, Parqet (cost breakdown). Serverless ≤ containers at <10k req/day; containers cheaper at scale (>100k req/day).
▶How do I debug Lambda in production?
Logging: CloudWatch Logs (stdout/stderr), JSON structured logging, tail via AWS CLI. Tracing: AWS X-Ray for latency breakdown (SQL, DynamoDB, HTTP calls). Errors: CloudWatch alarms on error rates, Lambda Insights for memory/duration profiles. Local testing: Serverless Framework offline plugin, AWS SAM local, LocalStack (local AWS clone). Never rely on logs alone — add synthetic monitoring (uptime checks, load testing).