Green Coding: Can Software Engineers Help Solve Climate Change?

Annie Freeman
6 min readNov 29, 2021

Over the past few years, we have been seeing an increasing number of extreme weather events. This is a result of rising global temperatures. Despite a lot of discourse around how to solve climate change, sometimes I feel a bit helpless — I spend most of my time writing code for accounting software!

While the companies we work for solve important problems for some of us, climate change is a problem for all of us.

In his book ‘How to Avoid a Climate Disaster’, Bill Gates advocates that “we need to transform everything we do” in order to avoid the effects of climate change.¹

Therefore, that includes us!

Some common action for companies to take to contribute to sustainability are offsetting carbon emissions by investing in green projects or promoting carbon-free forms of transport to work

But if we need to transform everything we do, then that means we need to transform how we do our actual day-to-day work. How do we do that?

We embrace the idea of green coding.

If you’ve heard of green coding before, you might think, “Isn’t that just writing clean, efficient code? Shouldn’t we do that anyway?” And yes, it is! But I believe we can go deeper than that and look at how green coding practices can influence decision making in tech companies to help them build greener software.

This blog will look at four ways green coding could affect our decision making process:

  1. Code size
  2. Impact on eWaste
  3. Third-party software
  4. Monitoring

Code Size

More data being sent over the Internet means more electricity is consumed. By 2040, the information and technology sector is expected to account for 14% of the world’s carbon emissions if the current trend continues.²

This is a significant amount. As a result, people are starting to look at the size of the code being sent over the Internet as a way to decrease carbon emissions.

Someone named Danny van Kooten owns a Wordpress plugin. It is used on over two million different websites. One day, he decided to refactor the plugin code. By removing a Javascript dependency, the plugin now sends 20kB less data every time it is loaded. This doesn’t seem like much, but he did some rough calculations and worked out that this change reduced global carbon emissions by approximately 59,000 kgs of CO2 per month! That’s equivalent to 85 flights from Amsterdam to New York.

You can read about how he calculated this number here: CO2 emissions on the web

In summary:

  • He used an average energy expenditure of 0.5kWh per GB of data transfer.
  • Assumed that each of the 2 million websites using his plugin received 10,000 visitors per month
  • Took the total energy output and multiplied by the amount of CO2 produced per kWh on the European electricity grid in February 2020.

Could you do this at your company?

What is bloating your code that you don’t need or your users don’t need? Are you installing large packages and then only using a small part of the package?

However, spending time refining old code doesn’t always happen.

As many growing companies discover, there is a fine balancing act between building new features and maintaining security and reliability. Often, feature generation can win out in an effort to build the customer base.

However, what would happen if you added environmental impact as a factor to consider when deciding whether to build a new feature or address technical debt? Would that affect your team’s decision?

Impact on eWaste

New Zealanders produce on average 20kgs of eWaste every year. We recycle less than 2% of this.³

As producers of software, we’re technically not the ones manufacturing the hardware that contributes to this waste. However, often the reason for someone upgrading their laptop or phone is because newer versions of software work quicker and more effectively on newer hardware. Your application might load quickly on a new computer with lots of memory, but how much longer does it take to load on devices a few years older?

As someone experiences problems more and more, they decide to buy a new device. Their old device still worked, but it couldn’t handle the newer versions of software they were trying to use on it.

Web page size is one factor that has significantly increased over the past decade. In 2010, the average web page on desktop was just under 500kB. Now, it’s 2200kB — a 370% increase.

(Source: Http Archive, HTTP Archive: Page Weight)

You might be optimising your software to run on the latest hardware, but this is inadvertently contributing to the eWaste problem.

Instead, you could test and optimise your applications to run on devices 3–4 years old, helping lengthen the lifespan of phones and computers. Spending time innovating how you do this also leads to more efficient software.

Third-Party Software

Running your software likely involves a lot of third-party applications, both for internal use and for supplementing the product.

You could include environmental impact as a factor when deciding which third-party application to use.

In addition to considering the relative costs, features and reliability of an application, you could also consider the third-party company’s commitment to green coding and offsetting their own carbon emissions.

Monitoring

How do you actually measure all of this?

One way is to include energy consumption in your monitoring metrics. If a new feature released or a change to some code has higher electricity consumption than expected, you can investigate this. As you learn more, you could establish standards of practice about what an average piece of software should be using.

A blog from Microsoft shares one way you can do this using a formula to get an approximate electricity consumption amount. It uses the Thermal Design Power number (usually used for determining what cooling a unit needs), CPU, memory consumption and GPU, as well as the PUW, or Power Usage Effectiveness ratio, of your data centre. Read more about it here: How to measure the power consumption of your backend service

Investing time into this space means you can also innovate to create better monitoring metrics for your greener code.

The Green Software Foundation

Green coding is starting to gain more momentum in the industry. The Green Software Foundation was founded in May 2021 by Microsoft, Github, Accenture, Thoughtworks and the Linux Foundation. Their aim is to “build a trusted ecosystem of people, standards, tooling and leading practices for building green software.”

Opportunity for your company

When we consider the size of our code, our impact on eWaste, how to choose third-party software, and how we monitor our progress, I believe we all have the opportunity to be leaders in this area.

We can all take ownership of establishing industry standards and accelerating innovation.

As more companies adopt these practices, we can all encourage others to do so, as well as influence government regulation around climate change mitigation.

Let’s turn our code green!

¹ My new climate book is finally here

² Belkhir, L., Emeligi, A., Assessing ICT global emissions footprint: Trends to 2040 & recommendations

³ Why can’t clean green NZ recycle its e-waste?

--

--

Annie Freeman

Software engineer with a law degree. Champion for green software.