1 of 64

Greening Digital �With Django

www.thegreenwebfoundation.org

Chris

Adams

2024.06.05

DjangoconEU 2024

1

GREEN WEB FOUNDATION

2 of 64

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

3 of 64

What we’ll cover

3

  1. How carbon emissions result from our use digital services, and why people are paying more attention
  2. How they are measured and estimated, and common tools used to do so
  3. Why Django is well placed to be the greenest framework out there.

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

4 of 64

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

5 of 64

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

6 of 64

Build open source tools, APIs, and libraries

6

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

7 of 64

Create prototypes.

Contribute to open source projects.

Publish open data.

7

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

8 of 64

Collaborate with research institutions

8

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

9 of 64

Publish reports, magazines, guides about this field.

If you found this talk interesting, you’ll like Branch

9

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

10 of 64

Talks.

Workshops.

Training.

Consulting.

10

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

11 of 64

How digital causes emissions, and why measure it

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

12 of 64

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

13 of 64

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 of 64

14

Credit: Photo by Skyler Smith on Unsplash

GREEN WEB FOUNDATION

15 of 64

15

Credit: Photo by Andy Li on Unsplash

GREEN WEB FOUNDATION

16 of 64

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

17 of 64

How does this affect me though?

(apart from the whole climate anxiety thing, obvs)

GREEN WEB FOUNDATION

18 of 64

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

19 of 64

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

20 of 64

Driving Climate Disclosure

20

liberté�egalité�CSRDé

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

21 of 64

  • Purchased goods and services
  • Capital goods
  • Fuel- and energy-related activities (not included in scope 1 or scope 2)
  • Upstream transportation and distribution
  • Waste generated in operations
  • Business travel
  • Employee commuting
  • Upstream leased assets

Scope 3

Scope 1

  • Fuel combustion
  • Company vehicles
  • Fugitive emissions
  • Purchased electricity
  • Purchased cooling
  • Purchased heat
  • Purchased steam

Scope 2

  • Downstream transportation and distribution
  • Processing of sold products
  • Use of sold products
  • End-of-life treatment of sold products
  • Downstream leased assets 14. Franchises
  • Investments

Scope 3

Upstream

Directly reported

Downstream

GHG Protocol and Scoped Emissions Reporting

GREEN WEB FOUNDATION

22 of 64

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

23 of 64

  • Purchased goods and services
  • Capital goods
  • Fuel- and energy-related activities (not included in scope 1 or scope 2)
  • Upstream transportation and distribution
  • Waste generated in operations
  • Business travel
  • Employee commuting
  • Upstream leased assets

Scope 3

Scope 1

  • Fuel combustion
  • Company vehicles
  • Fugitive emissions
  • Purchased electricity
  • Purchased cooling
  • Purchased heat
  • Purchased steam

Scope 2

  • Downstream transportation and distribution
  • Processing of sold products
  • Use of sold products
  • End-of-life treatment of sold products
  • Downstream leased assets 14. Franchises
  • Investments

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

24 of 64

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

25 of 64

Driving Climate Response

25

“Show us you have a plan informed by the science”

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

26 of 64

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

27 of 64

How people estimate carbon emissions for digital

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

28 of 64

All models are wrong, some models are useful.

GEORGE BOX

Empirical Model-Building and Response Surfaces, 1987

28

GREEN WEB FOUNDATION

29 of 64

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

30 of 64

Usage based

30

Component view

System view

Global view

Billing based

“Native”

3rd party

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

31 of 64

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

32 of 64

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

33 of 64

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

34 of 64

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

35 of 64

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

36 of 64

What these tools look like

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

37 of 64

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

38 of 64

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

39 of 64

Who has used a website carbon calculator before?

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

40 of 64

Website Carbon by Wholegrain Digital

Uses:

Sustainable Web Design with Green Web Dataset

40

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

41 of 64

WebPageTest by Catchpoint

Uses:

Sustainable Web Design through CO2.js and Green Web Dataset

41

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

42 of 64

An intro to CO2.js

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

43 of 64

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

44 of 64

Who’s using CO2.js today?

  • WebPageTest
  • Mozilla Firefox Profiler
  • Ecograder
  • Sitespeed
  • Datavizta (by Boavizta)
  • … and many more

44

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

45 of 64

What can you do with CO2.js?

  • Use peer reviewed models for calculating carbon from usage.
  • Access open grid intensity data by country.
  • Check if a website is hosted green using the Green Web Dataset.

45

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

46 of 64

How do they use it?

WebPageTest Carbon Control

Programming language: �PHP

Code: �GitHub

46

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

47 of 64

How do they use it?

Mozilla Firefox Profiler

Programming language: �JavaScript

Code: �GitHub

47

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

48 of 64

Green Metrics Tool Full stack measurements

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

49 of 64

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

50 of 64

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

51 of 64

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

52 of 64

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

53 of 64

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

54 of 64

Learning from a real example - entire lifecycle

Seeing the output for by scenario

54

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

55 of 64

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 of 64

56

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

57 of 64

Learning from a real example - putting the SCI in CI

Tracking Software Carbon Intensity in Continuous Integration

57

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

58 of 64

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

59 of 64

Code Carbon: Pythonic Server-side

carbon stats

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

60 of 64

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

61 of 64

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

62 of 64

Why Django is well placed to be the greenest framework out there

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

63 of 64

Why is Django well placed to lead in greening digital?

63

  1. Versatility of the framework - very wide range of use cases at different scales.
  2. Mature, pragmatic community - well-run open source projects sharing knowledge, collaborating with others. Python might not be fast, but it is productive and can call fast code.
  3. Long history of experience and expertise - the first online carbon calculators were built with Django in 2007 (!), we have active community members who know climate and energy really well
  4. Green is literally the most prominent colour on the django website: duh.

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

64 of 64

Thanks!I’ll be at the sprints, and this deck is online.

bit.ly/djangocon-eu-2024-greening-digital

chris@greenweb.org

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