Sustainable digital products – the carbon footprint of code
The internet so saturates our everyday lives that it’s understandable if we rarely stop to ask how much energy the technology uses – and if there are ways to ensure it uses less of it.
The digital world still feels a bit like science fiction for most people and science fiction is full of utopian ideas that seem impossible. A common sci-fi trope that is firmly set as one of the driving philosophies of the internet is the dream of building a “post-scarcity” world.
This is a world in which all goods are reproduced perfectly with no extra labor, pollution or waste. A person may write the code, but it can be replicated infinitely at almost zero cost. It’s an admirable ideal but try as they might humans still haven’t figured out a way to overcome basic economic constraints like trade-offs.
If we’re being realistic, software on its own doesn’t consume any energy or emit harmful emissions. But each line of code takes a jolt of electricity when it runs. That energy must come from somewhere. Simply put, there is no such thing as a free lunch – even online.
Every click costs
The normal operation of cryptocurrencies provides perhaps the best example of what economists call “externalities” in the digital world. The people who run a computer to solve the complex mathematics to unlock a new piece of Bitcoin may think their activities are costless. But all the electricity is likely coming from a power plant just over the hill that is burning fossil fuels.
Indeed, the energy used by cryptocurrencies can generate enormous externalities. According to researchers at the University of Cambridge, the electricity needed to maintain the Bitcoin network alone (150 terawatt hours) is more than the entire nation of Argentina.
It’s not much better across the wider information and communication (ICT) sector.
In 2011, Barath Raghavan and Justin Ma of ICSI and University of California, Berkeley calculated that all the power needed to build and maintain computers, network connections, cell-phone towers and other hardware uses about 84 to 143 gigawatts of electricity every year, or about 7% of global energy. By 2040, the sector is expected to account for 14% of the world’s carbon footprint.
So far, most of the pressure to improve sustainability has been firmly on datacenter providers. Google wants to run its entire datacenter estate on carbon-free energy by 2030, while Amazon Web Services (AWS) is aiming to power its operations with 100% renewable energy by 2025.
However, there is still a lot of room for software engineers to be “cleaner” as well.
Most software engineers are at least peripherally aware of the externalities of what they do and understand the need to develop clean code.
Sustainable code is lightweight code, which is simply faster. Our website for Institute of Project Management loads in just 1.2 seconds (First Contentful Paint).
What is clean computing?
Clean computing is a way of writing code that primarily considers the energy output of computer functions and tries to diminish the demand the software puts on physical servers and systems, since this is where the internet uses most of its energy.
Clean code can be split into two types – structural and behavioral. Structural refers to how the code is written while the behavioral aspects of code describe how people use their computers to send emails or watch videos of cats, all of which consume energy.
A more efficient codebase can help large companies meet their ESG targets, an increasingly important performance metric for both stakeholders and younger software engineers who tend to weigh a company’s sustainability when looking for a job.
On a more practical level, clean code can also help increase the battery life for mobile devices, maximize computing power, lower energy consumption and combine computing resources for greater efficiency.
Code can be crisp and tight or pompous and bombastic, it all depends on the styles of the individual coder. So, the best place to start building clean code is for the software engineer to improve their writing ability.
While it might not seem to be a big problem at first, bloated code results in the computer using more energy overall because the code contains a larger-than-necessary number of useless functions and lines. Inevitably, any computer system running bloated code wastes more energy on processing than it needs to. Not good for carbon emissions.
Yet the existence of bloated code can’t be strictly lumped on the coders themselves. After all, when computing chips were less advanced code by necessity had to be tighter and shorter. There just wasn’t enough memory. As computers got more powerful, the available memory expanded as well, and now there’s fewer reasons for coders to write efficiently.
And since bloated code indicates wasted resources, a company can ensure a higher-quality product that is more fit for purpose if they encourage developers to writer cleaner code. The trick is in convincing software engineers that writing more sustainably is worth the extra effort. Right now, they don’t seem to be so sure about that.
According to a paper prepared for the 38th International Conference on Software Engineering found that where green coding matters the most, its practice is worryingly rare. The paper’s researchers (from IBM, Google, Microsoft and the University of Delaware) asked if software engineers think about energy usage when they write software.
The researchers found mobile developers used green practices more than any other group (53% said they "almost always" or "often" wrote applications with energy usage requirements). However, for embedded and data center developers, a whopping 75% and 86% of respondents “rarely” or “never” thought about energy usage requirements, respectively.
One interviewee explained why they rarely considered the energy usage of their software:
“Our main concern is market share and that means user experience is a priority. We can be more efficient to try to cut costs, but since we don't charge by energy used this doesn't make us more attractive to users. We tend to focus on other things like performance or reliability.”
In other words, while coders say they are interested in writing cleaner code – and are often happy to use tools to boost the efficiencies (which are easily available) – their reflex to blame business processes, rather than put in extra effort to write clean code, is revealed as little more than an excuse for their own laziness. In this regard, they are not dissimilar to people working in any other sector hoping to improve their sustainability.
The lesson of this research for software and ICT companies is that before their developers can trim their digital fat, they must be properly incentivized to do so. It must become easier for them to write clean code than it is for them to be lazy.
Sustainable code will be a fitting feature of a website for a sustainability-related company. We worked with air quality monitoring company Kaiterra to create this lightweight website.
So, how might software engineers keep their code eco-friendly?
In an op-ed for the Harvard Business Review, researchers at global consulting company Accenture said encouraging cleaner code is a three-part process that begins by outlining a strategy and boundaries, which then targets the software development life cycle while encouraging the cloud to go green as well.
The boundaries are important, said the researchers, because there is always a trade-off between sustainability and business goals. By focusing on sustainability too much, the company risks dropping its profit margin to zero – or generating a loss. That’s never a good thing for any business. So, the researchers said it is important to put clear boundaries on how far to go with sustainability practices.
The researchers added that setting reasonable but clear metrics to measure progress is critical for improving the sustainability of code. As the great businessman Peter Drucker once said, if it can’t be measured, then it can’t be managed. And with the trillions of possible data points generated every day online, the digital world is eminently measurable. There really is no excuse for poor metrics.
As already mentioned, since clean code can be split into two types – structural and behavioral – writing cleaner code should always keep the user experience in mind. After all, the more intuitive a website or application is, the less time an average user must spend searching for the right information or operating the hardware. And less time means more energy saved.
Another low-hanging fruit is to optimize all websites, software, apps and tools for the specific devices that will be using them. Doing so will avoid the need for the developers to send unnecessary files to the device and to ensure the right amount of processing power is used by the intended devices to run the software.
Finally, by deploying clean code, software engineers can help expose new business opportunities for a company, enhance the business’ competitive advantage and contribute to a more sustainable world. It’s amazing what a little more effort can achieve.