Are there any best practices you use or thoughts around how to help a django web app do the least environmental harm as possible?
Hi there, Mr. Doe, I’m sorry it has taken me so long to respond to this question. I set it aside for a bit to think on this topic more and then got busy with REVSYS client stuff.
First off, I’ll give you the short version of this answer.
The greener your code, the leaner your performance.
This applies not only to Django, or Python apps, but to software written in any language.
Efficiently Operating Code
This is going to get a bit hand wavy, but at the core (pun intended) this boils down to electrical efficiency. Both in terms of voltage/amps and on some level the need to manufacture more silicon, SSDs, routers, switches, etc, etc.
Software performance is all about doing less
- Less SQL queries
- Less network calls to another service
- More cache hits, less reads from storage
- Smaller network payloads
- Less…
Therefore, making your code faster and more efficient makes it greener.
Luckily for the planet, users put a bit of a premium on speed and efficiency while businesses like to reduce their costs, so over a long time horizon hardware and software have and will continue to improve over time.
Tangent: This is also why I don’t find the environmental concerns about AI and LLMs to be terribly important. Consumers, and (most importantly) the companies are absolutely aligned to make these systems as efficient as possible over the long term.
Things that don’t matter that much
There are some tactics you’ll find that are marginal in their effectiveness. One that comes to
mind is that dark mode is more energy efficient
than a site with background-color: #FFFFFF.
They are not wrong, but it also doesn’t matter unless the site you’re operating has hundreds of thousands to millions of users.
As an old Unix greybeard, I prefer a dark theme most of the time, but you’re deluding yourself if you think flipping the Django Admin to dark mode on your personal blog is helping the environment in any significant way. However, Instagram forcing their users to switch would.
If all of your code has only a few consumers interacting with it, you would have a bigger impact on the environment by adopting Meatless Mondays or using more public transportation than worrying about if you should bail out of that for loop earlier or not.
Main Take Away
Work to make your most heavily used bits of code more efficient.
It’s far better to optimize a hot loop on a high traffic site by 1% than it is to optimize a monthly cronjob from 4 minutes to 3 minutes.
Asked on January 26, 2026