WebSockets
Messaging For Real-time Web Applications.
Tiju Titus John
Oct 21, 2016
Agenda
 Real-time web applications
 HTTP Challenges
 WebSocket
 Design Considerations
 Tooling
 Testing
 Alternate Considerations
 Summary
 Q&A
Real-time Web Applications
 Timely nature to the data /event
 Timely nature to the user experience
 Bit-Directional Message
 Peer-2-Peer
 Users to Systems
 Asynchronous
 Frequent and Chatty
Examples
• Web Telephony
• Web Conferencing
• Collaborative Rooms / Channels
• IM / Chats /
• Games
• Real-time Dashboards
HTTP wasn’t enough!
 Request-Response
 High amount of data in Headers
 Http 1.1 Keep Alive provide persistent connections.
 One Request at a Time  HTTP Pipelining (HOL Blocking –
problem)
 Bi-directional approaches
 Call back URLS (Works in server to server integration with
limitations)
 Polling and Long Polling
 Http Streaming
 SSE – Server Sent Events
Http Upgrade - WebSockets
 RFC6455 – Dec 2011
 Allows full duplex communication.
 Wide support of tools and browsers in short time.
 ws:// and wss://
 Post handshake is made each party can send message as
frames
 W3C WebSocket API
 Support Binary and Text Data
GET /chat HTTP/1.1
Host: server.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key:
dGhlIHNhbXBsZSBub25jZQ==
Origin: http://example.com
Sec-WebSocket-Version: 13
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept:
s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
Design Considerations
 Use Higher abstraction API’s
 Socket.io
 SockJS
 SDK vs Messages
 JS SDK (Twilio) (Good only browser clients)
 WebSocket Message API (Slack) – Interface definition's are bit tricky.
 Message Reliability – Application need to built it.
 Only a Delivery Mechanism – No Reliable delivery
 At-most-once.
 Using Multiple WS Channels.
 Big messages can delay other events as messages are delivered in order.
 Subscribe to only necessary data.
 Non Functional Aspects.
 Authentication / Authorization / Message-Auditing
 Webserver logs may not work.
Tool Support
 Chrome Developer console
 WebSocket Monitor – Firefox add-ons
 Non – Blocking io based libs
 Message bus Gateways
 Spring STOMP broker
 Database Gateways
 Caching and CDN’s
Testing Challenges
 Lack of support of the shelf testing tools.
 Use Asynchronous Testing Framework
 Mocha / should.js
 Perf Test – Jmeter Websocket sampler
REST Replacement?
 Non Real-time apps and services REST or Web Service
 Standardized / Templated frameworks
 Use mix of Both REST & Web Socket
 Non real-time / stateless with REST
 Real-time aspects with Web Sockets
 Scale the real-time and non-real-time services separately and differently.
Server side Integrations ?
 Using as an integration Framework between services.
 Not an Ideal one due lack of reliability
 Message bus / Message Brokers might be best.
 Can use to traverse via firewall ( Can use it as Message Bus gateways)
Similar Technologies
HTTP 2 Server Push
 Send multiple Response for single
Request
 Good for sending images/CSS/JS
WebRTC
 Focus on A/V, but also has data
channel
 Focus on P2P, but one peer be a
server.
 Data Streams are SCTP
 NAT and Firewall problems
 Good for rich content streams
 Many WebRTC solutions uses
WebSockets for signaling.
Summary
 Technology for Real-time web applications.
 Not a replacement for REST / Web Services
 Not ideal for service integrations.

Messaging for Real-time WebApps

  • 1.
    WebSockets Messaging For Real-timeWeb Applications. Tiju Titus John Oct 21, 2016
  • 2.
    Agenda  Real-time webapplications  HTTP Challenges  WebSocket  Design Considerations  Tooling  Testing  Alternate Considerations  Summary  Q&A
  • 3.
    Real-time Web Applications Timely nature to the data /event  Timely nature to the user experience  Bit-Directional Message  Peer-2-Peer  Users to Systems  Asynchronous  Frequent and Chatty Examples • Web Telephony • Web Conferencing • Collaborative Rooms / Channels • IM / Chats / • Games • Real-time Dashboards
  • 4.
    HTTP wasn’t enough! Request-Response  High amount of data in Headers  Http 1.1 Keep Alive provide persistent connections.  One Request at a Time  HTTP Pipelining (HOL Blocking – problem)  Bi-directional approaches  Call back URLS (Works in server to server integration with limitations)  Polling and Long Polling  Http Streaming  SSE – Server Sent Events
  • 5.
    Http Upgrade -WebSockets  RFC6455 – Dec 2011  Allows full duplex communication.  Wide support of tools and browsers in short time.  ws:// and wss://  Post handshake is made each party can send message as frames  W3C WebSocket API  Support Binary and Text Data GET /chat HTTP/1.1 Host: server.example.com Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== Origin: http://example.com Sec-WebSocket-Version: 13 HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
  • 6.
    Design Considerations  UseHigher abstraction API’s  Socket.io  SockJS  SDK vs Messages  JS SDK (Twilio) (Good only browser clients)  WebSocket Message API (Slack) – Interface definition's are bit tricky.  Message Reliability – Application need to built it.  Only a Delivery Mechanism – No Reliable delivery  At-most-once.  Using Multiple WS Channels.  Big messages can delay other events as messages are delivered in order.  Subscribe to only necessary data.  Non Functional Aspects.  Authentication / Authorization / Message-Auditing  Webserver logs may not work.
  • 7.
    Tool Support  ChromeDeveloper console  WebSocket Monitor – Firefox add-ons  Non – Blocking io based libs  Message bus Gateways  Spring STOMP broker  Database Gateways  Caching and CDN’s
  • 8.
    Testing Challenges  Lackof support of the shelf testing tools.  Use Asynchronous Testing Framework  Mocha / should.js  Perf Test – Jmeter Websocket sampler
  • 9.
    REST Replacement?  NonReal-time apps and services REST or Web Service  Standardized / Templated frameworks  Use mix of Both REST & Web Socket  Non real-time / stateless with REST  Real-time aspects with Web Sockets  Scale the real-time and non-real-time services separately and differently.
  • 10.
    Server side Integrations?  Using as an integration Framework between services.  Not an Ideal one due lack of reliability  Message bus / Message Brokers might be best.  Can use to traverse via firewall ( Can use it as Message Bus gateways)
  • 11.
    Similar Technologies HTTP 2Server Push  Send multiple Response for single Request  Good for sending images/CSS/JS WebRTC  Focus on A/V, but also has data channel  Focus on P2P, but one peer be a server.  Data Streams are SCTP  NAT and Firewall problems  Good for rich content streams  Many WebRTC solutions uses WebSockets for signaling.
  • 12.
    Summary  Technology forReal-time web applications.  Not a replacement for REST / Web Services  Not ideal for service integrations.

Editor's Notes

  • #5 Http-Streaming – With chunked headers.. The use of Comet techniques in web development predates the use of the word Comet as a neologism for the collective techniques. Comet is known by several other names, including Ajax Push,[4][5] Reverse Ajax,[6] Two-way-web,[7] HTTP Streaming,[7] and HTTP server push[8] among others https://www.quora.com/Oneline-Python-Whats-your-opinion-about-WebSockets-and-using-it-in-production-over-XHR-and-more-folklore-strategies
  • #6 High Reduction in headers Improve latency Improve Network Throughput Sub Protocols – STOMP, Chat, SuperChat
  • #7 http://doc.akka.io/docs/akka/2.4/general/message-delivery-reliability.html When it comes to describing the semantics of a delivery mechanism, there are three basic categories: at-most-once delivery means that for each message handed to the mechanism, that message is delivered zero or one times; in more casual terms it means that messages may be lost. at-least-once delivery means that for each message handed to the mechanism potentially multiple attempts are made at delivering it, such that at least one succeeds; again, in more casual terms this means that messages may be duplicated but not lost. exactly-once delivery means that for each message handed to the mechanism exactly one delivery is made to the recipient; the message can neither be lost nor duplicated. The first one is the cheapest—highest performance, least implementation overhead—because it can be done in a fire-and-forget fashion without keeping state at the sending end or in the transport mechanism. The second one requires retries to counter transport losses, which means keeping state at the sending end and having an acknowledgement mechanism at the receiving end. The third is most expensive—and has consequently worst performance—because in addition to the second it requires state to be kept at the receiving end in order to filter out duplicate deliveries.
  • #9 http://liamkaufman.com/blog/2012/01/28/testing-socketio-with-mocha-should-and-socketio-client/
  • #10 http://liamkaufman.com/blog/2012/01/28/testing-socketio-with-mocha-should-and-socketio-client/