Skip to content

Lesson 7 of 9 · 21m

Serverless Cost Models and FinOps

Requests, duration, memory, provisioned concurrency, API Gateway, logs, networking, and data transfer — what actually dominates the bill.

Serverless cost discussions swing between "basically free" and "ten times more expensive than EC2." Both can be true because the pricing model is granular. You pay per request, per millisecond, per allocated GB-second, per log line, per API call, and often per byte leaving the platform. Architecture decides which meter spins fastest.

Lambda's meter is simple but deceptive

cost = invocations * request price
     + invocations * duration * allocated GB-seconds
     + provisioned concurrency time, if enabled

A rough model is enough to expose bad assumptions:

requests/day:       2,000,000
average duration:   120 ms
memory:             512 MB
GB-seconds/request: 0.5 * 0.120 = 0.060
monthly GB-seconds: 2m * 30 * 0.060 = 3,600,000

Compare that with an always-on container only after including utilization. A mostly idle container is not automatically cheaper because its hourly rate looks small.

The surrounding platform often costs more

A real API may include API Gateway, CloudWatch Logs, DynamoDB, NAT Gateway, data transfer, EventBridge, SQS, Step Functions, WAF, secrets, and observability tooling. I have reviewed systems where Lambda compute was 12% of the bill and logs were 35%. The application was serverless; the cost driver was telemetry.

Logs are a pricing surface

This line is inexpensive once and expensive fifty million times:

logger.info("event received: %s", json.dumps(event))

Set levels deliberately, sample noisy success paths, and configure retention:

LogGroup:
  Type: AWS::Logs::LogGroup
  Properties:
    LogGroupName: /aws/lambda/orders-api
    RetentionInDays: 14

Retention is also data minimization. Full event payloads often contain personal data you never intended to keep.

Workflow and networking meters matter

Step Functions Standard charges per state transition; Express Workflows price differently and fit high-volume short workflows. Read the model before choosing. In VPC designs, NAT Gateway hourly and data-processing charges can dwarf Lambda compute. Prefer gateway VPC endpoints for S3 and DynamoDB, and question whether a function needs private subnet placement at all.

Tag before you optimize

Cost allocation is architectural hygiene:

Tags:
  service: billing
  environment: prod
  owner: platform-team

Without tags, every optimization conversation becomes archaeology across a shared bill.

Field notes

  • Provisioned concurrency is continuous cost. Tie it to measured latency requirements, not fear.
  • High invocation counts make edge economics important: API Gateway, ALB, CloudFront, and function URLs are not interchangeable cost-wise.
  • Enable budgets and cost anomaly detection before launch.
  • The cheapest design often does less work: batch events, cache responses, avoid unnecessary fanout, and do not log the universe.

Was this lesson helpful?

Sign in to rate