Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Architecting with Channels
Search
Andrew Godwin
July 19, 2016
Programming
1.2k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Architecting with Channels
My keynote from DjangoCon US 2016.
Andrew Godwin
July 19, 2016
More Decks by Andrew Godwin
See All by Andrew Godwin
Reconciling Everything
andrewgodwin
1
410
Django Through The Years
andrewgodwin
0
340
Writing Maintainable Software At Scale
andrewgodwin
0
550
A Newcomer's Guide To Airflow's Architecture
andrewgodwin
0
430
Async, Python, and the Future
andrewgodwin
2
760
How To Break Django: With Async
andrewgodwin
1
840
Taking Django's ORM Async
andrewgodwin
0
870
The Long Road To Asynchrony
andrewgodwin
0
780
The Scientist & The Engineer
andrewgodwin
1
870
Other Decks in Programming
See All in Programming
Agents on Rails - Rails at Scale 2026
irinanazarova
0
310
App Intentsのビルドプロセスを支える技術
kntkymt
0
490
Ghostty + Neovimで作る 透明でカッコ良い開発環境
j341nono
0
150
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
3.1k
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
400
wkhtmltopdfの次どうするか問題2026
willnet
2
1.8k
Are APIs Still Relevant in the AI Era?
soyuka
0
390
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
1k
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
810
Workers Cache を知る
syumai
0
320
Omarchy Tokyo やると聞いて UMPC 買ってセットアップしてきた
mtsmfm
0
200
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
460
Featured
See All Featured
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
390
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
[SF Ruby Conf 2025] Rails X
palkan
3
1.4k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
250
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
690
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1k
Code Review Best Practice
trishagee
74
20k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
420
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
Site-Speed That Sticks
csswizardry
13
1.5k
Transcript
None
Andrew Godwin Hi, I'm Django core developer Senior Software Engineer
at Used to complain about migrations a lot
2010
WebSockets
WebSockets (and Eventlet)
2012
None
2014
"django-onair"
2015
Channels
Born from WebSockets
Born from WebSockets Expanded to be more
The "real hard problem"
Asynchronous coordination
Why?
WebSockets don't magically solve everything
Architecture is about tradeoffs
Bidirectional, low overhead Complex client-side, compatibility CONS PROS
Streaming updates Chat applications Collaborative editing Game backends
Broadcast
Server Client 1 Client 2 Client 3 Client 4
Server Client 1 Client 2 Client 3 Client 4 Server
Server Client 1 Client 2 Client 3 Client 4 Server
The "hard problem"
Channels is a foundation for runnng 'async' at scale
WebSockets Task offloading Chat/Email integration IoT protocols
What makes it hard?
Stateful connections Internal network Bottlenecks
Server Server Django Script ASGI "Send to channel X" "Receive
from channel X" "Send to group Y" "Add channel X to group Y" "Remove channel X from group Y"
Server Server Django Script ASGI ASGI ASGI ASGI Redis
Server Server Django Script ASGI ASGI ASGI ASGI Shared Memory
Server Server Django Script ASGI ASGI ASGI ASGI Shared Memory
Redis Redis
bit.ly/asgi-spec
Channels wraps the low-level ASGI operations
Think of it as the "Django bit" of a larger
whole.
Daphne HTTP/WebSocket Server Channels Django integration asgi-redis Redis backend asgi-ipc
Local memory backend asgiref Shared code and libs
What does Channels provide? Routing Consumers Sessions Auth Helpers By
channel, URL, etc. Standardised message handling Cross-network persistence on sockets Including HTTP cookies on WebSocket runserver, runworker, debugging info
Putting it to use Let's make a chat!
Consumers def on_connect(message): Group("chat").add(message.reply_channel) def on_receive(message): Group("chat").send({"text": message["text"]}) def on_disconnect(message):
Group("chat").discard(message.reply_channel) websocket.connect websocket.receive websocket.disconnect
Routing from channels import route routing = [ route("websocket.connect", on_connect),
route("websocket.receive", on_receive), route("websocket.disconnect", on_disconnect) ]
Class-based from channels import route_class routing = [ route_class(ChatConsumer), ]
from channels.generic.websockets class ChatConsumer(WebsocketConsumer): def connection_groups(self): return ["chat"] def receive(self, text): self.group_send("chat", text=text) Routing
Full worked example github.com/andrewgodwin/channels-examples
Liveblog
Liveblog
Data Binding Multiplexing &
class IntegerValue(models.Model): name = models.CharField(max_length=100, unique=True) value = models.IntegerField(default=0) class
IntegerValueBinding(WebsocketBinding): model = IntegerValue stream = "intval" def check_permission(self, user, action, instance): return True def group_names(self, instance, action): return ["binding.values"]
Demo Do I dare?
More in channels-examples!
Custom Protocols
Decompose into messages Email email.send, email.receive Slack slack.receive, slack.send, slack.joined,
... MQTT mqtt.subscribe, mqtt.unsubscribe, mqtt.send, ...
Write a custom server Use asyncio, Twisted, Gevent, etc Server
takes path to ASGI channel layer instance (CLI/config file) Roll layer.send, layer.receive_many into your event loop
Write Django consumers Same codebase as the main project Optional
routing/per-worker channel limiting
IRC Worker ASGI Worker Worker Email MQTT Scheduler HTTP/WS Custom
Daemon
Channels is a tool for you to use
There's more to be done (and some funding for it)
1995 You are a desktop app 2005 You are a
website 2015 You are a rich web/mobile app 2025 ?
What are the goals of a framework? Do we adapt?
Let's keep Django and Python a great choice for complex
backends
Thanks. Andrew Godwin @andrewgodwin channels.readthedocs.io github.com/andrewgodwin/channels-examples