Photo by Zbynek Burival on Unsplash

Calculating the carbon cost of code

Gemma

--

An increasing ask from executives and investors is reporting on the carbon impact of software engineering.

Given growth of machine learning the significant emissions profiles of much AI, it will be an increasing focus for organisations as they look to reduce their operational spend and improve their emissions profiles.

In Europe GHG reporting more broadly is now a compliance demand.

The Corporate Sustainability Reporting Directive (CSRD) came into effect in January 2023 it requires EU businesses to disclose their environmental and social impact of their ESG initiatives on their business finances. Whilst this is not binding outside of the EU for businesses with EU based operations this may be something they need to consider.

ESG reporting under this directive is now obligatory and a whole raft of vendor based ESG reporting solutions have come onto the market to capitalise on this. The irony of this may be that we have increased our carbon footprint overall by demanding this reporting whilst not enforcing climate commitments with the companies reporting on it.. anyway I digress..

I have outlined here a list of resources and my own observations for any exec to consider.

Asking difficult questions is the start to finding real answers and you can start today.

CSRD reporting requirements

There are several categories for emissions reporting Scope 1 & 2 are obligatory however Scope 3 is not… and very hard to quantify in many cases anyway.

Scope 1 emissions

Scope 1 greenhouse gas emissions are emissions which come directly from a business and any controlled entities or inventory.

  1. Stationary combustion — for example fuels and heating sources which produce GHG.
  2. Mobile combustion — for example logistics and vehicles.
  3. Fugitive emissions — covers GHG leaks from sources such as refrigeration and air conditioning units.
  4. Process emissions — GHG from industrial processes and onsite manufacturing.

Electrifying your fleet of logistics is a good example of improving carbon metrics here.

Scope 2 emissions

Scope 2 is GHG which comes indirectly from purchased energy from a utility provider. For many companies, electricity consumption is their one and only source of Scope 2 emissions.

Scope 3 emissions

These are all indirect emissions — not included in scope 2 — that occur in the value chain and operations of the business. There are a staggering 15 categories for scope 3.

Examples of this can be cutting back on business travel, encouraging employees to work from home, using climate-friendly transport across the business etc.

Which part of the scope emissions does my software and hardware fit into?

An extract from the Linux Foundations Green Software training course below:

“For cloud applications running on servers that you own, the energy usage of your software falls into scope 2, and the embodied carbon of all your servers falls into scope 3.

  • For cloud applications running on a public cloud, both the energy usage of your application and the embodied carbon fall into scope 3.
  • In scenarios where you are running a hybrid private/public cloud application, part of its emissions will fall into scope 2 and part will fall into scope 3.
  • Similarly, for your customer-facing front-end application, energy usage falls into your organization’s scope 3, since your customer will purchase the energy to power their device.”

How to approach this

A number of execs have a reductionist approach to reporting metrics on this preferring a carbon credit scoring per line of code and compute time or using proxy measures for cost. This ignores many other factors and makes an easy get out which is buying carbon credits (most carbon credit and trading schemes are misleading) or simply reporting it with a standard corporate ethics statement.

https://www.theguardian.com/environment/article/2024/may/31/market-value-of-carbon-offsets-drops-61-aoe

To really consider this wholeistically I believe there are a number of layers which should be considered. Which are most relevant will depend on the context of your organisation or business.

Let’s start with some research-driven background reading.

Data Centres

Data centres have the same climate impact as the aviation industry, a sobering thought.

Research by Anthropologist Steven Gonzalez Monserrate is featured in the MIT series published here:

A full report summarising his research can be read here:

For Machine Learning of which most of the carbon footprint is Data Centre’s

The UN and Greenpeace have some very useful resources on their sites:

The latest from the UN or Greenpeace just run a Google Search for relevant articles however Steven Gonzalez Monserrate’s research summary above has a good list at the end of the document.

You can read the UN yearly published emissions gap report here:

https://www.unep.org/resources/emissions-gap-report-2023

On-site Data Centre

If you run your own onsite Data Centre it would be well worth considering the metrics of your carbon emissions. Not all Cloud Data centres are equal and some have a far bigger carbon footprint than others. Some notes on calculation parameters from the Hyperledger Carbon Calculation Project here:

It is worth noting that most server racks that have heavy use of Machine Learning workloads and Crypto will be dependent on water cooling even on on a very small scale (think home server set up). Indeed anything that causes the machine to run hot. Fan-driven air cooling per unit becomes inefficient at scale and is very noisy. In most water-cooled environments the water evaporates, also server uptime demands often leave Data Centre engineers to flood cooling units to reduce the risk of overheating thus adding to the overall carbon footprint.

Many naive engineering execs have talked about setting up their own on-site data centres to save cost and control emissions metrics. Hardware is a sought-after skill and keeping servers running 24/7 is demanding on energy, space and staff. There is also the significant latency to consider when serving international customers hence many data centres are located to reduce that and be located as close to the highest demand levels as is practically possible. Again this is very contextual but there is a real lack of knowledge on the market and a lot of rhetoric.

Hardware

I have barely mentioned hardware in this list of resources but this is not insignificant as a consideration. If you have many staff with devices (phones, laptops, TV screens) or a business whose operations depend on a lot of hardware the replacement rate and its GHG score in manufacture are important.

I noticed Oxford University have a write-up on their approach to these calculations and efforts to reduce emissions which will be relevant to a lot of businesses and organisations.

https://www.it.ox.ac.uk/article/environment-and-it

Cloud Providers and Carbon Calcs

Cloud platform providers all now have emissions calculators of varying accuracy. However, you need to spend with their service to be able to view historic reporting insights.

AWS carbon footprint tool:

G-Cloud

https://cloud.google.com/carbon-footprint

Microsoft Azure

https://www.microsoft.com/en-us/sustainability/emissions-impact-dashboard

GSF Impact Framework

There are frameworks to create estimate’s of the GHG emissions from a software system’s design, but it is is a complex calculation and needs parameters from vendors like Climatiq to be really effective. You can read about the framework here:

https://if.greensoftware.foundation/?ref=websustainability.org

Code Benchmarking

For the individual programming code level benchmarking, you can use energy measurements and libraries which estimate runtime energy usage and emissions based on your hardware.

There are open source tooling and repo’s which you can exploit to view the impact of your code and give you immediate reporting back on some current estimates of your emissions. Again these are only estimates and there are many factors which might impact whether this is more or less accurate.

Some tools to consider:

As with all open source its maintained by contributors.

How to avoid GHG Emissions

Organisations which also offer training on how to avoid GHG emissions. However these are mostly best practise guidance and as with everything in this space its very contextual. Worthy of a read and consider the training course for current best practise however.

https://greensoftware.foundation/

Can you calculate GHG emissions from static analysis??

This is unlikely to be accurate as it’s so contextual. There are some vendors claiming to produce accurate GHG emission’s based on this, I would be sceptical of these services.

Using proxy measures for carbon calculations💰

Cost is often cited as a proxy measure for carbon emissions with cloud providers.

Measuring a real “carbon footprint” is almost impossible so you need to model and approximate.

However cost isn’t always a reliable indicator. The cost of cloud services doesn’t necessarily relate at all to the environmental impact of a service (such as its energy usage or the embodied “carbon” that it contributes to).

Cloud providers pricing may reflect other input demands such as the wild Rn’D spend or services where it’s possible to simply drive profits higher than others. Costs often reflect this.

GreenOps an emerging area

Estimating GHG emissions based on Cloud usage you can check out vendors like Green Pixie who automate this with Calcs based on cloud usage rather than spend.

However I would argue for many org’s its more cost efficient to build out reporting and monitoring yourself which will do what most vendor software offers but this is contextual of course.

Resources and organisations and training

Guidance for optimizing your software to be as “Green” as possible. Its not just about reducing your carbon footprint its also about being as efficient as possible something every business should realistically aspire to.

Anne Currie. Sarah Hzu and Sara Bergman have written a handy book which is useful for any software engineer or CTO, (Anne Currie also runs courses on Greening your software for the Green Software Foundation). You can buy a copy of the book on Amazon.

Training

Training is a good idea for increasing awareness and applying some best practise approaches. Some vendor led courses here:

Microsoft

Linux Foundation

https://training.linuxfoundation.org/training/green-software-for-practitioners-lfc131/

Vendor solutions

Vendors like Climateiq have API services which you can integrate for carbon calculation https://www.climatiq.io/

Other considerations — how to approach a green code transition

InfoQ Podcast from some years ago but still very relevant.

API services

If you’re looking for data driven metrics for your applications and services here is a list of APIs as a starter for ten.

U.K. The National Grid

The National Grid in the U.K. has a partnership with various institutions and NGO’s and has an API service which forecasts carbon intensity 96 hours ahead for each region in the U.K.

https://buff.ly/2FiGPgc

Electricity Maps

There is also Electricity Maps which has partnered with several of the big tech players to demonstrate real time carbon intensity of electricity.

https://buff.ly/3uP88J7

Green Software Foundation

To integrate carbon intensity monitoring into your solutions The Green Software Foundations SDK.

https://buff.ly/3ZqMdVa

Historical data for grids around the world.

--

--

Gemma

Business Developer, programmer, solution architect, runner, swimmer, a culture and tech nerd. Busy building new solutions in emerging technologies.