September 25, 202410 minute read
Google Cloud Run functions pricing: understanding costs and optimization
author
Yiren Lu@YirenLu
Solutions Engineer

Google Cloud Run functions offer a flexible and cost-effective serverless solution for running your code in the cloud. This guide breaks down the pricing model for both first and second generation functions, helping you understand and optimize your costs.

First gen vs. second gen functions

Google Cloud Run functions come in two generations, each with its own pricing structure:

  1. First gen functions: The original offering, priced based on invocations, compute time, and networking.
  2. Second gen functions: Built on Cloud Run, offering more flexibility and features, with pricing based on vCPU, memory, and request count.

While Google recommends using second gen functions for new projects, both generations remain viable options. For a detailed comparison, see the Cloud Functions version comparison documentation.

First gen functions pricing

First gen functions are priced based on the following components:

  1. Compute Time: $0.0000100 per GHz-second
  2. Memory: $0.0000025 per GB-second
  3. Invocations: $0.40 per million
  4. Networking: $0.12 per GB of Internet data transfer out

The cost of the individual components are added together to get the total cost.

Google Cloud offers a generous free tier for first gen functions. For details on the free tier limits, refer to the official free tier documentation.

For more details, refer to the official first gen pricing documentation.

Understanding GHz-seconds and GB-seconds

For first gen functions, compute time is measured in GHz-seconds, while memory usage is measured in GB-seconds.

  • GHz-seconds: The product of the CPU clock speed (in GHz) and the execution time (in seconds).
  • GB-seconds: The product of the allocated memory (in GB) and the execution time (in seconds).

Examples:

  • A 2.0 GHz CPU used for 1 second = 2 GHz-seconds
  • A 2.4 GHz CPU used for 30 seconds = 72 GHz-seconds
  • 256 MB (0.25 GB) of memory used for 1 second = 0.25 GB-seconds
  • 1 GB of memory used for 30 seconds = 30 GB-seconds

Pricing example

Let’s say your first gen function runs for 200ms on a 2.4 GHz CPU with 256 MB (0.25 GB) of allocated memory:

  1. Compute Time: (2.4 GHz x 0.2 seconds) x ($0.0000100 / GHz-second) = $0.0000048
  2. Memory: (0.25 GB x 0.2 seconds) x ($0.0000025 / GB-second) = $0.000000125
  3. If this is the 2,000,001st invocation of the month, you’d also pay $0.0000004 for the invocation

Second gen functions pricing

Second gen functions are priced based on:

  1. vCPU usage: $0.00002400 per vCPU-second
  2. Memory usage: $0.0000025 per GB-second
  3. Invocations: $0.40 per million
  4. Networking: $0.12 per GB

Free tier

Google Cloud offers a generous free tier for second gen functions. For details on the free tier limits, refer to the official free tier documentation.

For more details, refer to the official second gen pricing documentation.

Resource allocation

With second gen functions, you can specify both CPU and memory:

  • vCPU: Choose from 0.08 to 8 vCPUs
  • Memory: Allocate from 128MB to 32GB

This granular control allows you to optimize performance and cost for your specific workloads.

Understanding vCPU-seconds

vCPU-second:

A vCPU (virtual CPU) is a unit of computing power in cloud environments. In Google Cloud Run functions, a vCPU typically represents a hardware hyper-thread, which is approximately equivalent to half of a physical CPU core. This means that 2 vCPUs would roughly correspond to one full physical CPU core. The exact performance can vary depending on the underlying hardware and workload characteristics. vCPUs allow for flexible resource allocation and can be easily scaled up or down based on workload requirements, with Cloud Run functions offering options from 0.08 to 8 vCPUs per instance.

A vCPU-second measures the amount of virtual CPU time consumed by your function. It’s calculated by multiplying the number of vCPUs allocated to your function by the execution time.

Examples:

  • 1 vCPU used for 1 second = 1 vCPU-second
  • 2 vCPUs used for 30 seconds = 60 vCPU-seconds

Pricing example

Let’s say your second gen function uses 1 vCPU and 2 GB of memory, and runs for 500ms:

  1. vCPU cost: 1 vCPU x 0.5 seconds x $0.00002400 per vCPU-second = $0.000012
  2. Memory cost: 2 GB x 0.5 seconds x $0.0000025 per GB-second = $0.0000025
  3. Invocation cost: $0.40 / 1,000,000 = $0.0000004

Total cost for this execution: $0.0000149

Note: Prices may vary by region. Always check the official Google Cloud pricing page for the most up-to-date information.

Ship your first app in minutes.

Get Started

$30 / month free compute