Handle unlimited channels
Handle unlimited channels
Pub/sub channels are lightweight and efficient. You can have millions of unique channels without worrying about memory or CPU usage. Channels are automatically cleaned up when they are no longer used.
Deploy easily
Deploy easily
The socketcluster
CLI tool exposes kubectl
(Kubernetes) shortcut commands to make it easy to deploy your app to any Kubernetes cluster. All necessary Kubernetes .yaml
files are provided.
Scale easily
Scale easily
After deploying your app to a Kubernetes cluster, you can scale indefinitely by using the kubectl scale deployment
command to add more scc-worker
and scc-broker
instances as needed.
Guarantee message order
Guarantee message order
You can perform asynchronous operations anywhere along a socket's inbound or outbound stream without disrupting the message processing order. Streams behave like processing queues by default.
Monitor message backpressure
Monitor message backpressure
Awaiting for asynchronous actions along a socket's inbound or outbout streams can cause messages to pile up. This can be easily monitored on the back end using socket.getInboundBackpressure()
and socket.getOutboundBackpressure()
.
Support efficient authentication
Support efficient authentication
SocketCluster supports JWT authentication by default. This type of authentication is well suited for WebSockets as it allows short-lived tokens to be renewed and pushed out frequently while allowing you to save on database lookups.
Enforce access control using middleware streams
Enforce access control using middleware streams
Middleware streams allow you to block socket connections using the MIDDLEWARE_HANDSHAKE
middleware line. Individual socket actions can be blocked using the MIDDLEWARE_INBOUND
and MIDDLEWARE_OUTBOUND
lines.
Throttle and transform data using middleware streams
Throttle and transform data using middleware streams
Every data packet which is sent between a client and server can be delayed or transformed using MIDDLEWARE_INBOUND_RAW
, MIDDLEWARE_INBOUND
or MIDDLEWARE_OUTBOUND
lines.
Avoid callback hell
Avoid callback hell
All data and events are consumed using asynchronous loops (e.g. for-await-of
). Event listener callbacks are not required; this solves many problems related to code readability and maintainability.
Recover from failure
Recover from failure
Clients are optimized to handle lost connections seamlessly. For example, if a client loses the connection, channels attached to that socket will be put in a pending
state and automatically resubscribe after the socket reconnects.
Write declarative code
Write declarative code
Without callbacks, asynchronous logic is easier to follow. Using async/await
and for-await-of
loops makes it more obvious which parts of the code are serial and which parts are parallel; it encourages a more declarative style of programming.
Avoid memory leaks
Avoid memory leaks
Sockets and channels do not need to be destroyed explicitly. They will be automatically marked for garbage collection as soon as they stop being used and are no longer referenced in the code.