Let’s become the architects of a cleaner, greener world
The cloud has a
By shifting electricity consumption to times and places where electricity is cleanest, programming can mitigate climate change and ensure a cleaner and safer future for us and future generations. This is Carbon Aware Computing, and it has the potential to make software development a critical force in mitigating climate change by helping us choose and optimize carbon-free energy with climate-conscious code.
There aren’t many examples of carbon-aware computing out there - which is why events like __Carbon Hack 22 __are significant in crowd-sourcing new ideas and accelerating innovation in software programming to build applications that are both climate-conscious and energy-responsive.
Green Software Foundation __discusses __carbon awareness as the idea of doing more when more energy comes from low-carbon “clean” sources and doing less when more energy comes from high-carbon “dirty” sources. As developers, we can do so by measuring and responding to the carbon intensity of electricity (gCO2/kWh), which can help create code to reduce the amount of carbon emissions generated through software.
There are broadly 3 approaches:
2.Time Shifting: Running our software at a cleaner time; when clean energy is being generated by wind, water, or solar power.
Building carbon-aware applications is challenging, despite various data sources, partly because some of these sources are hard to navigate. The
If you visit
We can hook it to APIs like
Time Shifting: What time is best to run my software?
When time shifting, you can use the /emissions/bylocations/best API endpoint, providing it with the location you are interested in in the location field. Currently, the location names are mapped to Azure region names. You also need to provide the time window during which you are able to move the job. The start time needs to be entered in the time field, and the end of it in the toTime field. The dates provided should be in the ISO 8601 format.
You can directly request data from the API via a Curl request like so:
curl -X 'GET' \
'https://carbon-aware-api.azurewebsites.net/emissions/bylocations/best?location=uksouth&time=2022-10-08T00%3A00%2B01%3A00&toTime=2022-10-08T23%3A59%2B01%3A00' \
-H 'accept: application/json'
Or even just a normal HTTP GET request in the browser.
As output, you will receive an array of JSON objects, with the WattTime region name for the location, time of the data, carbon intensity rating, and duration for which this data is valid (WattTime provides data in 5-minute intervals). This data will be the lowest carbon ratings for the requested location. This query looks at data from a single 24-hour window, so to get an accurate result you might want to request data for multiple days (e.g., by looking at the /emissions/bylocationsendpoint) and check if this is not a one-time drop in carbon intensity!
[
{
"location": "UK",
"time": "2022-10-08T00:45:00+00:00",
"rating": 351.98767912,
"duration": "00:05:00"
},
{
"location": "UK",
"time": "2022-10-08T00:40:00+00:00",
"rating": 351.98767912,
"duration": "00:05:00"
},
{
"location": "UK",
"time": "2022-10-08T00:35:00+00:00",
"rating": 351.98767912,
"duration": "00:05:00"
}
]
When location shifting, you can use the same endpoint as previously (/emissions/bylocations/best), but for this time, provide multiple locations you are interested in and a single time during which you are looking. The example query below has multiple locations provided, taking uksouth, eastus, and francecentral under consideration. You can provide it with a time window (similarly to time shifting) or a single time point instead, filling in the time and toTimefields.
You can directly request data from the API via a Curl request like so:
curl -X 'GET' \
'https://carbon-aware-api.azurewebsites.net/emissions/bylocations/best?location=uksouth&location=eastus&location=francecentral&time=2022-10-08T09%3A00%2B01%3A00' \
-H 'accept: application/json'
Or even just a normal HTTP GET request in the browser.
As output, you will receive the same format of a response, with locations having the lowest carbon intensity, along with the time for that reading, the actual value of the carbon intensity, and the duration for which this data is valid.
[
{
"location": "FR",
"time": "2022-10-08T08:00:00+00:00",
"rating": 242.21832558,
"duration": "00:05:00"
}
]
Demand shaping: How do I adjust user behaviour?
To implement demand shaping, use a combination of the above queries and others to determine how best to adjust the behaviour of your application.
Imagine if you still carried out those energy-hogger ML training jobs... but only when the electricity grid powering them was running on renewables. Imagine if your washing machine only ran at the time your local grid was fully wind-powered. Imagine you wanted to run your CI pipeline simultaneously each day, but ensured it runs only in an availability zone (country) currently powered by green energy. In all these cases, you would still consume as much energy as before, but you would generate much fewer greenhouse gas emissions.
Whether you are polling the Carbon Aware API, running it in a local container, or as a Command Line Tool (CLI), you can use the patterns of event-driven development to connect events in your app to triggers in the electricity grid. Your own local grid or a greener, distant one.
Depending on your use cases, you can allow an entire device, computing job, or application to run exclusively on renewable energy, either by only running when the local grid is green or running only from zones currently powered by green energy.
Instead of being mechanics who keep the engine of digital emissions running, let’s be the engineers who help slow it down while maybe even contributing to the rebuild.
Carbon-aware computing is the next frontier of sustainable software engineering. Some of the most influential decision-makers in the industry are interested in reducing carbon emissions from software and showing that by lending their resources and contributing significant prize money to
It is now also the job of software engineers to build solutions that do less harm to both people and the planet. Carbon-aware computing is how current and future generations of software engineers can help achieve this goal.
Written by Asim Hussain, Executive Director and Chairperson, Green Software Foundation