Blog
Thoughts on engineering, design, and building great products.
Cold Start: Measure It for Real, Then Optimize What's Optimizable
Back to cold start with real numbers. Force a cold start on the resolve handler to see Init Duration and the cost of the first call, then examine the ways to reduce it: more memory (also more CPU), smaller package, SnapStart, and provisioned concurrency — each has its own place, and on the test account one doesn't apply.
Observability: Lambda Powertools and X-Ray Tracing
Start operating like production by being able to see inside. Wire in Lambda Powertools for structured JSON logs and pushed metrics, enable X-Ray to trace which services a request passes through. Read a real trace showing the resolver calling DynamoDB and EventBridge as subsegments, and a log line carrying a trace id to link logs to traces.
Counting Clicks Safely: Idempotency, DLQ, and Partial Batch Failure
Turn the logging consumer from the previous article into a real aggregator. Insert SQS between EventBridge and Lambda for batching, retry, and a dead-letter queue, count clicks into DynamoDB with a transaction that both increments counters and prevents double-counting in one atomic operation, and report failures per message so only the broken one is retried. Real tests: a duplicate event counts once, a failing event lands in the DLQ.
Wiring DynamoDB Into Code: Safe Writes and Atomic Counter
Wire the two handlers into the real DynamoDB: create-link writes an item with a conditional write so it never overwrites a duplicate code, resolve-link does a lookup then counts clicks with an atomic counter. Fire many opens in parallel to see the atomic counter count exactly, and hit a real account limit — Lambda concurrency — when 40 of 50 requests come back 503.
How Lambda Runs Your Code Internally
Dissect Lambda's execution environment lifecycle: the three phases Init, Invoke, Shutdown, why cold start exists, and how static code runs once. Measure cold start for real (Init Duration), then measure the memory–CPU relationship with the same CPU work at 128 MB and 1769 MB. Understand this so later performance and cost decisions have a basis.
Setting Up the Environment: AWS SAM and Your First Lambda Function
Install the AWS SAM CLI, build a project skeleton for the URL shortener (TypeScript + esbuild), then deploy a real Lambda function to AWS via a Function URL, call it with curl, run it locally in Docker, and clean up with one command. Plus a lesson on the SAM CLI needing to be new enough to support the nodejs22.x runtime.
What Serverless Is and When to Use It
Series opener: what serverless actually means (not 'no servers'), what it trades away and what it gains, when NOT to use it, and the product we build throughout — a URL shortening service with realtime analytics. Includes the overall architecture diagram and a per-part roadmap.