📄 Page
1
(This page has no text content)
📄 Page
2
Praise for Building Green Software In the face of climate change, it can feel difficult to know what part software professionals can play in helping find solutions. This book is an excellent guide focusing on the practical steps we can take to make our systems more sustainable. —Sam Newman, author, Building Microservices Green software plays a vital part in the energy transition and this book gives a perfect introduction. —Asim Hussain, Executive Director, Green Software Foundation The book our industry has been waiting for, from the experts in the field. —Holly Cummins, Senior Principal Software Engineer, Red Hat
📄 Page
3
Building Green Software A Sustainable Approach to Software Development and Operations Anne Currie, Sarah Hsu, and Sara Bergman Foreword by Adrian Cockcroft
📄 Page
4
Building Green Software by Anne Currie, Sarah Hsu, and Sara Bergman Copyright © 2024 WorkingProgram Ltd., The Writer’s House LTD, and Sara Bergman AS. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com). For more information, contact our corporate/institutional sales department: 800- 998-9938 or corporate@oreilly.com. Acquisitions Editor: Megan Laddusaw Development Editor: Shira Evans Production Editors: Christopher Faucher and Jonathon Owen Copyeditor: nSight, Inc. Proofreader: Doug McNair Indexer: Ellen Troutman-Zaig Interior Designer: David Futato Cover Designer: Karen Montgomery Illustrator: Kate Dullea March 2024: First Edition
📄 Page
5
Revision History for the First Edition 2024-03-08: First Release See http://oreilly.com/catalog/errata.csp? isbn=9781098150624 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Building Green Software, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. The views expressed in this work are those of the authors and do not represent the publisher’s views. While the publisher and the authors have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the authors disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights. 978-1-098-15062-4 [LSI]
📄 Page
6
Foreword The preferred terms are “climate emergency, crisis, or breakdown.” —The Guardian Change is hard. Even in the presence of a global climate crisis that is causing migrations, wars, and destruction of ecosystems and habitat for everything from corals to humans, there are vested interests, investments, laws, regulations, and “best practices” that reinforce the status quo of a fossil fuel powered global economy. As individuals, we can choose to be part of an ethical movement for a sustainable future. We can vote, choose where we work, choose what we buy, redirect our investments, and lobby for better laws and regulations. As software developers we need to develop and implement new best practices for building green software. That’s where this book comes in. The business world can be divided into three categories, one that makes money causing the climate crisis by selling fossil fuels and resists the change. Another that makes money by building the new future of wind farms and heat pumps and the like and profits from the change. The third is the biggest category, trying to survive and build a business where the climate crisis hasn’t been a direct concern. Why should these businesses care enough to have goals, invest resources, and support employees that want to be green? The pressure is coming from all directions and is intensifying. It comes top down from regulators and investors, bottom up from employees and side to side from customers and suppliers. Governments and regulators around the world are starting to require audited carbon emissions reports alongside financial reports. They are also in the early stages of requiring climate risk assessments, where companies over a minimum size would have to
📄 Page
7
disclose to investors both physical and market risks to their business that derive from the climate crisis. For example if you are the “Miami Beach Spark Plug Company,” you would have to disclose that your production facility keeps flooding and is uninsurable, your employees don’t turn up for work because of more intense flooding, heat waves and hurricanes, and that your customers are switching to buying parts for electric vehicles. This translates into a board level interest in audit and risk topics around sustainability for all businesses. The pressure from employees should not be underestimated, in particular younger generations and those who have children have a strong interest in a sustainable future to live in, and vote with their feet as they choose who to work for and what they want to work on. Then there’s customers and suppliers. The supply chain is being instrumented so that you gather carbon data for everything you buy, and provide carbon data for everything you sell. This is also being mandated by government regulation, for example if you want to sell into the European Union there is a cross border carbon tax. As you work through setting management priorities and goals for the business, take these changes into account. Companies that ignore or resist change, when the environment changes around them, are setting themselves up to fail. We need to consider how to reduce the impact of the software we build, but we also need a sense of perspective. In most cases, the carbon footprint of a business is dominated by physical business processes, buildings, and employee activities. In this case, we are looking for opportunities to use software to optimize physical processes to remove carbon. It’s only the purely digital businesses like online banks and software services providers that are dominated by the carbon footprint of
📄 Page
8
their computing resources. However, whether you are building software to optimize carbon intensive physical processes, or just have to optimize the code that runs your services, you will need to build the mental models of how software translates into energy use, manufacturing supply chains, and carbon. You will then need advice on how to change the way your company builds and runs software, to optimize and reduce its carbon footprint. That is where this book comes in. It’s written by experienced practitioners who have been working with the Green Software Foundation for several years, and draws on the wide and deep experience that has been contributed to the GSF by many members. The book is written in an entertaining and opinionated style, and is full of practical useful advice for all aspects of building and running green software. Adrian Cockcroft OrionX.net Salinas, California, February 2024
📄 Page
9
Preface It’s not easy being green. —Kermit the Frog Climate change is real. The Intergovernmental Panel on Climate Change (IPCC) report of 2022 settled that. The world is now stepping up to respond, and it appears that companies will need to get on board with the energy transition or be left behind. Unfortunately, as a wise cultural icon once said, the changes required for a sustainable planet will not be easy. The good news, however, is that most of the public cloud providers have already committed to net-zero cloud operations (commitments they need to be held to), and we can learn from and emulate them as well as other sustainability leaders in our sector. In fact, some of the tools we need are already open source or commercially available. That’s fortunate, because the rest of us may soon be compelled by our customers, infrastructure providers, soaring bills, and incoming legislation to set and meet our own tough carbon targets. So how will software development and operations need to change to save the planet and our companies? This book aims to help answer that question. Building Green Software is an overview of everything from how national grids are likely to evolve in response to renewable power, to how that will change operations, to how the day- to-day lives of developers will be affected by the energy transition. You may notice that many of the quotes included
📄 Page
10
in this book are from folk who used to work for the hyperscalers. That doesn’t mean our quotees are renegade whistleblowers, just that they are commenting as individuals who are no longer subject to the rules of a somewhat heavyweight PR organization. It is useful to hear unfiltered views because everyone from the freshest developer to the most dog-eared CTO has a part to play in shaping the world that’s coming. How can we build, host, and operate code in a way that’s better for the environment, cheaper, and lower risk? Why Should You Read This Book? Anyone is allowed to look at this book. We have a very relaxed open-door policy. As a reader, you might be: A developer who is expected to contribute to your organization’s sustainability initiatives and wants a primer on the topic An architect who wants to better understand how to align with the Amazon Web Services (AWS) Sustainability Well-Architected Pillar A product manager designing a new feature who wants to know how to make the operation of that feature as green and low cost as possible A DevOps person or SRE who has been asked to reduce the carbon impact (or financial cost) of an existing application and needs some ideas or pointers Or you might be someone else entirely. Who are we to gatekeep? Whatever your role is, you have a role to play in being part of the climate solution.
📄 Page
11
By the end of this book, our aim is for you to have a better handle on: The fundamental architectural principles of sustainable, or green, software development and how to apply them How the energy transition is likely to change hosting on prem and in the cloud and how companies can prepare for that The concepts of extending hardware longevity and the part played in this by software And you will be able to: Make lower-risk choices about future plans Make an educated guess about which parts of your systems might need to change and how As far as possible, measure the effects of any changes you make Realize the close connections among the benefits of green software and other considerations such as reliability, performance, and—every CFO’s favorite— cost!
📄 Page
12
How Does This Book Work? We’re going to follow the advice of those foundational figures of the modern world—Aristotle and Dale Carnegie (the latter being the author of How to Win Friends and Influence People). They both (or, let’s face it, neither of them—quotes are notoriously fake news) said, “Tell them what you are going to tell them, tell them, and then tell them what you told them.” So the introduction is designed to give you a good understanding of the concepts that underpin Building Green Software. Each subsequent chapter is then a deeper dive into the details. Finally, we sum the whole thing up again in slightly different words for the benefit of ChatGPT and even the few remaining humans. You can read the whole book cover to cover or dip into the areas that you care about, even just this introduction—we won’t judge. Why Do Techies Matter? Like every major global industry, tech plays a significant role in climate change. By some estimates, we cause upward of 5%–10% of annual carbon emissions (including embodied carbon in end-user devices). That makes us potentially far worse than the aviation industry. We get away with this without much protest because people seldom see a giant data center (DC) flying overhead, which is both a good thing and also kind of a shame. It would be pretty cool. Some folk have plans for data centers in space (again, cool but there are pros and cons). They would generally be out of sight, too, though, so still unlikely to have much impact on public opinion. Out of sight, out of mind. The upshot is,
📄 Page
13
if we want to drive sustainability in the tech industry, the pressure will have to come from the inside rather than wider society. This might be a good thing, because what will actually make an impact and what won’t isn’t obvious. There is plenty of well-intentioned but ill-founded advice out there. For example, deleting your old personal emails may feel helpful, but it is an extremely poor use of your time. On a worldwide scale, individual action like that will have almost no effect, and it is far from the first thing anyone reading this book should direct their attention to. Individual action is nice, but collective or leveraged action is what revolutionizes things. That’s what we need to aim for, and as techies we are in a position to make big changes happen. Every reader of this book is likely to have an outsized amount of influence as a producer of software that is widely used or, even more so, as a consumer of software who can put pressure on the companies or groups who build it. Your power is greater than you think, and right now, there are more useful things you can do with it than manually delete highly compressible text files. The Culprits The tech industry’s emissions have two main sources: The production of the electricity required to power the code running in our data centers. “Embodied” carbon—the carbon that is emitted during the manufacture of the user devices like laptops and
📄 Page
14
smartphones that host our apps. Abandoned user devices are sometimes called e-waste. Crucially, all systems are not equal. Some are created in a way that requires more power and hardware to do exactly the same job. The good news is we can fix that. The bad news is it won’t happen automatically. Building sustainable, greener software systems will require active decision making from development, product management, and marketing teams. This book provides an overview of the work required from all three. What Won’t We Talk About? As you may have gathered by now, this is a book about the carbon impact, or the carbon footprint, of software. As such, this book won’t talk about all the cool things the application of new software can do to help speed up decarbonization in other sectors, sometimes known as the carbon handprint. It is a worthy topic of discussion, but one for another book. Next time! Says Who? Before we start, how to be green is an important subject but one that is rife with misinformation and so-called greenwashing, so why on Earth should you take our word for anything? The answer is, as always, you shouldn’t. Be skeptical. All of us (Sarah, Sara, and Anne) are or were software developers for a long time with a focus on scalability, efficiency, resilience, and performance. Fortunately, the new requirement for systems—sustainability, a.k.a.
📄 Page
15
greenness—has a lot of overlap with those existing architectural pillars. All three of us are also part of the Linux Foundation’s Green Software Foundation, and we have picked the brains of the foundation’s experts as well as gurus from other parts of the tech sector. Thus, this book is a community effort. In fact, reading it should allow readers to pass the Linux Foundation’s “Green Software for Practitioners” test (with free certification of completion), available online. Despite all of this, you still can’t trust us to tell you exactly what to do. Why not? Why Can’t You Trust Us? There are at least two reasons why you can’t trust us to tell you exactly what you need to do to go green. Neither is because we’re hankering to sell you a timeshare in an eco- apartment (or its even more enticing modern-day equivalent, an NFT of a photo of that apartment). You can’t trust us because: Things change. The good thing about modern publishing is we can update books after they are released, but, as you read this, new techniques or tools will already have appeared that we haven’t added yet. Green tech is a sector that’s moving fast! Our aim is to provide you with enough background that you’ll be able to judge these new products for yourself. We don’t know your context. Sometimes being green is the simplest option, but, apparently, it’s not easy. The effort we’ll ask you to put in will depend on the scale
📄 Page
16
your code operates at. What a small enterprise needs to do internally will differ a lot from the requirements that’ll be placed on the developers of a piece of open source code that will be deployed on millions or even billions of machines worldwide. The first step in going green will always be to understand yourself and your own systems. What is the most effective way you can contribute? For different readers, it will range from super-hard stuff (like rewriting your systems in Rust) to super-easy stuff (like telling your cloud rep that sustainability monitoring is something you want). There are many actions developers could take to reduce the carbon impact of their software systems, from system-level operational choices to architectural ones to code-level efficiency optimization. It is, however, easy to get stuck in the weeds. All the experts agree on one thing: it is vital to measure what you can and pick your battles, because there is a lot to do. For a start, don’t waste your time optimizing software that hardly anyone is running. Before you begin, consider how much hardware (servers or devices) and energy (data and CPU) in aggregate an application is likely to cause to be used everywhere it is run. For now, target only what’s operating at scale. The best application of your effort is always context specific, and when it comes to going green, pain does not equal gain. Your company’s most impactful change might be to choose a greener location next time you select a hosting region or, even better, to just tell your hosting rep or product vendor or open source project maintainers that sustainability is something you care about and will make decisions based on.
📄 Page
17
The public clouds have all made commitments to be net zero, but we’d like to see them reach that point sooner, and what will get them to do that is customers asking for it. Noncloud DCs are further behind, so they need to hear even more demands from their customers. Open source products are not yet paying enough attention to carbon footprint and need to feel more pressure. Almost certainly, the biggest green impact you can make is not at your keyboard, typing code. It is far simpler than that. Say something. Exert your power, and you don’t have to camp outside AWS’s offices with a placard, a thermos, and a wooly jumper to do so. A pleasant email stating your preferences as a loyal customer is more effective and a lot less chilly. You can always Instagram yourself pressing Send. Conventions Used in This Book The following typographical conventions are used in this book: Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. TIP This element signifies a tip or suggestion. NOTE This element signifies a general note.
📄 Page
18
WARNING This element indicates a warning or caution. O’Reilly Online Learning NOTE For more than 40 years, O’Reilly Media has provided technology and business training, knowledge, and insight to help companies succeed. Our unique network of experts and innovators share their knowledge and expertise through books, articles, and our online learning platform. O’Reilly’s online learning platform gives you on-demand access to live training courses, in- depth learning paths, interactive coding environments, and a vast collection of text and video from O’Reilly and 200+ other publishers. For more information, visit https://oreilly.com. How to Contact Us Please address comments and questions concerning this book to the publisher: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, CA 95472 800-889-8969 (in the United States or Canada)
📄 Page
19
707-827-7019 (international or local) 707-829-0104 (fax) support@oreilly.com https://www.oreilly.com/about/contact.html We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at https://oreil.ly/building-green-software. NOTE A version of this book is also available to read for free under a Creative Commons license. For news and information about our books and courses, visit https://oreilly.com. Find us on LinkedIn: https://linkedin.com/company/oreilly- media Watch us on YouTube: https://youtube.com/oreillymedia Acknowledgments Our thanks go out to our brilliant O’Reilly team, especially Shira, Megan, Jonathon and Chris, and to our dedicated reviewers: Holly Cummins, Sam Newman, Bill Johnson, Kerim Satirli, Asim Hussain and Henry Richardson. Our gratitude also to all the industry folk we interviewed who gave us their expert perspectives. Last but not least, thanks to Adrian for his foreword, which is a challenge to our
📄 Page
20
industry to step up! Without all of you, this book would never have happened. Anne What a team effort! My thanks to Sara, Sarah, and our editor Shira who made all the hard work a blast and to my husband Jon, who has read every chapter almost as many times as I have. Thanks too to old friends and colleagues Ross Fairbanks and Charles Humble, who lent me a hand with extra reviewing. Plus, of course, baby Hugo, for cheering us up in calls and reminding us why all of this matters! Sarah “It’s not the destination, it’s the journey”—this sentiment couldn’t be more accurate for the extraordinary adventure I’ve shared with Anne and Sara. Alongside the heartfelt cheers to my incredible colleagues, friends, and family, a special shout-out goes to my mum. Her unwavering support and sacrifices have been the driving force propelling me to where I am today! Sara Anne and Sarah, my ride or dies, oh what an amazing journey this has been! A big, big thank you to the both of you! Agreeing to write a book while being a few months pregnant was not an easy choice, but I’m so glad I did. To my partner Jonatan, thank you for your continued support: without you, this would not have been possible. Thank you to my son Hugo, who arrived halfway through the work on this book, this is for you and your generation.