Django and the
Real-Time Web
Zachary Voase
DjangoCon Europe 2012
Slide 2
Slide 2 text
WWW: A Changelog
IE
Chrome
0%
35.0%
70.0%
Jul 2008 Apr 2009 Jan 2010 Oct 2010 Jul 2011 Apr 2012
gs.statcounter.com
WebSocket
Backbone
#NewTwitter
Google Instant
Basecamp Next
NodeJS
pjax
Google Wave
Facebook
socket.io
Chrome Nitro JägerMonkey
Trello
Slide 3
Slide 3 text
“Now, here, you see, it takes all the
running you can do, to keep in the
same place. If you want to get
somewhere else, you must run at
least twice as fast as that!”
Slide 4
Slide 4 text
• UI before technology
• Proactive, not reactive
• Synchronized with the ‘real world’
What I Talk About When I
Talk About Real-Time
Slide 5
Slide 5 text
Three Stories
Slide 6
Slide 6 text
MVC
Slide 7
Slide 7 text
MVC
• Trygve Reenskaug et al. @ PARC, ’78/79
• Originally a part of Smalltalk-80
• Now the dominant UI design pattern
Slide 8
Slide 8 text
MVC
Controller
View
Model
Slide 9
Slide 9 text
Multi-MVC
C
V
M
C
V
M
C
V
M
Slide 10
Slide 10 text
MVC
• Start application
• Within event loop:
• Receive user and network events
• Dispatch to controller
• Read/write to models
• Render views to display
• Shut down application
Slide 11
Slide 11 text
MVC on the Web
Controller
View
Model
Server
Browser
Slide 12
Slide 12 text
MVC on the Web
• Listen for requests:
• Load session state for this user:
• Process forms & user input
• Read/write to/from database
• Render views (HTML, XML, JSON)
• Return response
• Persist session state, clean up objects
Slide 13
Slide 13 text
REST
Slide 14
Slide 14 text
REST
• REpresentational State Transfer
• Roy T. Fielding, 2000 (§5)
• Descriptive, not prescriptive
Conflict Resolution
if not uri:
CREATE
elif is_dirty: # I've made local changes
if local_etag == remote_etag:
OK
else:
CONFLICT
else:
if local_etag == remote_etag:
NOOP
else:
REDOWNLOAD