Did you know that the internet produces more than 2.5% of global emissions or one billion tonnes of greenhouse gases a year ?
This amount is currently more than the aviation industry and is expected to triple in the next 10 years. The communication industry is estimated to be responsible for 14-20% of emissions by 2040.
As developers, we wanted to establish if there was anything we could do to help reduce this, besides switching our computers to be powered by renewable energy.
Well yes actually.
The code you write now will likely still be in use in 5-10 years’ time. The servers your code is running on are running 24 hours a day, 7 days a week. Your thousands of end users are using power to consume your content. The choices you make could make hundreds of times the difference of switching your development machine to run on renewables.
You can make a huge difference in the CO₂ produced by your site or application with the code you write now and the decisions you make in your development.
Let’s take a look at some of those choices by considering the following areas:
The code you write could be loaded thousands of times, on millions of devices. Downloading that content takes power. Running the code takes power.
Here are some ideas that could help reduce power use in data transfer and on the end users’ machines.
The code you write can almost always be optimized. This not only saves power usage, but hosting costs as well. Some small changes can have orders of magnitude changes in performance.
Here are some considerations to improving your back end code.
The servers you decide to host your application on has perhaps the biggest impact on your CO₂ footprint. After all, high end servers can draw up to 800w of power, and run 24 hours a day, 365 days a year.
With database server and backup servers, this can add up to tonnes of CO₂ produced, depending on where you source your server power from.
Here are some ideas to reduce your footprint.
It is often ignored but sending data over the internet takes power. Between your server and the client, data may pass through tens of routers and signal boosters, often travelling under oceans and across continents. By reducing the distance and amount of data that needs to travel, you reduce your overall footprint.
Here are some suggestions.
As the developer is making changes and improvements on a web project, it is all too easy to mess things up. There are ways of catching these mistakes: unit tests, code review, code analysis, end-to-end tests and more. However, we have not had a reliable, automated way of catching issues that cause bundle size and transferred bytes to shoot up.
As it happens, there is a solid way of measuring data transferred over the network when visiting a site. Fire up Chrome, hit F12 and take notice of the numbers on the network tab. A tad manual and time consuming to be of much use, but something we can work with. The data and more is however available via JavaScript Performance API. The support is not the best across the browsers, but for measuring and testing, it’s enough.
On a recent project, we’ve included series of Selenium tests calling the performance API, collecting the same resource load data available in the Chrome developer tools. From the tests the data is pushed to a storage account, from where we can get a point of reference for future builds and tests.
This is currently where we are at. The intended use for the data is to raise a warning and/or an error if the route load size increases too much on a subsequent build. Testing caching this way should also be possible. There is also no reason not to gather the data for all test cases: filling forms, navigating wizards and such. Shooting stray XHRs in a SPA is even easier than messing the bundling up.
Once included into a CI/CD pipeline, we’ve added another guard against developer error. In the future, we should be seeing red or yellow when things have been going left in performance and environmental sense
It has been fairly difficult in researching this post to determine how much CO₂ you could save, as it is so dependent on how busy your site is, where it is hosted, where your customers are located, what devices they use and what they actually do on your site. However, this post could be summed up in a few bullet points for you to consider as a developer.
These are some of the ideas we have come up with to reduce our CO₂ footprint now and in the future. Read more about Innofactor's sustainability.
Simon Barrow
Simon Barrow is a Senior Full Stack Developer at Innofactor with 18 years of commercial experience building ASP.NET based sites and applications in Australia, the UK and Finland. He likes to get outdoors, and is a big believer in protecting the planet and nature for future generations.
Janne Forsell
Janne is a Tech Lead at Innofactor. In addition, he is a games developer on his 3rd year into .NET / VueJS adventure.