Skip to main content

Cloud Cost Models: Pay-Per-Use

Why This Matters

Traditional servers cost money whether you use them or not. Serverless only charges when your code actually runs.


Simple Explanation

What it is

This lesson explains how cloud billing changes when you move from always-on servers to pay-per-use functions.

Why we need it

If you do not understand the cost model, it is easy to choose the wrong architecture and overpay.

Benefits

  • Clear cost intuition for bursty workloads.
  • Better planning using pricing calculators.
  • Smarter design choices that reduce idle spend.

Tradeoffs

  • Estimates can be tricky without real traffic data.
  • Costs can spike if functions run longer than expected.

Real-world examples (architecture only)

  • Low-traffic API → Functions cost less than a 24/7 VM.
  • Always-on batch job → Reserved capacity is often cheaper.

Traditional vs. Serverless Pricing

Traditional Servers

  • Pay for the entire server (EC2 instance)
  • Running 24/7, even if idle
  • Fixed monthly cost
  • You manage capacity planning

Serverless (Lambda)

  • Pay per invocation + compute time
  • No charge when idle
  • Scales automatically
  • You only pay for what you use

Example: When Serverless Saves Money

Scenario: A web API that handles low, bursty traffic.

Instead of pinning a server on 24/7, serverless charges only for execution time. Use the official pricing calculators to compare costs for your exact traffic pattern.

Key Metrics

  • Invocations: Number of times your function runs (see provider pricing)
  • Compute time: Measured in GB-seconds (time × memory allocated)
  • Free tier: Varies by provider (see AWS/GCP pricing pages)

How to Estimate Costs

  1. Estimate number of invocations per month
  2. Estimate average function duration
  3. Estimate memory required
  4. Use the AWS and GCP pricing calculators

Cost Optimization Tips

  • Reduce function execution time
  • Use the right memory size (more memory = faster execution, but costs more)
  • Clean up unused functions
  • Monitor CloudWatch logs for unusual patterns

Hands-On

Visit the pricing pages and calculate the cost of:

  • 1 million invocations × 100ms duration × 128MB memory
  • 10,000 daily invocations × 500ms × 256MB
  • 100 monthly invocations × 30s × 512MB

Notice how the costs scale differently based on usage patterns. This is why serverless is ideal for variable, unpredictable workloads.

Key Takeaway

Serverless pricing rewards efficiency. The less your code runs, the less you pay. This fundamentally changes how you design applications.


Project (Cloud-Agnostic)

Estimate the monthly cost of a serverless API under two traffic patterns: steady traffic vs bursty traffic.

Deliverables:

  1. State your assumptions (invocations, duration, memory).
  2. Use AWS and GCP pricing pages or calculators to estimate cost.
  3. Explain which workload favors serverless and why.

If you want feedback, email your write-up to maarifaarchitect@gmail.com.


References