A step towards more ecological software development

Have you ever wondered if you, as a software developer, can do more to reduce your carbon footprint? What about the carbon footprint of all the apps you’ve deployed? 

Generally, in software development, you don’t hear a lot about this topic. But why is that? Can we not make enough impact? Is it even worth putting some effort in? 

Changing mindset

There are a lot of aspects in which software can be made more efficient, in order to reduce the computing power needed. Database queries can be made more performant, extra roundtrips can be avoided, unnecessary data doesn’t have to be stored, redundant calculations may be removed, log retention and the amount of logs could be reduced, multiple application instances running simultaneously could potentially be scaled down,… You name it. But do we actually care enough? Usually, when we think of improving these things, we usually do it to improve user experience, but rarely do we think about the ecological impact. We can actually change that. Let’s be a little more conscious in how we technically design our applications. The more of us who think about it, the more significant the overall impact can become over our shared application landscapes.

 

The trigger

To be honest with you, I didn’t always kept the ecological point of view in mind while developing applications. Sure, I thought about performance and log retention, caching were it would be advantageous, reducing round trips, introducing indexes in database queries, but I didn necessarily have the ecological footprint of the application in mind. But then I came accross an interesting post on LinkedIn, that changed this:

This immediately triggered me, and I went on to watch the Devoxx presentation on YouTube, which I truly recommend watching:

Green scheduling

Let’s talk a bit more about the software in the conference talk.

What is it? In a nutshell, it is software that allows you to schedule recurring tasks, like nightly jobs, considering the carbon intensity at the planned execution time. The aim is to run the task at the most opportune moment, being the window of time where carbon intensity would be at its lowest point.

Currently, the software consists of a propriatry API (maintained by First8) as well as an open source Java library. There are plans to support more programming languages in the future. Currently there is already support for the Spring and Quarkus frameworks.

The API is in charge of calculating the most desirable window in which to execute a given job, for a given time zone and region. It also takes an expected duration amount into consideration. Currently, the API is free of charge, but you do require an API key. You can easily set it up though, do go through the steps as documented on their Get Started page.

The library provides the annotation, its processing and the logic calling the API and the scheduled job management.

You are most likely already familiar with Spring’s Scheduled annotation, where you would define recurring jobs like so for example:
@Scheduled(cron = "0 0 2 * * ?", zone = "Europe/Brussels"). Using the library’s equivalent annotation, you would define that like so:
@GreenScheduled(fixedWindow = "02:00 08:00", carbonIntensityZone = "BE", duration = "1h" timeZone= "Europe/Brussels").
Note that instead of always running the job at 2AM, now we specify a time window. The carbonIntensityZone maps to a region as defined with ENTSO-E, from which the API consumes data. You also see that we need to pass a duration parameter, this is mandatory at the moment, and can be a rough estimation of the time the batch job would need to complete. Perhaps, this will be made a bit smarter in the future.

An example I’m personally already using in a hobby project:

@GreenScheduled(
fixedWindow = "01:00 23:00",
duration = "1h",
carbonIntensityZone = "BE",
timeZone = "Europe/Brussels",
dayOfWeek = "MON"
)
public void cleanUpArchivedLogs() {
// Log cleanup code omitted
}

As you can see, there’s different options for defining when the job has to run.
Of course, you would have to use this mindfully. If the job you want to execute is required to run at a specific time (do ask the question: why?), this approach doesn’t fit your case. But for jobs, like the above, where the execution time is not that important, go for it!

Now, imagine the impact it would make if all of us would consider something like this when setting up scheduled jobs. Every job can literally contribute in reducing the carbon footprint.

Even considering the downside of the extra API call and the computing power required for it to come up with the most suitable execution time, we will usually save more carbon, given we setup wide enough windows.

However, the supported regions, at the time of writing, only include ‘NL’. First8 (a Dutch company) does however plan to support a lot more regions, but the timeline on that is not yet very clear. If you are interested in support for a given region, do contact them to request support for it.  

Do not hesitate to contribute to the project on GitHub. The team is welcoming any change or improvement and they setup very easy-to-follow setup and contribution guidelines.

I’m playing around with the software myself. I’m evaluating wether it is ready for use in production applications (mostly region support seems to be lacking).
I’ve also contributed 2 minor changes to the library to show my support:
Implement Autocloseable on schedulers
Javadoc improvements

Green energy production often relies on multiple weather factors like, sun, wind, rain (for hydro plants),… And this little piece of software tries to make better use of that.

Moving forward

The green-scheduler I’ve just ellaborated on is of course not the only answer to improving our shared carbon footprint. It is a good step in the right direction. It makes us reflect on what we can do better. And that’s exactly it, that’s exactly what we need to start doing a little bit more.

Do you have suggestions to further improve ourselves on the topic? Or are there already other things you are actively doing to make an impact? Do let me know in a comment, I would be very interested in hearing about it, or to start a conversation!

Author: Thibault Helsmoortel

Belgian IT enthusiast with a wide range of interests. Enjoys table tennis and meeting friends at the local bar.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.