Serverless Costs Demystified: AWS Lambda vs. GCP Cloud Run

Serverless Costs Demystified: AWS Lambda vs. GCP Cloud Run

Serverless computing has revolutionised how we develop and deploy applications, offering a cost-effective, scalable, and hassle-free alternative to traditional server-based architectures. Among the top contenders in the serverless space are AWS Lambda and GCP Cloud Run, each with its unique pricing models and use cases.

While these platforms promise to charge only for what you use, costs can scale dramatically as workloads grow in complexity. In this blog, we’ll explore the pricing structures of AWS Lambda and GCP Cloud Run, walking through examples to highlight cost drivers and optimisation strategies.

How AWS Lambda Pricing Works

AWS Lambda charges based on two main factors:


How GCP Cloud Run Pricing Works

GCP Cloud Run, on the other hand, charges based on:


Example 1: Small API Use Case

Let’s start with a simple API that receives 1 million requests per month. Each request takes 100 ms to process.

AWS Lambda Costs

  • Memory Allocation: 512 MB
  • Region: US East (N. Virginia)


GCP Cloud Run Costs

  • Resources: 1 vCPU and 256 MB (0.25 GB) memory
  • Region: US Central


Example 2: A Scaled Data Pipeline

Now, consider a data pipeline with 5 processing steps. Each step runs for 10 seconds and requires 2 GB of memory (or 4 GB for Cloud Run) per function/container. Assume 1 million pipelines per month (5M invocations).

AWS Lambda Costs


GCP Cloud Run Costs


Key Differences

Optimisation Strategies:

For AWS Lambda:

  • Tune Memory Allocation: Use AWS Lambda Power Tuning to find the right balance of memory and execution time.
  • Batch Processing: Group smaller tasks into fewer invocations.
  • Minimize Chaining: Use event-driven architectures like Amazon SQS or SNS to reduce direct function chaining.

For GCP Cloud Run:

  • Increase Concurrency: Allow multiple requests per container to improve efficiency.
  • Right-Size Resources: Carefully allocate memory and vCPUs to balance cost and performance.
  • Batch Workloads: Process jobs in batches to reduce invocation counts.


Conclusion

AWS Lambda and GCP Cloud Run offer distinct approaches to serverless computing. AWS Lambda excels in lightweight, event-driven use cases, while GCP Cloud Run’s flexibility and concurrency model make it ideal for containerized, compute-heavy workloads.

As workloads scale, costs can rise significantly for both platforms. By understanding their pricing models and applying optimization strategies, you can build cost-efficient, scalable serverless applications tailored to your needs.

Choose wisely, and may your serverless adventures be both cost-effective and scalable!

Vikrant Banwal

Building CARS24 | Ex-PropertyGuru | Ex-Daffodil | Tech Lead | Senior Dev | MERN DEV | React | Node | Next | Mongo | GatsBy | Ejs | NeXtJS | MS SQL | JavaScript | Typescript | Elastic Search | Tailwind | NestJs | n8n

1mo

Highly Informative

Like
Reply

To view or add a comment, sign in

More articles by Prabhat Pankaj

Insights from the community

Others also viewed

Explore topics