Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Django and the Real-time Web

Django and the Real-time Web

The modern Web—indeed, the modern user—demands that we write applications that work faster than the traditional request/response cycle. But how relevant is Django in the age of pjax, node.js and WebSockets? I believe Django remains a powerful utility in the new Web, and in this talk I'll share some techniques and tools for reducing the complexity of real-time applications. I'll explain how I manage code duplication when key business logic is split between the client and the server, and demonstrate ways to preserve a RESTful and accessible design whilst providing a more responsive experience to clients who support it.

Zachary Voase

June 04, 2012
Tweet

More Decks by Zachary Voase

Other Decks in Technology

Transcript

  1. 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
  2. “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!”
  3. • UI before technology • Proactive, not reactive • Synchronized

    with the ‘real world’ What I Talk About When I Talk About Real-Time
  4. MVC

  5. MVC • Trygve Reenskaug et al. @ PARC, ’78/79 •

    Originally a part of Smalltalk-80 • Now the dominant UI design pattern
  6. 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
  7. 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
  8. WebSocket(s) • Real TCP connection • ‘Magic’ HTTP request to

    port 80 • Reduces latency • Enables real-time push
  9. REST & WebSockets • Full-duplex communication: client-server • Long-running connections:

    stateless • Direct TCP connection: layered, cacheable • Ad hoc protocols over WS: uniform
  10. C V M C V M C V M Server

    Bob Alice PUT /polls/123 PUT /polls/123
  11. C V M C V M C V M Server

    Bob Alice PUT /polls/123 PUT /polls/123
  12. C V M C V M C V M Server

    Bob Alice PUT /polls/123 PUT /polls/123
  13. 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