WebSocket Proxy

The WebSocket Proxy allows you to establish the WebSocket communication protocol between your origin and your users under the reverse proxy architecture. This type of protocol consists of a single bidirectional TCP connection that allows data to be exchanged in real time via a single handshake without the need to restart the connection.

WebSockets are designed to minimize latency and increase efficiency, and are suitable for applications that exchange data in real time, such as online games, chat platforms, notifications, and live streaming services. See the WebSocket protocol specification for more information.

Implementation

ScopeResource
Applications first stepsFirst steps
Functions WebSocket APIWebSocket API
Debug RulesDebug Rules

Functions WebSocket Support

Azion Functions supports WebSocket API, allowing your Applications to act as a full WebSocket server or client and proxy bidirectional traffic to backend services. This unlocks real-time use cases such as chat, multiplayer games, telemetry dashboards, and AI inference streams—all served directly from the edge for sub-second latency.

Key Features:

  • Server & client modes: Use upgradeWebSocket() for server-side handlers or the standard WebSocket(url) API for outbound connections
  • Broadcast helpers: Easily fan-out messages to all connected clients with minimal code
  • Edge Firewall support: Edge Firewall rules can inspect WebSocket traffic before the upgrade process is finalized
Go to WebSocket API reference

Requirements

Your client and server must support the WebSocket connection natively for the protocol to be implemented in your applications. On the client side, most browsers include native WebSocket support. See the complete list of browsers with WebSocket support.

Upgrade headers

The origin application must inject the Upgrade: websocket and Connection: upgrade HTTP headers for the connection to be successfully established. If the Connection and Upgrade headers are sent by the client with values other than those specified above or one of them isn’t present, the connection upgrade in the user request to the origin won’t be carried out.


Error treatments

By default, an application that has the WebSocket Proxy module enabled will consider any request received with the headers Upgrade: websocket and Connection: upgrade to be a websocket connection and will forward them to the origin. It’s recommended that the application itself controls the headers in cases where the protocol should be used.

A valid WebSocket connection will return the status 101 Switching Protocols. If this isn’t the status received, even if it’s among the 2xx or 3xx family of success statuses, it’s likely that the client request, the application, or the origin server didn’t complete the Websocket connection. In this case, you should review the connection upgrade requirements and make the necessary adjustments.


Limits

These are the default limits:

ScopeLimit
Maximum connection time¹15 minutes

¹ Azion recycles keepalive connections on its servers approximately every 15 minutes. Active WebSocket connections may be terminated if they exceed this range. In such cases, your application should handle these scenarios and reestablish the connection as needed.