AWS Lambda
serverless computing
function design
cloud architecture
microservices

One Lambda Function OR Multiple Lambda Functions

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Choosing between one large Lambda and multiple smaller Lambdas is an architecture decision about scaling, ownership, and operational risk. A single function can be simpler at the start, while multiple functions improve isolation and independent evolution. The right answer depends on workload shape and team structure, not on a fixed rule.

Single-Function Router Pattern

One Lambda can route requests by action or path.

javascript
1export const handler = async (event) => {
2  const route = event.routeKey || event.action;
3
4  if (route === "createOrder") {
5    return { statusCode: 200, body: JSON.stringify({ op: "create" }) };
6  }
7
8  if (route === "cancelOrder") {
9    return { statusCode: 200, body: JSON.stringify({ op: "cancel" }) };
10  }
11
12  return { statusCode: 400, body: JSON.stringify({ error: "unknown route" }) };
13};

This pattern is effective for early-stage services where operations share dependencies and release cadence.

Strengths and Limits of One Function

Strengths:

  • lower infrastructure surface area
  • one deployment unit
  • fast bootstrap for small teams

Limits:

  • broader IAM scope unless heavily segmented
  • shared cold-start profile across unrelated operations
  • harder incident isolation as routes grow
  • one deployment can affect all capabilities

As complexity rises, this pattern can become an operational bottleneck.

Multiple-Function Pattern

Splitting functions by capability improves isolation.

yaml
1Resources:
2  CreateOrderFn:
3    Type: AWS::Serverless::Function
4    Properties:
5      Handler: create.handler
6      Runtime: nodejs20.x
7      MemorySize: 256
8      Timeout: 6
9
10  CancelOrderFn:
11    Type: AWS::Serverless::Function
12    Properties:
13      Handler: cancel.handler
14      Runtime: nodejs20.x
15      MemorySize: 128
16      Timeout: 3

Each function can scale, fail, and deploy independently.

Benefits of Multiple Functions

  • least-privilege IAM per operation
  • per-route memory and timeout tuning
  • clearer ownership boundaries for teams
  • targeted rollback and safer releases

Tradeoff is higher infrastructure management overhead, which can be controlled with templates and shared tooling.

Cost and Cold-Start Considerations

Many teams assume one function is always cheaper. In practice, cost depends on invocation profile, package size, and runtime tuning.

Important factors:

  • package size and dependency bloat
  • provisioned concurrency for critical paths
  • memory settings per workload
  • idle traffic distribution

A large monolithic function with heavy dependencies can increase cold-start latency for all routes, including simple operations.

Security and Compliance Angle

Security boundaries are often the deciding factor:

  • if one operation requires elevated access, separate it
  • if audit rules demand distinct logs and controls, separate functions
  • if data domains differ by sensitivity, isolate aggressively

Security-driven decomposition is usually easier than retrofitting permissions later.

Hybrid Migration Strategy

A practical path:

  1. start with one function for MVP speed
  2. extract high-traffic route first
  3. extract high-risk security route second
  4. keep shared libraries versioned and minimal

This balances delivery speed with progressive hardening.

Observability Requirements

Regardless of architecture:

  • include request correlation IDs
  • emit structured logs with route or function labels
  • track latency and error metrics per operation
  • define retry and idempotency behavior clearly

Without observability discipline, both designs become difficult to operate.

Shared Code and Packaging Strategy

When using multiple functions, organize shared code in versioned libraries instead of copy-pasting utilities into each deployment package. This keeps bug fixes consistent and reduces review noise. At the same time, avoid pulling every shared dependency into every function, because oversized packages hurt cold-start behavior.

Deployment Pipeline Design

Independent functions are most valuable when pipelines support selective deploy and rollback. If your CI process always deploys every function together, you lose much of the isolation benefit. Invest early in per-function promotion controls and smoke tests so architecture and operations stay aligned.

Common Pitfalls

  • Keeping one function after clear domain and security boundaries emerge.
  • Splitting too early into many functions without shared deployment standards.
  • Reusing overly broad IAM policies across supposedly isolated functions.
  • Ignoring package size and dependency impact on cold starts.
  • Migrating function boundaries without updating monitoring dashboards and alerts.

Summary

  • One Lambda is simple and fast for early delivery.
  • Multiple Lambdas offer stronger isolation, tuning, and ownership clarity.
  • Choose based on scaling, security, and team boundaries.
  • Use a staged hybrid migration as complexity grows.
  • Maintain strong observability and deployment discipline in either model.

Course illustration
Course illustration

All Rights Reserved.