Quick Start
See our complete production example here for a full working implementation.
1
Install the library
2
Create server
3
Add WebSocket endpoint
CollaborationBuilder API
TheCollaborationBuilder provides a fluent interface for configuring your collaboration service.
Configuration Methods
Set the service identifier name
Set the debounce interval for auto-save in milliseconds (default: 5000ms)
Set how long documents stay in memory after last user disconnects (default: 5000ms)
Add Yjs extensions for additional functionality
Hook Methods
Configure the service after initialization
Authenticate users connecting to documents
Load document state from storage
Save document state to storage (called automatically based on debounce)
React to document changes (called on every edit - use sparingly!)
Process changes before they’re applied to the document
Build the collaboration service
Production Implementation Example
Here’s a complete server implementation based on the production example:Hook Details
onLoad - Document Loading
onLoad - Document Loading
Load document state from your storage system.Returns:
Document identifier to load
Full parameters object containing documentId and other context
Uint8Array | null - Document state or null for new documentsReturn
null for new documents. The collaboration system will initialize an empty document.onAutoSave - Document Persistence
onAutoSave - Document Persistence
onAuthenticate - User Validation
onAuthenticate - User Validation
Authenticate users connecting to documents (optional but recommended).Returns: User context object or boolean, or throws error to deny access
Authentication token from client
Document being accessed
Original HTTP request with headers and cookies
If no
onAuthenticate hook is provided, all connections are allowed.Optional Hooks
onConfigure
onConfigure
Configuration
Builder Methods
Set service identifier
Autosave interval (milliseconds)
Cache expiry when no users connected
Storage Implementations
- PostgreSQL
- S3
- Redis
Framework Integration
- Express
- Fastify
Production Deployment
Environment Variables
Docker Setup
Scaling Considerations
For production scale:
- Use Redis for document state (fast access)
- Implement sticky sessions for WebSocket
- Add health checks for load balancer
- Monitor memory usage per document
- Set connection limits per user
Security Checklist
1
Always use WSS in production
2
Implement rate limiting
3
Validate document IDs
4
Set connection limits
Monitoring
Health Check Endpoint
Metrics
Examples
API Reference
Full builder API documentation:Fluent builder for configuration

