The green impact of serverless
start building beautiful and sustainable software applications

The green impact of serverless

[this article's contents have been presented at Serverless Days Milan, 4th June 2020]

Living in Milan, I have had to deal with extraordinary air pollution values pretty much all my life, but the situation somehow worsened around December 2019: in some days controversial graphs compared Milan to much more densely populated and polluted cities, at least by common perception, in China and India. The air was objectively unbreathable and I bought masks for the kids and air purifiers for our home.

Then came covid-19, and, obviously, our concerns moved elsewhere. Like everyone, at least in Lombardy, I was in lockdown from 21 February to 4 May. We even re-discovered our small balcony, since it was the only outdoor place of our Milan apartment. In the midst of a thousand worries, a little voice in the back of my head kept pointing out that, however, suddenly, the air was no longer polluted, the CO2 levels had dropped, which in short meant that an important change, and with impactful results, was, indeed, possible.

This triggers a difficult question: do I want to go back to the impossibly polluted air of January 2020? If the answer is no, then something needs to change, or at least, un-change.

First, let's see why this is due and important. The whole scientific community agrees that the world has a pollution problem. Carbon dioxide in our atmosphere has created a layer of gas that traps heat and irreversibly changes the earth's climate. Earth's temperature has risen by more than one degree centigrade since the industrial revolution of the 1700s.

If we don't stop this global warming process, scientists tell us that the results will be catastrophic, with further increases in temperature, extreme weather conditions, drought, fires (remember the Australian situation at the beginning of the year?). The rising of the waters could make areas where more than two hundred million people live, uninhabitable, and the drought will necessarily lead to a food shortage, which can impact over one billion people.

When we speak of "carbon efficiency" we know that greenhouse gases are not made up only of carbon dioxide, and they do not all have the same impact on the environment. For example, one ton of methane has the same heating effect as 80 tons of carbon dioxide, therefore the convention used is to normalize everything to the CO2-equivalent measure. International climate agreements have ratified to drastically reduce "carbon" pollution and stabilize the temperature at a 1.5°C increase by 2100.

First Problem. Every year the world produces and releases more than 50 billion gas into the atmosphere.

Second problem. The increase in temperature does not depend on the rate at which we emit carbon, but on the total quantity in the atmosphere. To stop the rise in temperature, we must therefore avoid adding to the existing carbon, reaching a zero-emission target. Of course, to continue living on earth, this means that for every gram of carbon emitted, we must subtract as much.

Solution: emissions must be reduced by 45% by 2030, and we should be “zero-emissions” by 2050.

Let’s now address what happens in our closer world, within cloud datacenters. The demand for compute power is growing faster than ever. Some estimates (dated before covid-19, hence I assume the current estimates will be even higher), indicate that datacenter energy consumption will account for no less than a fifth of global electricity by 2025. A Virtual Machine operates on average at 20-25% of its processing capacity, while consuming a lot of unused energy. On the other hand, in an instance where applications run, it is still necessary to use resources, regardless of whether an application is idle or not. Containers have disrupted the application world, bringing VMs to a higher density, that can reach 60% or higher compute capacity usage. Ultimately, though, it is estimated that 40% to 75-80% of the world's server capacity is just sitting idle, consuming electricity resources for no reason.

While browsing for ideas, I found very little documentation or statements about sustainable software engineering. Talking to fellow Microsoft colleague Asim Hussain, I found out that there is indeed a “green-software” movement, which started with the principles.green website, where a community of developers and advocates is creating guidelines for writing environmentally sustainable code, so that the applications we develop and use are not only efficient and fast, but also affordable and sustainable.

The eight principles are listed as follows:

  1. Carbon. The first step towards sustainability, is to have the environmental efficiency of an application as a general target. It seems trivial, but to date there is not much documentation in computer textbooks or websites.
  2. Electricity. Most of the electricity is produced from fossil fuels and is responsible for half of the CO2 emitted into the atmosphere. All software consumes electricity to run, but developers generally don't have to worry about these things: the electricity consumption is usually referred to as "someone else's problem". But a sustainable application must take charge of the electricity consumed and be designed to use as little as possible.
  3. Carbon intensity. The carbon intensity is the measure of how many CO2-equivalent emissions are produced per kilowatt-hour of electricity consumed. Electricity is produced from a variety of sources, each with different emissions, in different places and at different times of the day, and most of all, when it is produced in excess, we have no way of storing it (yet). Sources as wind, solar, hydroelectric are clean, but other sources such as power plants have different degrees of emissions depending on the material used to produce energy. If we could connect the computer directly to a wind farm, the computer would have a zero-carbon intensity. Sadly, we connect it to the power outlet, which receives energy from different sources and therefore we must handle the fact that our carbon intensity can never be zero.
  4. Embedded or embodied carbon is the amount of pollution emitted during the creation and disposal of a device. Efficient applications that run on older hardware also have a good impact on emissions.
  5. Energy Proportionality. The maximum rate of server utilization must always be the primary objective. In general, in the public cloud this also equates to cost optimization. The most efficient approach is to run an application on as few servers as possible and with the highest utilization rate.
  6. Networking. Reducing the amount of data, and the distance it travels across the network, also has its impact on the environment. Optimizing the network routes of packages is as important as reducing the servers use. Networking emissions depend on many variables: the distance crossed, the number of hops between network devices, the devices' efficiency, the carbon intensity of the region where and when the data is transmitted.
  7. Demand shifting and demand shaping. Instead of designing demand-based applications, a green software infers demand from the energy supply. Demand shifting involves moving workloads to regions and at times with lower carbon intensity. Demand shaping, on the other hand, involves separating the workloads so that they are independently scalable, and prioritizing them to support each feature based on energy consumption. When the carbon intensity is higher, the application reduces its features to a minimum, keeping just the essential. Users can also be involved by presenting them a "green" option.
  8. Monitoring and optimization. Energy efficiency must be measured in all application's aspects to understand how to optimize it. Does it make any sense to spend two weeks reducing network communication by a few Mb when a full-scan db query has ten times the impact on emissions?

These principles are generic for any type of software, but what about serverless? Serverless computing generally refers to applications where resources management and allocation are completely handled by the public cloud provider. By eliminating the need to manage the infrastructure, development is faster and cheaper. But can it also be sustainable?

a serverless architecure sample, an e-commerce scalable website

Serverless applications are natively designed to optimize emissions. Since the same application consumes power differently, depending on the place and time of execution, demand shifting is easily applied to serverless. Of course, we have no control over the infrastructure used, we must trust that cloud providers want to use their resources at 100% capacity. ??

Cost optimization is also an indication of sustainability, and with serverless, we can directly impact on execution times, on the network data transport, and in general on emissions.

No alt text provided for this image

Using serverless for sustainable software can be very impactful, as it means a more efficient use of the underlying servers, since they are managed in shared mode by the cloud providers, and built for an efficient use of energy to reach optimal data center temperature and power. In general, cloud datacenters have strict rules and often have ambitious targets for emissions (for instance, Microsoft recently declared its will as a company to become carbon negative by 2030). Making the best use of the most optimized resources of a public cloud provider implicitly means optimizing the emissions of your application. Since serverless only uses on-demand resources, we already know the server density is the highest possible, but serverless workloads are also ready to run with demand-shifting / shaping techniques. From a purely theoretical point of view, writing optimized and efficient code is always a good rule of thumb, regardless of the reason for doing it. ??

Developers can immediately have an IMPACT on application sustainability that affects millions of users:

  • Making a program more accessible to older computers.
  • Writing code that exchanges less data, has a better user experience and is more environmentally friendly.
  • If two or more microservices are highly coupled, considering co-locating them to reduce network congestion and latency.
  • Considering running resource-intensive microservices in a region with less carbon intensity.
  • Optimizing the database and how data is stored, thus reducing the energy to run the database and reducing idle times, pending completion of queries.
  • In many cases, web applications are designed by default with very low latency expectations: a response to a request should occur immediately or as soon as possible. However, this may limit the sustainability options. By evaluating whether latency limits can be eased in some areas, can help reduce further application emissions.

In conclusion, I strongly believe serverless architectures, where properly used, are the future of native cloud, not just because they are beautiful, practical and affordable, but also because today they have the least impact on emissions. With the help of the community, we can create specific guidelines for serverless and maybe even an "carbon meter" for our application, which in the future could also become "low-carbon certified".

COVID-19 was an inspiring moment in terms of what we managed to do on a global level: all the countries stopped, all the flights, the traffic, the non-essential production. We know that something great can be done and it’s the right moment: rebuilding everything from scratch, we should draft it in the right direction and change it for good.

 

Wilco Burggraaf

Green Software (Foundation) Champion & Architect at HighTech Innovators

7 个月

Amazing read!! Although there are some challenges in your conclusions, I love that as a community we try to find the best possible scenarios!

Juliette Fournier

Software engineer at Theodo

2 年

Hello Paola Annis, great article ?? You state that "40% to 75-80% of the world's server capacity is just sitting idle". It's scary ?? Do you have the source of this number ?

回复
Asim Hussain

Executive Director at Green Software Foundation | Psychedelic Medicine Advocate

4 年

Great article Paola!

Riccardo Trubiani

Strategic Program Manager @ Microsoft WE | Lightspark Advocate

4 年

????very nice article Paola! ??

要查看或添加评论,请登录

社区洞察

其他会员也浏览了