How to calculate the carbon emission of your cloud services
Understanding and calculating the carbon footprint of your cloud services has never been simpler. This tutorial will walk you through using Climatiq API to assess emissions based on a variety of cloud computing factors.
Key Considerations in Cloud Carbon Emissions
Cloud computing power utilization depends on several factors:
- The CPU, Memory, and Storage demand of your services
- How well utilized the machines in the data centers are used.
- Efficiency in data centers regarding cooling and electricity usage, usually denoted as Power Usage Effectiveness (opens in a new tab) or PUE.
- Where the data centers are located to determine the electricity grid mix.
- The embodied emissions, meaning the emissions related to the manufacturing and disposal of the physical components.
With these factors in mind, let's explore different types of services and how Climatiq can help you calculating your emissions.
Carbon Emissions for Virtual Machines
Several services let you rent a Virtual Machine (VM) in the cloud, such as GCP's Compute Engine, Azure Virtual Machines, or AWS's EC2 instances. Other services might also be backed by a VM that you designate, like Azure's App Service or Kubernetes clusters.
For all instances where your workload runs on a specific VM, Climatiq provides a Virtual Machine Endpoint where you need to put in the region you're running, instance type, and optionally, the CPU load of the instance. This will automatically compute the electricity used for memory and CPU usage, and embodied emissions for the specified instance type.
Virtual Machines Example
Here is an example of renting a t2.nano
from AWS for 24 hours in the "us west 2" region. For more information about this endpoint, we refer to the API reference documentation.
Request
curl --request POST \ --url https://api.climatiq.io/compute/v1/aws/instance \ --header "Authorization: Bearer $CLIMATIQ_API_KEY" \ --data '{ "instance": "t2.nano", "region": "us_west_2", "duration": 24, "duration_unit": "h"}'
Response
{ "total_co2e": 0.03879, "total_co2e_unit": "kg", "memory_estimate": { "co2e": 0.001575, "co2e_unit": "kg", "co2e_calculation_method": "ar5", "co2e_calculation_origin": "source", "emission_factor": { "name": "Electricity supplied from grid", "activity_id": "electricity-supply_grid-source_supplier_mix", "id": "73cf8c76-3be9-4942-ac09-201cf572e3a1", "access_type": "public", "source": "EPA", "source_dataset": "eGRID", "year": 2022, "region": "US-NWPP", "category": "Electricity", "source_lca_activity": "electricity_generation", "data_quality_flags": [] }, "constituent_gases": { "co2e_total": 0.001575, "co2e_other": null, "co2": 0.001566, "ch4": 1.456e-7, "n2o": 2.08e-8 }, "activity_data": { "activity_value": 0.005733, "activity_unit": "kWh" }, "audit_trail": "enabled", "source_trail": [ { "data_category": "emission_factor", "name": "Electricity supplied from grid", "source": "EPA", "source_dataset": "eGRID", "year": "2022", "region": "US-NWPP", "region_name": "WECC Northwest, US" } ] }, "cpu_estimate": { "co2e": 0.01587, "co2e_unit": "kg", "co2e_calculation_method": "ar5", "co2e_calculation_origin": "source", "emission_factor": { "name": "Electricity supplied from grid", "activity_id": "electricity-supply_grid-source_supplier_mix", "id": "73cf8c76-3be9-4942-ac09-201cf572e3a1", "access_type": "public", "source": "EPA", "source_dataset": "eGRID", "year": 2022, "region": "US-NWPP", "category": "Electricity", "source_lca_activity": "electricity_generation", "data_quality_flags": [] }, "constituent_gases": { "co2e_total": 0.01587, "co2e_other": null, "co2": 0.01577, "ch4": 0.000001467, "n2o": 2.096e-7 }, "activity_data": { "activity_value": 0.05775, "activity_unit": "kWh" }, "audit_trail": "enabled", "source_trail": [ { "data_category": "emission_factor", "name": "Electricity supplied from grid", "source": "EPA", "source_dataset": "eGRID", "year": "2022", "region": "US-NWPP", "region_name": "WECC Northwest, US" } ] }, "embodied_cpu_estimate": { "co2e": 0.02135, "co2e_unit": "kg", "co2e_calculation_method": "ar4", "co2e_calculation_origin": "source", "emission_factor": { "name": "AWS - Embodied emissions - t2.nano - Xeon E5-2676 v3", "activity_id": "cpu-provider_aws-type_t2.nano_xeon_e5_2676_v3", "id": "7a8ff5fd-3361-427b-aedf-e47a5e49ea82", "access_type": "public", "source": "CCF", "source_dataset": "Derived from CCF models", "year": 2021, "region": "GLOBAL", "category": "Cloud Computing - CPU", "source_lca_activity": "upstream-end_of_life", "data_quality_flags": [ "notable_methodological_variance" ] }, "constituent_gases": { "co2e_total": 0.02135, "co2e_other": null, "co2": null, "ch4": null, "n2o": null }, "activity_data": { "activity_value": 24, "activity_unit": "instance-hour" }, "audit_trail": "enabled", "source_trail": [ { "data_category": "emission_factor", "name": "AWS - Embodied emissions - t2.nano - Xeon E5-2676 v3", "source": "CCF", "source_dataset": "Derived from CCF models", "year": "2021", "region": "GLOBAL", "region_name": "Global" } ] }, "calculation_details": { "instance": "t2.nano", "instance_memory": 0.536870912, "memory_unit": "GB", "vcpu_cores": 1, "average_vcpu_utilization": 0.5, "power_usage_effectiveness": 1.135, "energy_used_cpu": 0.0577488, "energy_used_memory": 0.00573275054800896, "energy_unit": "kWh" }}
When viewing or overriding electricity emission factors, a number of aspects need to be taken
into account including; what particular mix of energy is being provided by the source, whether
the factor includes upstream emissions and whether it includes transmission and distribution
losses. This information is encoded in the activity_id
and the source_lca_activity
fields
provided in API response. More information can be retrieved from the issuing source. Read more
about selecting electricity EFs here.
Carbon Emissions for Other Services
For many services, you aren't renting a complete VM, but instead, leasing some storage, memory, or CPU power. Even in these cases, Climatiq can assist you. Endpoints are available for estimating emissions based on storage reserved, memory available or virtual CPU power used
Depending on the service, obtaining these metrics might pose different levels of difficulty. This guide doesn't cover the specifics of retrieving these metrics, but a good starting point could be your cloud provider's monitoring systems or your billing/usage data. If you need further assistance, refer to this document (opens in a new tab), or your cloud provider's documentation.
Let's take a couple of examples of how we can use the Climatiq endpoints to measure based on this more granular input.
CPU Example: Serverless Functions
If you are running serverless functions, you are often able to retrieve the CPU usage from monitoring or billing. Let's consider an AWS Lambda function with the following specifications:
- Function runtime: 200ms
- CPU usage: 1 vCPU core
- Location: US West (Oregon) (see this link for a detailed guide of AWS regions (opens in a new tab))
The emissions from this function's CPU usage can be calculated using Climatiq's CPU endpoint like this.
Request
curl --request POST \ --url https://api.climatiq.io/compute/v1/aws/cpu \ --header "Authorization: Bearer $CLIMATIQ_API_KEY" \ --data '{ "cpu_count": 1, "region": "us_west_2", "duration": 200, "duration_unit": "ms"}'
Response
{ "co2e": 3.674e-8, "co2e_unit": "kg", "co2e_calculation_method": "ar5", "co2e_calculation_origin": "source", "emission_factor": { "name": "Electricity supplied from grid", "activity_id": "electricity-supply_grid-source_supplier_mix", "id": "73cf8c76-3be9-4942-ac09-201cf572e3a1", "access_type": "public", "source": "EPA", "source_dataset": "eGRID", "year": 2022, "region": "US-NWPP", "category": "Electricity", "source_lca_activity": "electricity_generation", "data_quality_flags": [] }, "constituent_gases": { "co2e_total": 3.674e-8, "co2e_other": null, "co2": 3.651e-8, "ch4": 3.396e-12, "n2o": 4.851e-13 }, "activity_data": { "activity_value": 1.337e-7, "activity_unit": "kWh" }, "audit_trail": "enabled", "source_trail": [ { "data_category": "emission_factor", "name": "Electricity supplied from grid", "source": "EPA", "source_dataset": "eGRID", "year": "2022", "region": "US-NWPP", "region_name": "WECC Northwest, US" } ]}
Memory Example: Serverless Functions
To account for the carbon emissions linked to memory (RAM) usage, one must consider both the allocated and the actually used memory.
Even if the full memory isn't used, it still consumes power. a good rule of thumb is to use the total amount of RAM you have allocated, not just the amount you use.
For our AWS Lambda function, consider the following specification:
- Function runtime: 200ms
- Memory allocated: 1792MB
The emissions from this function's memory usage can be calculated using Climatiq's Memory endpoint like this.
Request
curl --request POST \ --url https://api.climatiq.io/compute/v1/aws/memory \ --header "Authorization: Bearer $CLIMATIQ_API_KEY" \ --data '{ "region": "us_west_2", "data": 1792, "data_unit": "MB", "duration": 200, "duration_unit": "ms"}'
Response
{ "co2e": 1.217e-8, "co2e_unit": "kg", "co2e_calculation_method": "ar5", "co2e_calculation_origin": "source", "emission_factor": { "name": "Electricity supplied from grid", "activity_id": "electricity-supply_grid-source_supplier_mix", "id": "73cf8c76-3be9-4942-ac09-201cf572e3a1", "access_type": "public", "source": "EPA", "source_dataset": "eGRID", "year": 2022, "region": "US-NWPP", "category": "Electricity", "source_lca_activity": "electricity_generation", "data_quality_flags": [] }, "constituent_gases": { "co2e_total": 1.217e-8, "co2e_other": null, "co2": 1.21e-8, "ch4": 1.125e-12, "n2o": 1.607e-13 }, "activity_data": { "activity_value": 4.429e-8, "activity_unit": "kWh" }, "audit_trail": "enabled", "source_trail": [ { "data_category": "emission_factor", "name": "Electricity supplied from grid", "source": "EPA", "source_dataset": "eGRID", "year": "2022", "region": "US-NWPP", "region_name": "WECC Northwest, US" } ]}
Combining the CPU and memory usage for this serverless function will then give you a good idea of the use phase emissions.
Storage
Storage in cloud computing not only consumes power but also varies in terms of the backing hardware and replication strategies.
To calculate storage emissions, consider the following aspects:
- The type of hardware backing your storage: HDDs generally consume less power but are slower than SSDs.
- Calculate emissions based on storage purchased, not just used. Even if you're not using the storage, having it available will use electricity.
- Replication: storage is often duplicated across multiple machines or data centers. If your storage is replicated you should take your storage amount and multiply it by how many times it's replicated. You'll have to look at your cloud provider and the specific services you use to figure out how many times data is replicated. Here's a list of list of replication factors (opens in a new tab), which covers many services for all the major cloud providers.
Two examples are presented below, one considering SSD instance storage on EC2 and the other taking into account usage of S3 for file storage. Each case illustrates how these factors affect carbon emissions calculations.
Storage Example 1. An SSD EC2 Instance Storage
In this example, we mount a 20GB SSD instance storage on our EC2 instance, and we want to calculate the emissions over a week.
Looking at the AWS replication factors (opens in a new tab), the EC2 Instance Storage is not replicated. This means we only have estimate with the data we've purchased.
Request
curl --request POST \ --url https://api.climatiq.io/compute/v1/aws/storage \ --header "Authorization: Bearer $CLIMATIQ_API_KEY" \ --data '{ "region": "us_west_2", "data": 20, "data_unit": "GB", "storage_type": "ssd", "duration": 7, "duration_unit": "day"}'
Response
{ "co2e": 0.001258, "co2e_unit": "kg", "co2e_calculation_method": "ar5", "co2e_calculation_origin": "source", "emission_factor": { "name": "Electricity supplied from grid", "activity_id": "electricity-supply_grid-source_supplier_mix", "id": "73cf8c76-3be9-4942-ac09-201cf572e3a1", "access_type": "public", "source": "EPA", "source_dataset": "eGRID", "year": 2022, "region": "US-NWPP", "category": "Electricity", "source_lca_activity": "electricity_generation", "data_quality_flags": [] }, "constituent_gases": { "co2e_total": 0.001258, "co2e_other": null, "co2": 0.00125, "ch4": 1.162e-7, "n2o": 1.661e-8 }, "activity_data": { "activity_value": 0.004576, "activity_unit": "kWh" }, "audit_trail": "enabled", "source_trail": [ { "data_category": "emission_factor", "name": "Electricity supplied from grid", "source": "EPA", "source_dataset": "eGRID", "year": "2022", "region": "US-NWPP", "region_name": "WECC Northwest, US" } ]}
Storage Example 2: Using S3
Let's take a slightly harder example, where we try to calculate emissions based on the use of S3 to store files.
This is harder for several reasons:
- Hardware: Amazon has never published which sort of physical storage they use in S3, but it's generally safe to assume that cheaper HDDs are primarily used so we'll use the HDD emission factor.
- Pre-allocation: Unlike certain services, S3 doesn't require pre-allocation of storage. You pay for what you store. It's likely that you share hard-drives with other consumers so we only consider the amount of storage actually used.
- Replication: S3 data is replicated in 3 different locations, meaning we'll need to take the amount we've stored and multiply it by 3.
For instance, if we're storing 5GB in S3, we'd use the HDD emission factor and an amount of "15GB". The latter is because the data is replicated three times, effectively using 15GB of storage. The resulting CO2e emissions for storing this data for a week are calculated below.
Request
curl --request POST \ --url https://api.climatiq.io/compute/v1/aws/storage \ --header "Authorization: Bearer $CLIMATIQ_API_KEY" \ --data '{ "region": "us_west_2", "data": 15, "data_unit": "GB", "storage_type": "hdd", "duration": 7, "duration_unit": "day"}'
Response
{ "co2e": 0.0005109, "co2e_unit": "kg", "co2e_calculation_method": "ar5", "co2e_calculation_origin": "source", "emission_factor": { "name": "Electricity supplied from grid", "activity_id": "electricity-supply_grid-source_supplier_mix", "id": "73cf8c76-3be9-4942-ac09-201cf572e3a1", "access_type": "public", "source": "EPA", "source_dataset": "eGRID", "year": 2022, "region": "US-NWPP", "category": "Electricity", "source_lca_activity": "electricity_generation", "data_quality_flags": [] }, "constituent_gases": { "co2e_total": 0.0005109, "co2e_other": null, "co2": 0.0005077, "ch4": 4.722e-8, "n2o": 6.746e-9 }, "activity_data": { "activity_value": 0.001859, "activity_unit": "kWh" }, "audit_trail": "enabled", "source_trail": [ { "data_category": "emission_factor", "name": "Electricity supplied from grid", "source": "EPA", "source_dataset": "eGRID", "year": "2022", "region": "US-NWPP", "region_name": "WECC Northwest, US" } ]}
Climatiq relies on the Cloud Carbon Footprint (opens in a new tab) methodology for most of our assumptions such as the power-usage of memory and vCPU's. While the CCF methodology allows for specific power calculations based on the underlying hardware, Climatiq currently only uses an average watts per vCPU per provider, and not architecture specific power consumption data.
Summary
This guide provides a solid foundation on how to calculate the carbon emissions of your cloud computing usage. While Climatiq's emission factors are comprehensive for many aspects of cloud computing, it doesn't cover areas such as network traffic to the end-user, or network traffic between your servers.
For a more accurate and complex assessment, don't hesitate to get in touch (opens in a new tab). Together, we can make your cloud computing greener and more sustainable.