1 of 52

Greening Digital �With Django

(abridged)

www.thegreenwebfoundation.org

Chris

Adams

2024.06.27

Django User Group Berlin

1

GREEN WEB FOUNDATION

2 of 52

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 52

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 52

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 52

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 52

Build open source tools, APIs, and libraries

6

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

7 of 52

Create prototypes.

Contribute to open source projects.

Publish open data.

7

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

8 of 52

Talks.

Workshops.

Training.

Consulting.

8

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

9 of 52

How digital causes emissions, and why measure it

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

10 of 52

How do digital services cause emissions?

GREEN WEB FOUNDATION

10

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

11 of 52

Estimates vary, but between 2% and 4% of global carbon emissions is safe to use.

GREEN WEB FOUNDATION

11

How big is tech’s carbon footprint?

Source: https://www.thegreenwebfoundation.org/publications/report-fog-of-enactment/

GREEN WEB FOUNDATION

12 of 52

12

Credit: Photo by Skyler Smith on Unsplash

GREEN WEB FOUNDATION

13 of 52

13

Credit: Photo by Andy Li on Unsplash

GREEN WEB FOUNDATION

14 of 52

The internet is the biggest machine in the world, and today, it mostly runs on fossil fuels.

GREEN WEB FOUNDATION

14

Source: https://www.thegreenwebfoundation.org/publications/report-fog-of-enactment/

GREEN WEB FOUNDATION

15 of 52

How does this affect me though?

(apart from the whole climate anxiety thing, obvs)

GREEN WEB FOUNDATION

16 of 52

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

17 of 52

Driving Climate Disclosure

17

“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

18 of 52

Driving Climate Disclosure

18

liberté�egalité�CSRDé

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

19 of 52

  • 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

20 of 52

How I remember the Greenhouse Gas Protocol

Greenhouse Gas Protocol:

Scope 1,

Scope 2,

Scope 3

20

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

21 of 52

  • 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

22 of 52

Driving Climate Response

22

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

Corporate Supply Chain Due Diligence Directive (CSDDD)

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

23 of 52

Driving Climate Response

23

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

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

24 of 52

Emerging Standards: Software Carbon Intensity

Think of “carbon emitted per activity”.

CO2e per page request

CO2e per CI run

CO2e per LLM query

CO2e per ad impression

Created by the Green Software Foundation - with a freely available spec. Developed in the open on GitHub.

24

https://sci.greensoftware.foundation

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

25 of 52

Emerging Standards: Software Carbon Intensity

25

Now a recognised ISO standard, as of March 2024

https://www.iso.org/standard/86612.html

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

26 of 52

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 our plans to reduce it when asked

GREEN WEB FOUNDATION

27 of 52

How people estimate carbon emissions for digital

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

28 of 52

All models are wrong, some models are useful.

GEORGE BOX

Empirical Model-Building and Response Surfaces, 1987

28

GREEN WEB FOUNDATION

29 of 52

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 data into emissions data.

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

30 of 52

Usage based tooling

30

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 for server side measurements.

Scaphandre:

Rust, gives server-side per process figures for every process running.

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

Common to start experimenting with these first.

(All use sustainable web model under the hood))

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

31 of 52

Billing based tooling

31

Native

Third party

Microsoft Emissions Impact Dashboard

Scopes 1, 2 and 3

AWS Customer Carbon Footprint Tool

Scopes 1, 2 (no scope 3- can make up to 99% of emissions in some cases)

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)

Native have better access to data about underlying infra.�

3rd party options have more compatible across providers, and are often easier to trust (!)

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

32 of 52

What these tools look like

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

33 of 52

Starting out:

My suggestions for fellow Django users

33

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

(All use sustainable web design model under the hood))

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

34 of 52

Website Carbon by Wholegrain Digital

Website Carbon is a usage based, global view tool.

Easy to use and explain to people new to the field.

34

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

35 of 52

WebPageTest by Catchpoint

Web Page Test is a usage based, global view tool.

Open source, offers more detail than Website Carbon.

See the issue that lead to this being built.

35

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

36 of 52

Firefox Profiler by Mozilla Firefox

Firefox Profiler is a usage based, component view tool.

Open source - see our PR that added this :)��Might already be installed on your laptop (!)

36

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

37 of 52

Code Carbon by MILA and others

CodeCarbon is a usage based, component view tool for measuring carbon emissions for python code

Most common library used in AI papers for tracking carbon emissions of training.��Also pythonic: provides context managers and decorators

💚

from codecarbon import EmissionsTracker

�tracker = EmissionsTracker()

tracker.start()

�try:

# Compute intensive code goes here

_ = 1 + 1

finally:

tracker.stop()

37

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

38 of 52

Green Metrics Tool by Green Coding Solutions

GMT is a usage based, system view tool,

It creates a system comprised of instrumented docker containers, executes common use cases, and shows resource impacts.

See also: Extensive real-world example with Django Wagtail (and workshop at end of this talk)

38

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

39 of 52

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

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

40 of 52

Why is Django well placed to lead in greening digital?

40

  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

41 of 52

Thanks!

Follow this link for the deck, and an afternoon’s worth workshop of activities

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 - I interview experts in this field to share what they know�branch.climateAction.tech - an online magazine all about this stuff

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

42 of 52

Extra bonus bits

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

43 of 52

Green Metrics Tool Full stack measurements

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

44 of 52

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

44

Component view

System view

Global view

Usage based

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

45 of 52

How GMT works at very high level

Use docker to set up a system, and record metrics from “the outside”

45

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

46 of 52

What can you do with GMT?

Try different usage scenarios for your service - static vs dynamic, different page designs, etc.

46

https://www.green-coding.io/case-studies/wordpress-vs-hugo-cloudflare/

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

47 of 52

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

47

Django app

Postgres

Browser

docker-compose.yaml

Redis

usage_scenario.yaml

+

scripts to drive the browser

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

48 of 52

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

48

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

49 of 52

Learning from a real example - entire lifecycle

Seeing the software carbon intensity for each usage scenario

49

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

50 of 52

Learning from a real example - putting the SCI in CI

Tracking Software Carbon Intensity in Continuous Integration

50

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

51 of 52

Learning from a real example

Figuring out what to do next.

This is roadmap is entirely open source, and actively worked on again this Google Summer of Code.

51

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION

52 of 52

Thanks!

Follow this link for the deck, and an afternoon’s worth workshop of activities

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 - I interview experts in this field to share what they know�branch.climateAction.tech - an online magazine all about this stuff

GREEN WEB FOUNDATION

GREEN WEB FOUNDATION