Skip to content
Back to blog
  • AWS
  • Engineering
  • DevOps

Designing a Scalable Serverless API on AWS Lambda

How I structure Lambda + API Gateway + DynamoDB services that stay cheap, fast and maintainable as they grow.

MMuhammad Muneeb1 min read

Building a serverless API on AWS Lambda gets you a long way before you ever think about servers - but only if you structure it deliberately. Here is the pattern I reach for on most AWS projects.

Designing a serverless API on AWS Lambda: One handler, one responsibility

Each Lambda should do exactly one thing. For tasks that take longer, offload them like background jobs with BullMQ, and keep core business logic in plain, testable modules while letting the handler act as a thin adapter.

src/handlers/createOrder.ts
import type { APIGatewayProxyHandlerV2 } from 'aws-lambda'
import { createOrder } from '../services/orders'

export const handler: APIGatewayProxyHandlerV2 = async (event) => {
  const body = JSON.parse(event.body ?? '{}')
  const order = await createOrder(body)
  return {
    statusCode: 201,
    body: JSON.stringify(order),
  }
}

Model access patterns, not entities

DynamoDB rewards you for designing around how you read data. List your access patterns first, then design the partition and sort keys to serve them with single-digit-millisecond queries.

  • Start from the queries, not the schema.
  • Use a single-table design where it genuinely simplifies access.
  • Add GSIs only for patterns you actually have.

Infrastructure as code from day one

CloudFormation or the CDK means every environment is reproducible and every change is reviewable. When moving beyond serverless to traditional hosting, similar discipline applies to self-hosting Next.js on a VPS with PM2 and Nginx, keeping infrastructure maintainable over time.

Related posts