I have a Spring Boot application where we use Hazelcast to handle pub/sub messaging for WebSockets. However, our current approach has scalability issues:
Every STOMP message is sent to every WebSocket instance, even if that instance doesn't have any active WebSocket connections that care about the event.
Hazelcast does not natively track which instance is subscribed to which topic, leading to unnecessary message broadcasting.
Essentially, we want to track which instance cares about what topic so it only gets events concerning that topic.
Steps Tried:
Using Redis to track which WebSocket instances are subscribed to which topics dynamically.
Querying Redis before sending messages via Hazelcast to only relevant instances.
Automatically removing stale subscriptions when instances shut down.
However, the issue with this approach is that
- If a WebSocket instance terminates, it loses all its subscriptions, and there is no easy way to reassign them to a new instance.
Any ideas on how to solve this would be appreciated.