Cost Optimization
Advanced 16 min read Cost Optimization

Cost-Optimized Architecture Patterns

Cheap is a design property, not a clean-up

Designing cheap from the start: serverless/spot for spikes, storage tiering, egress-aware topologies, cost-aware autoscaling, and lifecycle polices. The levers meet the drawing board, so savings are cultural, not cruft-removal.

architectureserverlessspottieringegress-awarelifecycleautoscaledesign
Before we start

What you will learn

  • Choose compute patterns by cost shape (on-d/sp/srvless)
  • Design storage/egress-aware topologies
  • Budget cost in architecture reviews
In 60 seconds

Cost-aware architecture picks the right tool per traffic shape: spot for stateless bursts, serverless for spiky/event-driven, commitments for steady, tiered storage for cold data, egress minimized by geography. Autoscaling with cost, lifecycle policies, and tagging-gates built in.

Introduction

What is this?

Compute shapes: steady (EC2/VM + commitments), bursty-stateless (spot/spot-asg + autoscale), spiky-short (Lambda/Cloud Run: zero-idle-cost), GPU batch (spot/transient). Storage: S3/GCS tiers + lifecycle to cold/archive; object storage instead of EBS-mounted folders; databases sized + committed (not gold-plated instances). Networking: egress-aware — keep compute near data (nuance vs replication), use private endpoints/interface, cache at edge, watch cross-region/AZ chatter. Autoscaling: scale-to-zero for dev, warm pools + spot mix, scheduled scale (office hours), memory-aware CPU sizing. Lifecycle: dev/test nightly stop, env-level tags + SCP caps, snapshot pruning. Use-case: pipelines (spot workers, cheap eventing), static sites (S3+CFN, zero server), data lake (tiered storage). Architecture review gate: cost mode per service in the design doc, unit cost projected.

Motivation

Why do you need it?

  • Design-time cost beats remediation: serverless/spot from day one avoids the 'we've built it heavy' tax.
  • Egress/tiering are design decisions — the topology you draw determines the bill.
  • Cost-aware autoscaling (scale-to-zero, spot mix) turns 'idle at 3am' into free.
  • Patterns make the cheap option the default: reailly cheaper to run and operate.
Think about it

Mental model

Imagine

Choosing a car by trip type: commuter sedan (steady), taxi-share for weekends (spot), scooter for errands (serverless)

Think of

Compute-shape choice

Buying a 8-seat SUV for errands is over-provisioning; renting one for the weekend is fine. Match the vehicle to the trip shape and the garage (bill) shrinks — same for capacity.

Mechanics

How it works

  • Classify workload by traffic shape (steady/bursty/spiky) and data tier (hot/cold).
  • Pick per-shape: on-demand+commit / spot+autoscale / serverless / tiered storage.
  • Design egress-aware: keep data near compute, edge-cache reads, minimize cross-region replication.
  • Encode lifecycle + tag gates in IaC; autoscale with cost-aware policies.
  • Arch review gate: cost-per-service model + projected unit cost in the design.

Shape-to-pattern map.

Traffic shape
Compute
Storage
Networking
Lifecycle
Hands-on

Examples

A cheap-as-design pipeline

A cheap-as-design pipeline
# Ingest → process → store → serve (cost-shaped):
# ingest : S3 event → Lambda (spiky = serverless)
# process : spot EMR/GPU batch (stateless burst = spot)
# store : tiered (hot 30d, cold 90d, archive yearly via lifecycle)
# serve : S3 + CloudFront/edge (no servers)
# ops : scale-to-zero dev; schedules during office hours
# est. : ~1/4 the always-on equivalent; idle-hour cost = archive tier only.

Every component chosen for its shape: spiky go serverless, bursty go spot, steady commits, cold archives. The drawing IS the saving.

Real world

In production

  • Static/read-heavy: S3 + CDN instead of a VM farm.
  • ETL: spot workers + tiered warehouse; spiky events via serverless.
  • Dev/test: scale-to-zero + overnight stop + env budget caps.
Guidelines

Best practices

  • Classify each workload's traffic shape; match pattern to shape (the cardinal rule).
  • Autoscale down, not just up — scale-to-zero for dev and worker queues.
  • Prefer serverless/spot where bursts are mandatory and state lives elsewhere.
  • Design egress-aware: keep compute near its data, cache at the edge, minimize cross-region sync.
  • Go cheaper from day one: an architecture review gate with a cost-per-unit projection.
Watch out

Common mistakes

  • Serverless-everything dogma: steady high OR low-latency loops often cheaper as committed compute.
  • Spot everywhere ignoring resilience: critical stateful services don't belong in reclaimable capacity.
  • Forgetting egress in the topology: drawing compute far from data invents a transfer bill.
  • Autoscaling to zero without a warm-up plan → thrash and 5xx at load time.
When things break

Debugging tips

  • Cost spike on a 'cheap' pipeline → the component with serverless-per-poll or no lifecycle; find the shape mismatch.
  • 'Serverless' DB bill big → reads hot-loop or cold tier missing; add tiering/cache first.
  • Spot evictions hitting critical path → move that workload off spot or add warm spare (~the resilience/cost tradeoff).
  • Egress creeping up → check CDN fill/cross-region replication; cache + locality fixes.
Interviews

Interview checkpoint

Test yourself

Quick quiz

0/2
1

The right match for a steady 24×7 hot-path API:

2

The architectural decision that most shapes the bill:

Go deeper

Official documentation