chapter eight

8 Sustainability

 

This chapter covers

  • Sustainability and software’s environmental footprint
  • Applying green design patterns
  • Estimating the carbon footprint of software
  • Using tools to improve code efficiency

Let’s extend the scope of the art of code beyond readability, simplicity, and failure handling to consider the resources software consumes when it runs. Disk space, memory, network traffic, and CPU usage are not just technical concerns: they require electricity and hardware, all of which carry both operational and environmental costs.

We’ll start by examining how digital technology contributes to our environmental footprint. Next, we’ll explore green design patterns that give developers actionable ways to reduce unnecessary computation, storage, and data transfer. Finally, we’ll review tools developers can use to measure and improve the efficiency of their code. By the end of this chapter, you’ll understand the sources of software’s environmental footprint, how these patterns address them, and how to apply them effectively in real projects.

8.1 The three pillars of sustainability

Sustainability means meeting present needs without compromising the ability of future generations to meet theirs. It is traditionally described by three pillars: environmental, social, and economic. In software, these pillars translate as follows:

8.2 The environmental impact of digital technology

8.2.1 The carbon cost of electricity

8.2.2 The hidden lifecycle cost of digital devices

8.3 The craft of green software

8.4 Green design patterns

8.4.1 Frugality pattern

8.4.2 Lean packaging pattern

8.4.3 Lean storage pattern

8.4.4 Lean communication pattern

8.4.5 Efficient execution pattern

8.4.6 Memory efficiency pattern

8.4.7 Carbon-aware pattern

8.5 Tools

8.5.1 Estimating carbon footprint

8.5.2 Tools for developers

8.6 Summary