#Single WebSocket Gateway with Namespaces vs. Separate Gateways for Chat and Notifications in NestJS?

3 messages · Page 1 of 1 (latest)

tribal otter
#

I'm building a NestJS server with Socket.IO to handle both chat and notification functionalities. I'm trying to decide between:
Using a single WebSocket gateway with two namespaces (/chat and /notification) to manage both features.
Creating separate gateways for chat and notifications, each with its own namespace and logic.
My app needs real-time messaging for group/private chats and push-like notifications for user-specific updates. Both features will likely share similar authentication (JWT-based) but may differ in scaling needs or event complexity down the line.
What are the pros and cons of each approach in terms of:
Performance (e.g., connection overhead)?
Scalability (e.g., handling multiple servers with Redis adapter)?
Code maintainability and modularity?
Which would you recommend for a medium-sized app with potential for growth, and why? Any pitfalls to watch out for? Thanks for your insights!

ocean dune
#

Either is fine. If you don't know better pick one and adapt later.

#

But. Merging implementations is usually much easier than splitting them apart