Use own websocket for yjs
- Deciders: Julian Bäume
- Date: 2025-06-05
- Updated: 2025-10-29 - Clarified notification architecture
Status
Accepted
Context
With the Switchboard component we introduced a way to send messages between different user sessions using Socket.IO. Our idea was to only have one WebSocket connection per user session and use it from multiple components to share state. This approach still works fine for most use cases, but there is no official support for Yjs to use Socket.IO as a transport layer. While there are multiple community plugins for Socket.IO and Yjs they seem to be based on the same implementation and have not seen much activity in the last years.
Despite from possibility, it would be best to use officially maintained code that is actively developed and tested. In case the official y-websocket provider should be used at least on the client side, it would mean to use a second WebSocket connection per user session. This would also mean to have another implementation on the server side, or have a dedicated microservice to handle these WebSocket connections.
Option 1: Use y-websocket provider and y-redis backend
Since we need to scale our service to handle a lot of concurrent users, we need to use a backend that can handle the load. All in all it seems possible to maintain such a plugin and if we go for Yjs in general There is y-redis to do exactly this. The only drawback here is, that y-redis is published under AGPL-3.0 which might or might not be a problem for us. To be on the safe side, we can not rely on this library and would need to implement it ourselves. This is however not a big problem, as we have already done so in the form of Switchboard.
When using y-websocket on the client side, we can always switch to y-redis at any time in the future, as the API is compatible.
Option 2: Use y-websocket provider and change Switchboard to use plain WebSockets
Another viable option would be to change Switchboard to use plain WebSockets instead of Socket.IO. We'd need to adjust some components that use the Socket.IO API. Currently that's only Switchboard itself (and the old Chat component) for initiating video calls and for maintaining the presence state of users. So it would not affect a lot of code at the moment, it would still be a breaking change.
In this case it would be possible to use y-websocket on the server side as well and implement persistence and scaling using a custom implementation. The scaling problem is already kind of solved in Switchboard and it should be possible to easily adjust it to work with y-websocket instead.
Option 3: Use y-websocket provider and integrate into Teams middleware
Another option would be to maintain a dedicated WebSocket to the client for Yjs and integrate it into the Teams middleware. This would mean a little overhead but it would be the most flexible solution for now and we do not need much custom code to implement it. Most of it can be handled by officially supported libraries and we just hook those up into the Teams middleware.
It would also easily be possible to switch to any of the other options in the future, as the API is compatible.
Option 4: Implement a custom sync provider using Socket.IO
This option would mean to implement a custom sync provider for Yjs that uses Socket.IO as a transport layer. This can then easily be integrated into the existing Switchboard component and we get scaling for free. Persistence still needs to be implemented on the Switchboard side, but the there are libraries to help with that.
Decision
We go with Option 3 for now, as this is the simplest solution to implement and we can easily switch to other options in the future if needed. As the goal for now just is to explore Yjs and its capabilities, we do not want to invest too much time to implement a custom solution.
Consequences
We will maintain a second WebSocket connection per user session for Yjs. This will increase resource usage on the server side but it's manageable for initial user testing and POC setups. We need to consolidate the WebSocket connections in the future, but for now this is a good compromise to get started with Yjs.
Notification Architecture (Update 2025-10-29)
Superseded by ADR-0023 (2026-09-03): thread events are published server-side via PostgreSQL LISTEN/NOTIFY and pushed over Server-Sent Events; Switchboard is no longer used for messaging. The Yjs decision above is unchanged.
This decision establishes clear separation of concerns between real-time collaboration and user notifications:
Yjs WebSocket (Port 8080, /ws/:threadId)
- Purpose: CRDT-based collaborative editing only
- Implementation: Custom WebSocket using
@y/websocket-serverandy-postgresql - Persistence: PostgreSQL via
y-postgresqlprovider - Use case: Real-time document synchronization across multiple editors
Switchboard (Socket.IO)
- Purpose: User-to-user notifications and presence
- Implementation: Socket.IO-based messaging via Switchboard component
- Use cases:
- User mentions in comments
- Presence state
- Video call initiation
- Other user-facing notifications
Architectural Benefits
- Separation of concerns: Document sync vs user notifications are fundamentally different problems
- Simplicity: Each system optimized for its specific use case
- Maintainability: Clear boundaries between CRDT operations and user messaging
- Flexibility: Can evolve notification system independently from collaborative editing
Implementation Notes
- Backend creates mention records in database but does NOT send notifications
- Frontend sends notifications via Switchboard after mention creation
- This prevents duplicate notifications and keeps notification logic in one place
- WebSocket notification service (
src/services/websocket-notifications.js) is no longer used and can be removed in future cleanup

