Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
A Brief History of Channels
Search
Andrew Godwin
March 31, 2016
Programming
2
2.5k
A Brief History of Channels
A talk I gave at DjangoCon Europe 2016
Andrew Godwin
March 31, 2016
Tweet
Share
More Decks by Andrew Godwin
See All by Andrew Godwin
Reconciling Everything
andrewgodwin
1
280
Django Through The Years
andrewgodwin
0
180
Writing Maintainable Software At Scale
andrewgodwin
0
410
A Newcomer's Guide To Airflow's Architecture
andrewgodwin
0
330
Async, Python, and the Future
andrewgodwin
2
630
How To Break Django: With Async
andrewgodwin
1
700
Taking Django's ORM Async
andrewgodwin
0
700
The Long Road To Asynchrony
andrewgodwin
0
620
The Scientist & The Engineer
andrewgodwin
1
730
Other Decks in Programming
See All in Programming
The Price of Micro Frontends… and Your Alternatives @bastacon 2025 in Frankfurt
manfredsteyer
PRO
0
360
15分で学ぶDuckDBの可愛い使い方 DuckDBの最近の更新
notrogue
3
910
研究開発と実装OSSと プロダクトの好循環 / A virtuous cycle of research and development implementation OSS and products
linyows
1
120
OUPC2024 Day 1 解説
kowerkoint
0
330
Node.js, Deno, Bun 最新動向とその所感について
yosuke_furukawa
PRO
5
2.4k
機能が複雑化しても 頼りになる FactoryBotの話
tamikof
1
280
Generative AI for Beginners .NETの紹介
tomokusaba
1
190
AI Agentを利用したAndroid開発について
yuchan2215
0
150
Devin入門 〜月500ドルから始まるAIチームメイトとの開発生活〜 / Introduction Devin 〜Development With AI Teammates〜
rkaga
5
2k
イベントソーシングによってインピーダンスミスマッチから解放された話
tkawae
1
120
AIエージェントを活用したアプリ開発手法の模索
kumamotone
1
160
Accelerate your key learnings of scaling modern Android apps
aldefy
0
110
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Product Roadmaps are Hard
iamctodd
PRO
51
11k
Into the Great Unknown - MozCon
thekraken
35
1.7k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.6k
Writing Fast Ruby
sferik
628
61k
It's Worth the Effort
3n
184
28k
Stop Working from a Prison Cell
hatefulcrawdad
268
20k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
50
2.3k
Bash Introduction
62gerente
611
210k
Typedesign – Prime Four
hannesfritz
41
2.5k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2.1k
Transcript
Andrew Godwin @andrewgodwin BRIEF HISTORY of CHANNELS A
Andrew Godwin Hi, I'm Django core developer Senior Software Engineer
at Likes networking a little bit too much
Channels
Channels?
WebSocket
HTTP 1 request response Browser Server request response request response
request response
HTTP 2 request response Browser Server request response request 1
response 2 request 2 response 1
WSGI request response Browser Server Django call app return val
WebSockets receive send Browser Server send receive send send
receive send Browser Server send receive send send Django ?
Hard to deadlock Built-in authorisation Scales down Widely deployable Optional
Django is not built for this.
But what if it was?
Instead of requests, we have events
Events of the same type are grouped on a named
channel
HTTP requests HTTP responses WebSocket connecteds WebSocket frames received WebSocket
frames sent WebSocket disconnections
A channel is a: named, first-in-first-out, at-most-once, non-broadcast, network-transparent queue
of messages
http.request Protocol Server Worker Server http.response websocket.connect websocket.send websocket.receive websocket.send
websocket.send
Responses are on single-reader channels (http.response!1A2B3C)
You can send onto channels from anywhere
How do you use it?
View request response callable
Consumer event event callable event event
Every message on a channel runs the consumer function
http.request routes to a view system consumer
def ws_message(message): # Get things from message data = json.loads(message['text'])
# Use ORM like normal MyModel.objects.create( value=data['value'], ) # Send a reply and close socket message.reply_channel.send({ 'text': 'OK', 'close': True, })
routing.py: urls.py for Channels
message.user: like request.user
message.channel_session: per-socket sessions
Groups broadcast/pub-sub
Add a channel to a Group Remove a channel from
a Group Send to a Group
Worked Examples github.com/andrewgodwin/channels-examples
Liveblog http.request Django view layer websocket.connect Add to liveblog Group
websocket.disconnect Remove from liveblog Group <Article.save> Send notification to liveblog
Chat http.request Django view layer websocket.receive Either add to room
Group or send to chat_messages websocket.disconnect Remove from room Groups chat_messages Send to room Groups
It's so easy to join! CALL NOW
Things I didn't even get to: Replacing WSGI Pluggable channel
backends Sharding and scaling It's still just runserver
A base for the future Scheduler? Retry logic? Generic Consumers?
...and much more
1.10 "Provisional"?
1.8 1.9 pip install channels
channels.readthedocs.com github.com/andrewgodwin/channels-examples
Thanks. Andrew Godwin @andrewgodwin