Greening Digital �With Django
www.thegreenwebfoundation.org
Chris
Adams
2024.06.05
DjangoconEU 2024
1
GREEN WEB FOUNDATION
Hello, I’m Chris!
My background:
First started working with Django in 2008. My background is mainly in climate and open data startups and companies since then.��Loco2 - Low CO2 Travel in Europe by train
A.M.E.E (Avoid Mass Extinction Engine) - CO2 calculation as an API
Green Software Foundation - policy working group co-chair
Branch Magazine - contributor, co-founding editor
climateAction.tech - community organiser since 2018
Environment Variables podcast - host since 2022
Djangocon EU - various talks and workshops on this subject since 2017
Green Web Foundation - exec director, my full time job today
2
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
What we’ll cover
3
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Accessing this deck
4
This deck is online with a bajillion links, and presenter notes.
The QR code will visible on the last slide too.
https://bit.ly/djangocon-eu-2024-greening-digital
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
The Green Web Foundation is working towards a fossil-free internet by 2030.
5
The internet should be a global public good —healthy for the planet and for the people who use it.
GREEN WEB FOUNDATION
Build open source tools, APIs, and libraries
6
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Create prototypes.
Contribute to open source projects.
Publish open data.
7
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Collaborate with research institutions
8
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Publish reports, magazines, guides about this field.
If you found this talk interesting, you’ll like Branch
9
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Talks.
Workshops.
Training.
Consulting.
10
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
How digital causes emissions, and why measure it
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
How do digital services cause emissions?
GREEN WEB FOUNDATION
12
Source: https://developers.thegreenwebfoundation.org/co2js/overview/
Datacentre usage
End user device usage
Network transfer
Production and disposal
Powering and cooling servers
Powering core networks, mobile networks,
on-premise wifi and fixed routers
Powering end user devices - laptops, workstations, smartphones and tablets
Energy usage from making all of the above - processing raw silicon and other raw materials into integrated circuits, batteries, metal casings, etc
GREEN WEB FOUNDATION
Estimates vary, but between 2% and 4% of global carbon emissions is safe to use.
GREEN WEB FOUNDATION
13
How big is tech’s carbon footprint?
Source: https://www.thegreenwebfoundation.org/publications/report-fog-of-enactment/
GREEN WEB FOUNDATION
14
Credit: Photo by Skyler Smith on Unsplash
GREEN WEB FOUNDATION
15
Credit: Photo by Andy Li on Unsplash
GREEN WEB FOUNDATION
The internet is the biggest machine in the world, and today, it mostly runs on fossil fuels.
GREEN WEB FOUNDATION
16
Source: https://www.thegreenwebfoundation.org/publications/report-fog-of-enactment/
GREEN WEB FOUNDATION
How does this affect me though?
(apart from the whole climate anxiety thing, obvs)
GREEN WEB FOUNDATION
New changes in the law are making firms care more about two things:
1. Climate Disclosure: what are my emissions?
2. Climate Response: what is my plan to reduce them?
GREEN WEB FOUNDATION
Driving Climate Disclosure
19
“Show us you track emissions, and share this info with society”
Corporate Sustainability Reporting Directive (CSRD)
Climate Corporate Data Accountability Act (CCDAA)
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Driving Climate Disclosure
20
liberté�egalité�CSRDé
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Scope 3
Scope 1
Scope 2
Scope 3
Upstream
Directly reported
Downstream
GHG Protocol and Scoped Emissions Reporting
GREEN WEB FOUNDATION
How I remember the Greenhouse Gas Protocol
Greenhouse Gas Protocol:
Scope 1,
Scope 2,
Scope 3
22
Emissions from burning fossil fuels to make hot coffee
Scope 1
Emissions from electricity generated on your behalf, to make coffee
Scope 2
Emissions from activity in your supply chain, so you can have coffee
Scope 3
Scoped emissions communicated through the medium of hot beverages
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Scope 3
Scope 1
Scope 2
Scope 3
Upstream
Directly reported
Downstream
GHG Protocol and Scoped Emissions Reporting - if you sell to affected firms
You are here
And maybe here
GREEN WEB FOUNDATION
Driving Climate Response
24
“Show us you have a plan informed by the science”
Corporate Supply Chain Due Diligence Directive (CSDDD)
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Driving Climate Response
25
“Show us you have a plan informed by the science”
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Key takeaways.
1. Climate Disclosure: what are my emissions?
2. Climate Response: what is my plan to reduce them?�3. Digital has an impact too: we will�need to be able to answer questions �about it when asked
GREEN WEB FOUNDATION
How people estimate carbon emissions for digital
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
All models are wrong, some models are useful.
GEORGE BOX
Empirical Model-Building and Response Surfaces, 1987
28
“
GREEN WEB FOUNDATION
Usage based
29
Billing based
Estimate emissions based on observed usage of one or more parts of a system.
Estimate emissions based on observed spend. Turn billing into emissions data.
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Usage based
30
Component view
System view
Global view
Billing based
“Native”
3rd party
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Usage based
31
Component view
System view
Global view
Instrument a single part of the system.��Self report own impact.
See impact of focussed changes.
Composable into bigger systems.
Instrument components in a system.
�Report at a system or service level.
Figure out where to focus efforts for things in production.
See impact of different configurations or usage scenarios
Use data from a single component to model your share of the global impact of digital
Very easy to start out with, but assumptions in models may not match your context.
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Usage based
32
Component view
System view
Global view
Firefox profiler:
Javascript, browser reports own energy / carbon use. �
Code Carbon:
Python, often used for AI, can wrap existing python code
Scaphandre:
Rust, gives server-side per process figures
Green Metrics Tool:
Python, simulates common usage scenarios
Greenframe
Proprietary, javascript. Simulates common usage scenarios
KEPLER
Kubernetes focussed, uses production telemetry data, growing corporate support
Website Carbon
Javascript, proprietary
Ecograder
Javascript, open source
Sitespeed.io
Javascript, used by Wikipedia, has own grafana dashboards
Webpage Test Carbon Control
php + js, available as hosted service
An incomplete list:
(All use sustainable web model under the hood))
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Billing based
33
Native
Third party
Consumes billing data about service, region, quantity.
Direct access to hardware.
Applies proprietary conversions to turn purchased capacity into carbon dioxide equivalents.
Each provider has a different, incompatible proprietary methodology.
Largely consumes same billing data as native.��Less access to hardware.
Uses external model to enrich billing data with environmental figures.
More consistent across cloud providers (if supported)
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Billing based
34
Native
Third party
Microsoft Emissions Impact Dashboard
Scopes 1, 2 and 3
AWS Customer Carbon Footprint Tool
Scopes 1, 2 (no scope 3)
Google Cloud Carbon Footprint
Scopes 1, 2 and 3
OVH
Scopes 1, 2 and 3, also water usage 👍
Cloud Carbon Footprint
Scopes 1,2 3 - first “significant” open source project
OpenCost
Recently merged PR now adds carbon costs to dashboards.
Green Pixie (proprietary)
Originally based on CCF, available as hosted service. Now offers richer data than just carbon.
(And more, each day)
An incomplete list:
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Key takeaways.
You probably would start with billing based tools for climate disclosure.
�You would use usage based �tools for climate response.
GREEN WEB FOUNDATION
What these tools look like
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Usage based
37
Component view
System view
Global view
Firefox profiler
Javascript, reports measured browser energy
Code Carbon
Python, server side, often used for AI
Scaphandre
Rust, gives server-side per process figures
Green Metrics Tool
Python, simulates common usage scenarios
Greenframe
Proprietary, javascript simulates common usage scenarios
KEPLER
Kubernetes, uses production telemetry data for “real time” figures
Website Carbon
Javascript, proprietary
Ecograder
Javascript, open (?)
Sitespeed.io
Javascript
Webpage Test Carbon Control
php + js, available as hosted service
An incomplete list:
(All use sustainable web design model under the hood))
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Understanding how these work
Website carbon estimation tools are usage based, global view
38
Component view
System view
Global view
Billing based
“Native”
3rd party
Usage based
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Who has used a website carbon calculator before?
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Website Carbon by Wholegrain Digital
Uses:
Sustainable Web Design with Green Web Dataset
40
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
WebPageTest by Catchpoint
Uses:
Sustainable Web Design through CO2.js and Green Web Dataset
41
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
An intro to CO2.js
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
An open-source JavaScript library that enables developers to estimate the emissions related to use of their apps, websites, and software.
“
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Who’s using CO2.js today?
44
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
What can you do with CO2.js?
45
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
How do they use it?
46
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
How do they use it?
47
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Green Metrics Tool Full stack measurements
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Green Metrics Tool (GMT) - what is it?
GMT is a usage based, system view tool, that creates a system under test, then simulates common interactions
49
Component view
System view
Global view
Billing based
“Native”
3rd party
Usage based
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
How GMT works at very high level
Use docker to set up a system, and record metrics from “the outside”
50
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
What can you do with GMT?
Try different usage scenarios for your service - static vs dynamic, different page designs, etc.
51
https://www.green-coding.io/case-studies/wordpress-vs-hugo-cloudflare/
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Applying this to django - what you need
If you have a dockerised app, you’re halfway there to trying it out.
If you have any integration tests that drive a browser, you have a head start on usage scenarios too
52
Django app
Postgres
Browser
docker-compose.yaml
Redis
usage_scenario.yaml
+
scripts to drive the browser
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Learning from a real example - Wagtail and the bakery
Last year on the Wagtail GSoC project: used GMT to test common scenarios on the bakery demo site
53
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Learning from a real example - entire lifecycle
Seeing the output for by scenario
54
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Learning from a real example - specific scenarios
Seeing where and when the impact lies for each scenario
55
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
56
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Learning from a real example - putting the SCI in CI
Tracking Software Carbon Intensity in Continuous Integration
57
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Learning from a real example
Figuring out what to do next.
�(This is roadmap is entirely open source, and full of cool things you can contribute to in the sprint days)
58
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Code Carbon: Pythonic Server-side
carbon stats
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Code Carbon: what is it?
CodeCarbon is a usage based, component view tool for measuring the carbon, for python code
60
Component view
System view
Global view
Billing based
“Native”
3rd party
Usage based
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
How to start with it
Most common library used in AI papers for tracking carbon for training runs.��Also provides context managers and decorators 💚
from codecarbon import EmissionsTracker
�tracker = EmissionsTracker()
tracker.start()
�try:
# Compute intensive code goes here
_ = 1 + 1
finally:
tracker.stop()
61
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Why Django is well placed to be the greenest framework out there
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Why is Django well placed to lead in greening digital?
63
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Thanks!�I’ll be at the sprints, and this deck is online.
www.linkedin.com/in/mrchrisadams
mastodon.social/@mrchrisadams�
climateAction.tech - a friendly community of climate-minded tech workers
podcast.greensoftware.foundation - me interviewing experts in this field�branch.climateAction.tech - an online magazine all about this stuff��P.S. Come to my workshop on Friday to level up in Greening Digital with Django
64
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION