You certainly noticed that WebSocket is the current
trendy flavor for any modern web framework.
But does it scale? Would it replace HTTP/REST?
There is a feature
request ticket about them for mORMot, so here are some thoughts -
matter of debate, of course!
I started all this by answering a StackOverflow
question, in which the actual answers were not accurate enough, to my
opinion.
From my point of view, Websocket - as a protocol -
is some kind of monster.

You start a HTTP stateless connection, then switch to WebSocket
mode which releases the TCP/IP dual-direction layer, then you may switch later
on back to HTTP...
It reminds me some kind of monstrosity, just like encapsulating everything over
HTTP, using XML messages... Just to bypass the security barriers... Just
breaking the OSI layered
model...
It reminds me the fact that our mobile phone data providers do not use
broadcasting for streaming audio and video, but regular Internet HTTP servers,
so the mobile phone data bandwidth is just wasted when a sport event occurs:
every single smart phone has its own connection to the server, and the same
video is transmitted in parallel, saturating the single communication
channel... Smart phones are not so smart, aren't they?
WebSocket sounds like a clever way to circumvent a
limitation...
But why not use a dedicated layer?
I hope HTTP 2.0 would allow
pushing information from the server, as part of the standard... and in one
decade, we probably will see WebSocket as a deprecated
technology.
You have been warned. Do not invest too much in WebSockets..
OK. Back to our existential questions...
First of all, does the WebSocket protocol scale?
Today, any modern single server is able to server millions of clients at
once.
Its HTTP server software has just to be is Event-Driven (IOCP)
oriented (we are not in the old Apache's one connection = one
thread/process equation any more).
Even the HTTP server built in Windows (http.sys - which is used in
mORMot) is IOCP oriented and very efficient (running in kernel
mode).
From this point of view, there won't be a lot of difference at scaling between
WebSocket and a regular HTTP connection. One TCP/IP connection
uses a little resource (much less than a thread), and modern OS are optimized
for handling a lot of concurrent connections: WebSocket and HTTP
are just OSI 7 application layer protocols, inheriting from this TCP/IP
specifications.
But, from experiment, I've seen two main problems with
WebSocket:
- It does not support CDN;
- It has potential security issues.