Carbon Aware Cloud
Tags: cloud, devops, terraform, carbonfootprint
Published: 2023-03-07 13:33:48

Microsoft recently [announced](https://news.xbox.com/en-us/2023/01/11/xbox-carbon-aware-console-sustainability/) that Xbox will now be "Carbon Aware". It will download updates during periods of low carbon intensity on the power grid. 

Can we imagine doing the same for a cloud infrastructure? Can we imagine a carbon aware cloud? Public cloud providers are constantly improving their environmental impact by, for example, saving water or building solar plants. However, the virtual machines we spin up or the computing tasks we trigger are completely up to us. And there is room for improvement.

## What is the problem with data centres?

According to the [International Energy Agency](https://www.iea.org/reports/data-centres-and-data-transmission-networks), data centres consume between 220 and 320 terawatt-hours (TWh) of electricity, which is around one percent of the world's electricity demand in 2021. Data centres account for around 0.3% of all global CO2 emissions. While this number may seem small, it can be compared to the total emissions of countries like [France, UK or Australia](https://www.climatewatchdata.org/ghg-emissions?breakBy=countries&chartType=line&end_year=2019&gases=co2&regions=AUS%2CFRA%2CGBR%2CDEU&sectors=total-including-lucf&start_year=1990)!

Projections published by [Nature](https://www.nature.com/articles/d41586-018-06610-y) suggest that the electricity demand of Information and Communications Technology (ICT) will jump to 20% of global electricity. To put this in perspective, ICT currently has the same carbon footprint as the aviation industry, and data centres account for 20% of it according to the [Shift Project](https://theshiftproject.org/en/article/lean-ict-our-new-report/). This share is only expected to grow!

![Energy Forcast of ICT - Nature](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2fvt58n9m0u4zk5hq7kh.png)

_Energy Forcast of ICT - [Nature](https://www.nature.com/articles/d41586-018-06610-y)_

![Distribution of energy consumption per source for production and use of digital services in 2017 - the Shift Project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qmko1r0zbvfvkw0pdzyd.png)

## First, measure your cloud carbon footprint

There are tools available to analyse the carbon footprint of your cloud infrastructure. Major public cloud providers have released tools for this purpose:

- AWS [Carbon Footprint Tool](https://aws.amazon.com/aws-cost-management/aws-customer-carbon-footprint-tool/)
- Google Cloud [Carbon Footprint](https://cloud.google.com/carbon-footprint)
- Microsoft Azure [Sustainability Calculator](https://azure.microsoft.com/en-gb/blog/microsoft-sustainability-calculator-helps-enterprises-analyze-the-carbon-emissions-of-their-it-infrastructure/)

Various open-source initiatives, like [Cloud Carbon Footprint](https://www.cloudcarbonfootprint.org/docs/methodology/#appendix-iii-gpus-and-minmax-watts), can analyse your cloud provider bill, get resource usage, and estimate carbon emissions.

Other tools, like [Scaphandre](https://hubblo-org.github.io/scaphandre-documentation/index.html), rely on monitoring agents to measure the electric consumption of your machines.

There are many methodologies to estimate power consumption of your cloud resources. Basically, if you know the underlying models of the CPU, memory, disk, or GPU, you need to multiply it by their usage percent over time, and you will have the power consumption in kilowatt-hours (kWh).

Having the power consumption is the most difficult part. Once you have it, there are various methods to estimate CO2 emissions from it.

![SCI Formula - Green Software Foundation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uhls3lbecnviu1g3rw3i.png)

The key part is multiplying your power consumption (E) by the carbon intensity of the electricity consumed (I).

But, what’s the carbon intensity of the electricity ? Cloud provider might provide some net value, taking in account their effort to offset carbon (basically net zero according to [Google](https://cloud.google.com/sustainability/region-carbon)), but realistically electricity used by data center comes from the regional grid. So, depending on where the data center is located, electricity can be more or less “clean”:

![Carbon Intensity of electricity, 2022, OurWorldData.org](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i0qrhh4pb2tbwq18mnph.png)

We can even get a real time value from projects like [Electricity Maps](https://app.electricitymaps.com/map)

![Real time [Electricity Maps](https://app.electricitymaps.com/map)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m0crzba0j5mu4wges8qy.png)

## Then, reduce your cloud carbon footprint

Once you know how to measure your carbon footprint, it's time to take action! The first thing that comes to mind is making software more energy efficient. However, on the infrastructure level, there are choices that can be made.

### Move to an Hyperscaler provider

Moving to a [hyperscaler](https://www.gartner.com/en/newsroom/press-releases/2022-01-24-gartner-predicts-hyperscalers-carbon-emissions-will-drive-cloud-purchase-decsions-by-2025) cloud provider can have a significant impact. Public cloud providers, such as AWS, GCP, and Azure, are constantly working to lower energy bills by improving water cooling, among other things.

### Choose your region wisely

According to [Google](https://cloud.google.com/sustainability/region-carbon), hosting in Paris can result in a carbon footprint as low as 59 gCO2eq/kWh, while in Frankfurt it can jump to 269. By choosing a "greener" region in the same neighbourhood, the impact on carbon footprint can be massive!

![Moving server - Green Software Foundation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wz6ptyb3hncn5t28wpr2.png)

### Follow the sun

Carbon intensity varies a lot during the day because of renewable energy which depends on weather conditions. During a windless night, carbon intensity is worse than during a windy and sunny day!

![Carbon intensity over time - Green Software Foundation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/42k4u9mnhblqljkfqx52.png)

Scheduling a heavy task, like machine learning, where it’s daylight can be a powerful way to reduce the carbon footprint of asynchronous tasks.

### Leverage Infrastructure as Code (IaC)

Infrastructure as Code (IaC) tools like [Terraform](https://www.terraform.io/) enable infrastructure automation. Your infrastructure is described in a machine-readable file, which can be analysed and generated (templates, variables). Changing the region of an infrastructure could be as simple as changing the value of a variable.

By reading these Terraform files, tools like [Carbonifer](https://github.com/carboniferio/carbonifer) can compute the size and number of virtual machines in your infrastructure and estimate the carbon footprint in gCO2eq/h.

Integrating such a tool with your Continuous Integration (CI) could raise alerts when you reach a threshold of CO2 emission estimation for any planned changes to your infrastructure (thanks to GitOps).

![[Carbonifer](https://carbonifer.io/) screenshots](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r18ynzrzb5d4gal5h8mp.png)

### Accept loss of quality

There is virtually no limit to the performance of your software, regardless of the cost in money. Having more and bigger machines can ensure customer satisfaction with features like Ultra HD streaming and instant responsiveness. However, during a dark, cold winter when electricity relies on fossil fuels, it may not make sense to prioritise these features. Cloud companies could reduce their quality of service slightly to remain within their climate commitments. Tools could be developed to resize "autoscaling groups” when the carbon intensity of the cloud is high.

## Carbon Aware Cloud

Although there is not yet a fully integrated solution for a carbon-aware cloud, various tools, automations and methodologies can help in the following ways:

- **Estimate** the CO2 emissions of a deployment
- **Analyse** the Carbon Footprint of an existing infrastructure
- actively **pilot** your infrastructure according to the carbon intensity of the grid

By changing the hosting region, selecting a better time of day, or accepting a lower quality and automating these actions, there are ways to reduce our cloud carbon footprint.