3. WHAT ARE REAL-TIME WEB APPS?
• Allows users to receive information as soon
as it is published
• Bi-directional communication between
clients & server
• Both pull and push based systems
4. EXAMPLES & APPLICATIONS
• Gmail
• Facebook
• Twitter
• Chat Services
• Online Gaming
• Notification and signaling
• Shows live data
• Easy collaboration
11. AJAX REQUEST
• Window.open()
• HTTP Request browser will stop or hang for the server
response
• Xmlhttp.open()
• Ajax request is Async, java script does not have to wait
for the server response, so it can execute other scripts
and respond to user events while waiting for server
response
12. CONS OF “HACKS”
•http web server timeouts
•Too many connections
•Too much overhead
•Only a workaround and not a
native solution
14. WEBSOCKET PERFORMANCE
• Each HTTP Request/Response (header + body) have
minimum of 871 Bytes over head
• WebSocket frames has 2 Bytes of over head
• 1000 HTTP Clients polling per second = 6.6Mbps
Network throughput
• 1000WebSocket Clients receiving messages per second =
0.015Mbps Network throughput
21. WEBSOCKET & MESSAGING LIBRARIES
FEATURES
• heartbeats / keep alive calls
these are tiny messages that are send on pre-defined intervals.They
make sure that the other side is still responsive and prevent certain
network constructs like proxies or firewalls from cutting your
connection due to inactivity.
• reconnecting
if your connection drops, you want it to be re-established. Some
libraries also queue messages while the connection is down and
resend them once it becomes available again.
22. WEBSOCKET & MESSAGING LIBRARIES
FEATURES
• http fallback
if WebSockets are not available, some libraries fall back
to http long polling and other techniques to mimic bi-
directional communication (collectively known as
"comet"). Depending on your target audience this might
not be a necessity, but is still a good choice if your app
needs to be available within large corporate
infrastructures.
23. WEBSOCKET LIBRARIES
• engine.io
Engine.io is the transport layer that powers socket.io, but can
also be used as a standalone library. It incorporates a few
unusual design choices, such as starting with http long-polling to
ensure immediate connectivity and only upgrade the connection
to websocket a bit later.
• WS
A solid, barebone WebSocket server for node.js Used by
engine.io
• SockJS
A fast JavaScript / Node.js abstraction layer for websockets,
supporting a number of fallback techniques
24. WEBSOCKET LIBRARIES
• Tornado
Tornado is a general purpose networking library for
Python, offeringWebsocket abstractions and fallbacks.
• web-socket-js
Flash based websocket implementation
• libwebsocket
Really fast websocket implementation in low level C.
• Fleck
Fleck is a WebSocket implementation in C#
25. WEBSOCKET LIBRARIES
• Atmosphere
Atmosphere is a general websocket abstraction layer for
JVM compatible languages. It's focused to run on Java and
J2EE application servers and comes with an ecosystem of
extension points to connect it to caches like Redis or
Hazelcast.
• Java Web Socket
Exactly what the name suggests
26. WEBSOCKET LIBRARIES
• Mojolicious
A websocket implementation with fallbacks for Perl
• SignalR
WebSocket abstraction for .NET
• SuperWebSocket
TCP/Websocket library for .NET
• Plezy
WebSocket abstraction for Ruby
27. PUBLISH / SUBSCRIBE
• Real-time messaging
• Many clients subscribe to a topic (sometimes also
called an event, namespace or channel) and other
clients publish messages on that topic.This is a
simple and scalable pattern for many-to-many
communication.
28. PUBLISH / SUBSCRIBE LIBRARIES
• socket.io
Definitely the most popular. Socket.io is a Node.js library that comes
with clients in many languages. It offers direct messaging and pub-sub
based on rooms (think chat-rooms) with the ability to distribute load
across multiple nodes using a Redis server in the background.
• socket cluster
A pub-sub framework built in Node.js that focuses on load-balancing
connections across a larger cluster of processes.
• Centrifugo
A backend agnostic pub-sub system written in Go
29. PUBLISH / SUBSCRIBE LIBRARIES
• Faye
One of the first pub/sub systems around. Faye offers servers in both
Ruby and Node and implements the Bayeux Protocol, designed 2007
by the Dojo foundation. Similar to socket.io, Faye relies on Redis
pub/sub to scale across multiple nodes. It does however lack support
for Redis clusters which limits its scalability to a single Redis instance.
• Firehose.io
A simple, Ruby based pub-sub system with integration points for
Backbone and Ember.
• Phoenix Framework
Phoenix is a whole web-app framework for Erlang, but with a focus on
pub/sub via channels.
30. DATA-SYNC
• Why not Pub/Sub?
• User A changes some data and hits save.The data is send via ajax to a
server and stored in a database. The client now publishes an event,
e.g. Data-update/<some-id> .
Other clients receive this event, make an ajax request to the server
and download the updated data.
• Data-sync models your data as observable objects or tree-structures
that can be manipulated by clients and servers.
Any change to the data is immediately synchronized across all
connected clients.
• This significantly reduces request-overhead, makes applications faster
and development simpler.
31. DATA-SYNC LIBRARIES
• Horizon
RethinkDB’s Horizon - a Node.js server and associated JavaScript
client library that sits on top of RethinkDB and exposes its database
and realtime querying capabilities to browser apps.
Horizon supports authentication via openAuth and JSON webtoken
and access control viaTOML configured permissions for user groups
• FeatherJS
FeatherJS is a RESTful CRUD framework for Node build on top of
express.js that sends out events via a socket.io connection whenever
an object is created, updated or deleted, allowing clients to react
accordingly.
32. REMOTE PROCEDURE CALL (RPC) / REMOTE
METHOD INVOCATION (RMI)
not strictly a realtime concept, but more the
classical REST/HTTP request/response workflow,
mapped onto a bi-directional connection.
RPC allows you to call methods on a remote server
and process their response.This can be a powerful
concept in itself, but it becomes even more
powerful when used in conjunction with other
realtime concepts like pub/sub or data-sync
33. HYBRIDS
• In a voting system you might want to send a user’s vote as
a remote method invocation - which increment the
number of votes on a data-sync object as well as block the
voting user from voting more than once.
• For multiplayer games it can make sense to rely on simple
pub-sub messaging to update player positions whilst using
data-sync to keep track of scores.
34. HYBRIDS
• Deepstream.io
Deepstream.io is a realtime server that combines data-sync with
pub/sub and request response. It offers an open ecosystem of
connectors for databases, caches and messaging systems. Its
unobtrusive client plays well with any M*C framework and comes with
plugins for React, Polymer and other libraries.
• Meteor
Meteor is a full stack framework for realtime apps, featuring data-sync,
pub/sub, RPCs, realtime search and a host of other features. It offers a
highly structured and opinionated way to set up and connect servers
and databases, build clients and test and deploy applications. It comes
with its own, self-contained ecosystem, including a proprietary
(potentially soon to be deprecated?) package manager and originally its
own client side templating library.
35. HYBRIDS
• Autobahn
Autobahn offers Pub/Sub and RPC. It's a server implementing the
WAMP (Web Application Messaging Protocol) spec and offers a
selection of clients for JS, Python,Android and C++.
• CometD
CometD has been one of the first entries in the realtime space. It
combines pub/sub with rpcs and supports browser connectivity via a
stack of comet techniques.
36. LIBS BASED ON LANGUAGE
• Java: Netty, Jetty
• JavaScript (Node.JS): Faye, Socket.IO (Engine.IO), Primus.io
• .NET (C#): SignalR, XSockets
• Python: Lots of options built on Tornado
• PHP: ReactPHP, Ratchet
• Ruby: Faye