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
Thesocketcluster
CLI tool exposeskubectl
(Kubernetes) shortcut commands to make it easy to deploy your app to any Kubernetes cluster. All necessary Kubernetes.yaml
files are provided.
Scale easily
After deploying your app to a Kubernetes cluster, you can scale indefinitely by using thekubectl scale deployment
command to add morescc-worker
andscc-broker
instances as needed.
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
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 usingsocket.getInboundBackpressure()
andsocket.getOutboundBackpressure()
.
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
Middleware streams allow you to block socket connections using theMIDDLEWARE_HANDSHAKE
middleware line. Individual socket actions can be blocked using theMIDDLEWARE_INBOUND
andMIDDLEWARE_OUTBOUND
lines.
Throttle and transform data using middleware streams
Every data packet which is sent between a client and server can be delayed or transformed usingMIDDLEWARE_INBOUND_RAW
,MIDDLEWARE_INBOUND
orMIDDLEWARE_OUTBOUND
lines.
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
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 apending
state and automatically resubscribe after the socket reconnects.
Write declarative code
Without callbacks, asynchronous logic is easier to follow. Usingasync/await
andfor-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
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.