Skip to Content

WRITING GREENER CODE FOR THE PLANET

July 2, 2025
Jonas Hultenius

Let’s be honest for a second. When we write code, our biggest concerns usually orbit around deadlines, feature bloat, and whether our linter is yelling at us again. We stress about performance, security, UX. But how often, really, do we stop and ask: is this line of code going to contribute a little more to emissions?

Yeah. Didn’t think so.

But maybe it’s time we start.

Because code isn’t just ethereal logic floating in a vacuum. It runs. It spins up servers, slurps down power, and leaves a trail of carbon dioxide in its wake. Sometimes a small puff. Sometimes a foghorn blast. And as it turns out, we as developers might have a much bigger role to play in saving the climate than we ever imagined.

Not by chaining ourselves to a data center in protest. But by writing better code. Greener code. Code that asks for less and does more.

Back when I started coding, green meant one thing: syntax highlighting in Vim. The only carbon we cared about was the soda we were drinking at 3 a.m. But now? We’re facing a climate crisis, and tech is no longer the clean, quiet industry we pretended it was. The data centers that run our stuff are loud, hot, and thirsty for power. The cloud? It’s basically just someone else’s coal-fired computer unless you’re very intentional about where you deploy.

And here’s the kicker. The software we write directly influences how much hardware has to do. The more bloated, inefficient, and over-engineered our code is, the more energy it eats. And at scale? That adds up.

Think about this. Let’s say you have a microservice that does something simple, checks a user’s subscription status or filters a list of products. If that function is called a million times a day, and your implementation is a few milliseconds slower than it could be, or queries the database twice instead of once, you’re not just costing your company performance. You’re burning extra CPU cycles. Which means more electricity. Which means more emissions. Multiply that across a million services, a billion users, and you get the picture.

The good news? Writing greener code isn’t about turning into some kind of performance monk who speaks only in assembly. It’s about caring. About paying attention. About taking a second to think before you drop in that third-party dependency or spin up another background task that no one ever shuts off.

Let’s zoom in.

A while ago I inherited a project where the front end loaded seven different fonts. Seven. Some of them were used once. Others… not at all. Every single one was a blocking request. Together they added over a megabyte of extra traffic. On every page load. Multiply that by a few thousand users per day and suddenly your marketing site is a small emissions factory. And for what? So that H2 headers could look “slightly more European”?

This stuff matters.

And it’s not just front end. I’ve seen backend APIs that re-hydrate massive JSON blobs from databases when they only need two fields. I’ve seen functions that recalculate the same value over and over again instead of caching it for three seconds. I’ve seen devs loop through entire datasets in memory when a simple SQL query with a WHERE clause would’ve done the trick.

You might be thinking, “But it runs fine.” Sure. But so does a diesel truck. Doesn’t mean it’s the best choice to drive to your mailbox.

The truth is, modern hardware hides a lot of our sins. CPUs are fast, RAM is cheap, networks are dense. Which means we’ve gotten lazy. We over-fetch, over-process, over-engineer. We wrap things in three layers of abstraction so we can feel smart, and then forget what the code even does.

But every layer, every call, every wasted byte adds up.

Writing greener code is about rethinking what we’ve come to accept as “normal.” Do you really need that animation to be 120fps? Does that dashboard really need to poll every two seconds? Is your fancy algorithm actually better, or just more complex?

And it’s not about perfection either. It’s about intent. If you build a feature that saves 5 percent on compute time across an entire user base, you’ve probably done more for the environment than any “green” logo slapped on your homepage.

I like to think of it like packing for a trip. You could throw everything into a suitcase and just sit on it until it closes. Or… you could plan a little. Fold things. Bring only what you need. Same trip, less hassle. Lighter load.

So how do you start writing greener code?

You measure. Not just what’s fast, but what’s used. Profile your app. Look at memory. Look at CPU. Look at I/O. See where the waste is. Spoiler alert: there’s always waste.

You simplify. Remove dead code. Avoid unnecessary libraries. Choose data structures that make sense. There’s a reason why a Set exists. Use it.

You cache. But not blindly. Cache what makes sense. Avoid reprocessing the same request fifty times a second if the answer doesn’t change.

You batch. You debounce. You delay. You stream instead of buffering the whole thing at once. Basically, you write like someone who’s paying the power bill.

Here’s the wildcard: sometimes writing greener code means not writing code at all. Can you offload to a service that does it better? Can you reuse something that’s already out there instead of rebuilding from scratch? Can you say no to a feature that adds little value but infinite complexity?

You might not always have that power. But when you do… use it.

One more thing. Writing green code also means thinking about where and how it runs. Are you deploying to a cloud provider that uses renewable energy? Are your systems scaled efficiently? Do you shut down things that aren’t being used? That CI pipeline you left running on every branch? Yeah, that too.

All of this ties back to a bigger idea. That software is infrastructure. And infrastructure has consequences. We talk a lot about “digital transformation” and “scalability” and “user experience.” Maybe it’s time we start talking about carbon budgets too.

Because if the internet were a country, it would already be the fourth biggest polluter in the world. And developers? We’re the ones building the roads.

Here’s the part where I should probably tie everything up with a Marvel reference or something. So let’s go there. Remember when Tony Stark built that tiny, efficient arc reactor in a cave? That’s us. We don’t need more code. We need better code. Smaller, smarter, cleaner code. Code that knows what it’s doing and why. Code that gets in, does its job, and gets out without leaving a mess behind.

So next time you sit down to write, take a second. Ask yourself: is this necessary? Is it efficient? Is it the best I can do, not just for the user, but for the planet?

Because you may not be able to stop climate change with code alone. But you can definitely stop making it worse.

And that? That’s a pretty good place to start.

About the author

Software Architect | Sweden
I love technology and I tend to collect languages, techniques, patterns and ideas and stack them high. There is a beautiful synergy to be had and endless possibilities when mixing and matching. A process I find to be both exciting and fun. Innovation has always been a driving force for me.

Leave a Reply

Your email address will not be published. Required fields are marked *

Slide to submit