Google Cloud Functions Tutorial : Pricing

Romin Irani
Romin Irani’s Blog
4 min readApr 24, 2018

This is part of a Google Cloud Functions Tutorial Series. Check out the series for all the articles.

This post touches upon pricing in Google Cloud Functions. There is excellent documentation available with pricing examples and I strongly suggest to take a good look at that.

To reiterate, since Google Cloud Functions are part of the Serverless Computing option, you are not charged for resources if you are not using it. Given that the unit of code that we are executing over here is a function , the questions that should pop up in your mind could be one or more of the following:

  • What factors are used to calculate how much to charge you?
  • Is there a free tier that applies to Cloud Functions? How much is that? Is that used while calculating the final cost?

Cloud Functions pricing factors

You will be charged for the following resources that you use:

  • The number of invocations of your function. There could be millions of invocations of your function. Hence the pricing is rounded up per million invocations. The cost is $.4 per million invocations.
  • The Compute Time that your function uses. This is a combination of CPU and Memory usage that is used by your function to execute. The compute time is measured as the time that it takes for your function from receiving the request to completing its work, either by indicating that it is complete or via a timeout. This time is rounded to the nearest 100ms and is then computed in terms of number of GB/second and GHz/Second. There is a rate of $.0000025 per GB-Second and $.00001 per GHz-Second. A working example later on will make it clear.
  • The Network Egress of your functions. This is calculated at a flat rate per GB of data that comes out of your function. You are not charged for inbound data, outbound data to Google APIs in the same region and other global Google APIs.

A solid diagram is available as part of the documentation that highlights how your cost is calculated. It is reproduced below:

When you provision your function to run, you select from one of several CPU + Memory Configuration that is available to you. The table is given below:

In addition to the above, you also have a Free Tier that will kick in and will apply as deductions from your usage, as part of your bill. The details for Cloud Functions in the Always Free Tier is given below:

This is obviously very difficult to comprehend, but let’s work it out via an example. This example is given in the official documentation along with another example and I suggest that you go through the same too.

Let us consider the following scenario:

A background function with 256MB of memory and a 400MHz CPU, invoked 10 million times per month and running for 300ms each time using only Google APIs (no billable egress).

If we analyze the items that I have marked in bold, we will come to teh following conclusion:

  • Invocations per month= 10 million (10,000,000)
  • Memory consumed per invocation in GB-seconds = (256/1024) * 0.3s = 0.075 GB-seconds per invocation. Since total number of invocations per month are 10 million, the total memory consumed in GB-seconds is 0.075 * 10 million = 750,000 GB-seconds per month.
  • CPU consumed per invocation in GHz-seconds = (400/1000) * 0.3s = 0.12 GHz-seconds per invocation. Since total number of invocations per month are 10 million, the total CPU consumed in GHz-seconds is 0.12 * 10 million = 1,200,000 GHz-seconds per month.
  • There are no charges for Network egress i.e. $0.

We can now work out the following total cost:

Notice that in the above table:

  1. Net Value = Gross Value — Free Tier.
  2. Free Tier gives us 2 million calls per month free along with 400,000 GB-seconds of Memory and 200,000 GHz-seconds of CPU.
  3. The Unit Price as mentioned before is a flat rate of $.0000004 per call i.e. $.4 per million invocations. The Unit Price for GB-seconds and GHz-seconds is $.0000025 per GB-Second and $.00001 per GHz-Second.

The Cloud Function pricing is also available in the Cloud Platform Cost Calculator available over here.

Pricing is often best understood by keeping a track of your usage, looking at a few billing cycles and then determining if you need to tweak your functions around execution time, etc.

This is part of a Google Cloud Tutorial Series. Check out the series for all the articles.

--

--

Romin Irani
Romin Irani’s Blog

My passion is to help developers succeed. ¯\_(ツ)_/¯