9. February 2024 By Yelle Lieder
Green coding – Guidelines for the development of sustainable software
There is no shortage of guidelines and recommendations for sustainable software. On the contrary, there are so many criteria catalogues and best-practice lists, which are evolving on a daily basis, that a regular work week is hardly enough to stay abreast of developments. The Handbook of Sustainable Design of Digital Services of the Institute for Sustainable IT with 516 criteria, the Web Sustainability Guidelines by W3C with 93 recommendations, the Criteria Catalog of the Environmental Campus Birkenfeld with 20 criteria, the pattern library of the Green Software Foundation with 53 patterns and the tactics archive of VU Amsterdam with 95 examples are just a selection of the available sources. They are useful for familiarising yourself with the range of options for action. However, their scope makes them rather overwhelming for day-to-day work and the granularity of the decisions discussed distracts from the essentials. Therefore, we at adesso have thought about what is really important to us. The result is 9 (+2) guidelines for the development of sustainable software, which I want to present below.
Data-based life cycle analysis
Sustainable software not only considers the runtime behaviour, but also the environmental impact over the entire life cycle. Undesirable interactions can be detected and dealt with appropriately through simulations, calculations and measurements of the actual environmental impact in all phases of the life cycle. For example, a technology can be very efficient in operation, but consume a disproportionate amount of resources when idle or during start-up. Efficient runtime behaviour would be important for applications with a constantly high load without dynamic scaling. On the other hand, if scaling is regularly set to zero, the overhead for booting can be significant. Such conflicting objectives can only be identified and taken into account during implementation when an evaluation over the entire life cycle takes place. Therefore, it should be a top priority to take all decisions not only in the context of a single life cycle phase, but always on the basis of previously collected data. You can find out more about measuring the sustainability of software in this blog post.
Caching
Sustainable software stores results temporarily and reduces the number of redundant operations. Data that you frequently require should be available quickly. This can reduce redundant calculations or even expensive inferences in AI models. This type of caching can be used in frontend applications in the browser as well as in backend APIs or at the http level. Computing power and power consumption of network devices can be reduced when data are made available quickly without having to retransmit it over the network or search databases again.
Data minimisation
Sustainable software can ‘save’ data. Fewer pieces of physical hardware are required for processing and storage when the amount of data stored, processed and transmitted is minimised. In addition, less energy is consumed by the hardware involved, as it has to provide less computing power and fewer storage media have to be continuously supplied with power. Concrete strategies for more data economy include compression, batching of operations, provision of filters in APIs or pagination – both in the front end and in APIs.
Carbon awareness
Sustainable software performs less if no green electricity is available. By aligning the execution of resource-intensive processes with the availability of renewable energies, the CO2 emissions of system operation can be reduced by up to 40 per cent, depending on the region. Processes can be shifted in time in order to benefit from a better CO2 intensity on site if the processes are not time-critical, or they can be carried out at other locations where more renewable energy is currently being produced if the processes are time-critical. It is estimated that up to 30 per cent of all workloads are not time-critical and are therefore suitable for relocation.
Mobile first
Sustainable software is compatible and powerful on mobile devices. Development according to the ‘small-first’ paradigm not only leads to runtime-efficient solutions. Compatibility on more end devices can also achieve greater backwards compatibility, meaning that users need to purchase new hardware less frequently in order to use the latest software. Mobile systems need to be used even more sparingly as there are often fewer resources available on them. This applies to processors and memory as well as bandwidths and displays.
Efficient algorithms and data structures
Sustainable software uses efficient algorithms and data structures that are tailored to the problem. By dispensing with generic solutions, application-specific strengths in the area of resource consumption of specific alternatives can be utilised. Optimising the selected algorithms and data structures can be particularly worthwhile when economies of scale come into play. All too often, several lists or arrays are simply nested where alternative data types – such as hash tables – would tackle the problem more adequately and efficiently. Likewise, standard sorting algorithms are used just as often without taking into account the nature of the specific data. This results in an unnecessarily high number of CPU cycles or memory utilisation, which increases the system’s resource consumption.
Avoiding over-engineering
Sustainable software specifically avoids over-engineering. Technological sufficiency can reduce resource consumption by only doing what is really necessary. This includes an appropriate complexity of the implementations and the selected technologies as well as the reduction of the functional scope to the essentials. Specific decisions to avoid over-engineering can include approximate programming, feature toggling, needs-based logging or architectures that are oriented to plugins.
Avoiding obsolescence
Sustainable software counteracts obsolescence in terms of technology. Strategies to avoid obsolescence – as opposed to outdatedness – allow systems to be used for longer. This means that new systems need to be developed less frequently, which saves resources. This focus on longevity applies to both hardware and software. To promote the longevity of hardware, particular attention should be paid to downward compatibility, in other words, software should have low performance requirements enabling it to also run on older hardware. Software longevity can be achieved through targeted maintenance and update strategies. The selection of technologies that are rolled out with long-term updates and further developed also plays a role here. Suitable instruments for technology selection can be, for example, technology readiness level models such as the Technology Readiness Level (TRL) developed by NASA. Patterns for easily maintainable code – such as single responsibility patterns, encapsulation and loose coupling – can also be used to technically support maintainability and check it with metrics such as cyclomatic complexity, code duplication or method/class length.
Keep it simple
Future-proof software is simple. Simple in both senses of the word.
On the one hand, sustainable software must be simple in itself. Established and less complex solutions generally consume fewer resources. Only in exceptional cases will you achieve a more efficient solution if you recreate the function of an available library manually. For this reason, in terms of sustainability, it is rarely worthwhile to reinvent the wheel. Simplicity must also apply to the choice of technology. If JSON is suitable as a data format for solving problems, you really need to have good reasons to use XML. After all, such more complex data formats not only consume more resources during parsing, but also generate greater loads for data transfer and memory.
On the other hand, implementing sustainable software is easy. Only one of the methods presented is truly groundbreaking and requires additional effort. And even this new carbon-aware paradigm is supported by existing approaches such as the separation of batch jobs – for example, when executing spot instances. In many cases, sustainability can simply be used as an additional criterion for or against decisions without incurring any relevant additional expense. There are often also positive side effects for other quality characteristics, such as better maintainability or user experience.
Sustainable software development guidelines at adesso
Our internal guidelines also include the points ‘Selecting sustainable technologies’ and ‘Use of event-based patterns’, in addition to the nine points presented above. The importance and advantages of these two items have already been presented in this blog post on sustainable software architecture, which is why we will not repeat them here.
The guidelines presented here were developed together with the adesso Software Engineering Community. We would like to take this opportunity to thank all those involved for their active participation. They should serve as orientation or a recommendation for action and not as the sole path to sustainability. Our guidelines are intended in particular to show those developers who have had less contact with sustainable software how to act and take decisions in everyday life. Of course, they do not represent a complete list of possible activities, but in our view, they are the first steps on the way to more sustainable software.
You can find more exciting topics from the world of adesso in our previous blog posts.
Also interesting: