Introduction to WebSockets
WebSockets is 10+ years old technology for bidirectional, full-duplex communication between clients and server over a persistent TCP connection. All major browsers support WebSockets and server-side implementations are available for all well-known programming languages (Node, Python, Java etc).
The WebSocket client establishes an HTTP connection and requests to switch the protocol to WebSockets using the HTTP Upgrade
mechanism.
If the server supports WebSockets, the 'socket' connection is established and both the client and server can then send data to the other party.
WebSockets fits use cases where low latency, real-time communication between clients and server is required, like chat applications and multiplayer online gaming.
A Beginner's Guide to WebSockets
Dion Misic gave an excellent introductory talk about WebSockets at PyCon Australia in August 2018. Click the image below to watch his "A Beginner's Guide to WebSockets" on Youtube.
WebSockets references
- WebSockets specification
- WebSockets browser support
- Wikipedia: WebSocket
- Introducing WebSockets - Bringing Sockets to the Web [web.dev]
CDNs and WebSockets
WebSockets data cannot be cached by the CDN (there is no 'request' and 'response'), so how do CDNs support and add value to customer apps that require WebSockets?
Proxy
Does the CDN support proxying WebSockets traffic between client and origin?
Origin-less
Can you build and run a WebSockets app in the CDN edge platform, without an origin?
CDN comparison
CDN | Proxy | Origin-less |
---|---|---|
Akamai
|
||
bunny.net | ||
CDN77 | ||
Cloudflare
|
||
CloudFront
|
||
EdgeNext | ||
Edgio
|
||
Fastly
|
||
Gcore
|
||
Imperva | ||
StackPath
|
More info per CDN
Akamai
Akamai can proxy WebSockets traffic. Read their Techdocs article WebSockets.
Cloudflare
Cloudflare has supported WebSockets in a proxy mode since 2014. As of 2022, you can run origin-less WebSockets apps in their edge Workers platform. Read the WebSockets in Workers docs or the announcement on their blog
CloudFront
CloudFront supports WebSocket connections globally with no required additional configuration. More info in Using WebSockets with CloudFront distributions. The costs of using WebSockets on CloudFront is on the CloudFront pricing page, see sections "Amazon CloudFront to origin server" and "WebSocket pricing"
Edgio
Edgio supports WebSockets on their traditional CDN (formerly Edgecast) but not in their AppOps platform (formerly Layer0)
Fastly
Fastly supports WebSocket connections in a limited availability release. Customers must have a paid Fastly account. Billing for WebSockets on a combination of bandwidth and connection time. Read more on the Fastly WebSockets product page or - more technical - in the WebSockets passthrough article.
Gcore
Gcore supports WebSocket connections globally on the CDN. WebSockets is enabled by default for whole-site delivery. Read more in the WebSockets. Allow WebSockets connections to an origin server article.
StackPath
StackPath allows you to proxy your WebSocket connections through the CDN simply by enabling a setting in your CDN Stack. Read how in How-To Use WebSockets with the StackPath CDN. StackPath considers WebSocket traffic and HTTP traffic the same, therefore you will not be charged for ingress traffic and will be billed at your regular rate for egress traffic.