Top Banner
Building RealTime Web Applica4ons Tony AbouAssaleh & Mark Dineen October 22, 2013 Volta Labs
42

Building Real-Time Web Applications

Jan 24, 2015

Download

Technology

This is a hands-on workshop that will teach you how to build a Web application that incorporate real-time communication between the client application running on the browser and the back-end server.

We will start with an overview of technologies and tools available for building real-time Web apps, what’s involved, the basics, and the gotchas. Next, we will build, in real-time, a real-time chat application using the python (Tornado) + socket.io + Backbone stack. Why not Node.js, you might ask. Simple: it’s too easy, too popular, and and not super-stable or secure. But you’re welcome to use Node.js as the backend in your own apps!
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Building Real-Time Web Applications

Building  Real-­‐Time  Web  Applica4ons  

Tony  Abou-­‐Assaleh  &  Mark  Dineen  October  22,  2013  

Volta  Labs  

Page 2: Building Real-Time Web Applications

Agenda  

•  What  is  real-­‐time  web  •  The  stack  •  Client-­‐side  •  Server-­‐side  •  The  Flow  •  Beyond  the  basics  •  Live  Tutorial  

Copyright  (c)  2013  TitanFile  Inc.   2  

Page 3: Building Real-Time Web Applications

Who  we  are  

•  Tony  Abou-­‐Assaleh  – PhD  in  Computer  Science  from  Dal  – Cofounder  and  CEO,  TitanFile  – Ex-­‐Google,  VP  Tech  /  R&D  Director  @  GenieKnows  

– Developed  the  initial  real-­‐time  components  of  TitanFile  

– Core  member  of  Backbone  Marionette  Team  

Copyright  (c)  2013  TitanFile  Inc.   3  

Page 4: Building Real-Time Web Applications

Who  we  are  

•  Mark  Dineen  – CTO,  TitanFile  – Made  RT  in  TitanFile  fast  and  secure  – Director  of  IT  at  Allianz  – Compliance  and  security  veteran  – Contributor  at  OWASP.org    

Copyright  (c)  2013  TitanFile  Inc.   4  

Page 5: Building Real-Time Web Applications

What  is  Real-­‐Time  Web?  

Copyright  (c)  2013  TitanFile  Inc.   5  

Page 6: Building Real-Time Web Applications

What  is  Real-­‐Time  Web?  Copyright  (c)  2013  TitanFile  Inc.   6  

Page 7: Building Real-Time Web Applications

What  is  Real-­‐Time  Web?  

•  Saves  to  the  database  ≠  real-­‐time  Web  •  Periodic  refresh  ≠  real-­‐time  Web  •  Real-­‐time  computing  ≠  real-­‐time  Web  •  Real-­‐time  streaming  ≠  real-­‐time  Web  

Copyright  (c)  2013  TitanFile  Inc.   7  

Page 8: Building Real-Time Web Applications

What  is  Real-­‐Time  Web?  

A  set  of  technologies  and  practices  that  enable  users  to  receive  information  as  soon  as  it  is  

published  by  its  authors,  rather  than  requiring  that  they  or  their  software  check  a  source  

periodically  for  updates.  

Copyright  (c)  2013  TitanFile  Inc.   8  

Page 9: Building Real-Time Web Applications

What  is  Real-­‐Time  Web?  

•  Dynamic  user  interface  •  Server-­‐side  push  •  Event-­‐driven  •  Asynchronous  

Copyright  (c)  2013  TitanFile  Inc.   9  

Page 10: Building Real-Time Web Applications

Applica4on  of  RT  Web  

•  Chat,  communication  •  Collaboration  •  Co-­‐editing,  co-­‐browsing,  co-­‐shopping  •  Dashboards  and  monitoring  •  Gaming  •  Social  Web  •  Date  Streaming  

Copyright  (c)  2013  TitanFile  Inc.   10  

Page 11: Building Real-Time Web Applications

The  Stack  

Copyright  (c)  2013  TitanFile  Inc.   11  

Page 12: Building Real-Time Web Applications

Copyright  (c)  2013  TitanFile  Inc.   12  

Page 13: Building Real-Time Web Applications

The  Stack  

•  Asynchronous,  dynamic  client  •  HTML5  WebSockets  

 

•  Asynchronous  backend  server  

Copyright  (c)  2013  TitanFile  Inc.   13  

Page 14: Building Real-Time Web Applications

The  Stack  @  TitanFile  

Client   Server  

Dispatcher  

TornadIO2  

Copyright  (c)  2013  TitanFile  Inc.   14  

Page 15: Building Real-Time Web Applications

Client-­‐Side  Stack  

Copyright  (c)  2013  TitanFile  Inc.   15  

Page 16: Building Real-Time Web Applications

Transport  Op4ons  -­‐  Comet  

•  HTML5  WebSockets  •  Flash  Socket  •  Long  Polling  –  IFrame  – Ajax  – XMLHttpRequest  –  JSONP  

Copyright  (c)  2013  TitanFile  Inc.   16  

Page 17: Building Real-Time Web Applications

Cross-­‐origin  resource  sharing  (CORS)  

Copyright  (c)  2013  TitanFile  Inc.   17  

Page 18: Building Real-Time Web Applications

Polling  vs.  WebSockets  

Copyright  (c)  2013  TitanFile  Inc.   18  

Page 19: Building Real-Time Web Applications

WebSocket  Handshake  

Copyright  (c)  2013  TitanFile  Inc.   19  

Page 20: Building Real-Time Web Applications

WebSocket  Op4ons  

•  Plain  HTML5  WebSockets    •  SockJS  

•  Socket.io  

Copyright  (c)  2013  TitanFile  Inc.   20  

Page 21: Building Real-Time Web Applications

HTML5  WebSockets  

•  Open  Connection  •  Send  message  •  On  message  event  •  Close  connection  

Copyright  (c)  2013  TitanFile  Inc.   21  

Page 22: Building Real-Time Web Applications

SockJS  

•  WebSocket  Emulator  •  Follows  HTML5  WebSocket  API  •  Cross-­‐domain  support  •  Polling  as  fallback  

Copyright  (c)  2013  TitanFile  Inc.   22  

Page 23: Building Real-Time Web Applications

Socket.IO  

•  Real-­‐time  Web  App  Protocol  •  Event-­‐based  communication  – Connection  events  – Named  events  

•  Broadcast  •  Cross-­‐browser  and  platform  •  Server-­‐side  (Node.JS)  and  client-­‐side  

Copyright  (c)  2013  TitanFile  Inc.   23  

Page 24: Building Real-Time Web Applications

Server-­‐Side  Stack  

Copyright  (c)  2013  TitanFile  Inc.   24  

Page 25: Building Real-Time Web Applications

Real-­‐Time  Web  Servers  

•  Most  modern  languages  …  

•  Many  modern  frameworks  …  – NodeJS  – Tornado  

Copyright  (c)  2013  TitanFile  Inc.   25  

Page 26: Building Real-Time Web Applications

The  Flow  

Copyright  (c)  2013  TitanFile  Inc.   26  

Page 27: Building Real-Time Web Applications

Copyright  (c)  2013  TitanFile  Inc.   27  

Page 28: Building Real-Time Web Applications

Copyright  (c)  2013  TitanFile  Inc.   28  

Page 29: Building Real-Time Web Applications

More  Detailed  (Useful)  Flow  

Copyright  (c)  2013  TitanFile  Inc.   29  

Page 30: Building Real-Time Web Applications

Copyright  (c)  2013  TitanFile  Inc.   30  

Page 31: Building Real-Time Web Applications

Copyright  (c)  2013  TitanFile  Inc.   31  

Page 32: Building Real-Time Web Applications

Pub  Sub  PaPern  

•  Decouples  senders  from  receivers  •  Intermediate  hub  •  Senders  –  publish  messages  to  a  channel  •  Receivers  –  subscribe  to  a  channel  

Copyright  (c)  2013  TitanFile  Inc.   32  

Page 33: Building Real-Time Web Applications

The  Flow  @  TitanFile  

Copyright  (c)  2013  TitanFile  Inc.   33  

User  Action  

Backbone  Model  Saved  

ioSync  Socket.io  

TornadIO2  Dispatcher  

Django  Handler  

Django  Model  Saved  

Django  post_save  

Django  signal  handler  

TorandIO2  Broadcast  

ioBind  Socket.io  

Backbone  handler  

Render  changes  

Sender  Client   Server   Recipient  Client  

Page 34: Building Real-Time Web Applications

Beyond  the  Basics    

Real-­‐World  Challenges  

Copyright  (c)  2013  TitanFile  Inc.   34  

Page 35: Building Real-Time Web Applications

Real  World  Challenges  

•  Authentication  •  Security  •  Binary  Data  (Files)  •  Blocking  Code  – Database,  File  I/O,  Network  

•  Scalability  

Copyright  (c)  2013  TitanFile  Inc.   35  

Page 36: Building Real-Time Web Applications

Authen4ca4on  

Copyright  (c)  2013  TitanFile  Inc.   36  

Page 37: Building Real-Time Web Applications

Security  

Copyright  (c)  2013  TitanFile  Inc.   37  

Page 38: Building Real-Time Web Applications

Binary  Data  

Copyright  (c)  2013  TitanFile  Inc.   38  

Page 39: Building Real-Time Web Applications

Blocking  Code  

Copyright  (c)  2013  TitanFile  Inc.   39  

Page 40: Building Real-Time Web Applications

Scalability  

Copyright  (c)  2013  TitanFile  Inc.   40  

Page 41: Building Real-Time Web Applications

Live  Tutorial  

https://github.com/mdineen/chatserver  

Copyright  (c)  2013  TitanFile  Inc.   41  

Page 42: Building Real-Time Web Applications

Tony  Abou-­‐Assaleh  &  Mark  Dineen  https://www.titanFile.com  {taa,mark}@titanFile.com  

Twitter:  @tony_aa,  @DineenMa