Deployment guide
Choose a deployment shape for a Server SDK application by scale, from one machine to a separate import and export node and multiple collaboration nodes.
A Server SDK application has three deployment shapes, and the scale of the application determines which one to use. Begin with Collaboration SDK, import and export, and the examples to see how the modules are assembled. Deployment only determines how many nodes run that same assembly.
| Shape | Collaboration | Import and export | Recommended scale |
|---|---|---|---|
| Single machine | One node | Same node | Local applications, development, a few internal users |
| Split import and export | One node | Separate node | Multi-user online service within one node's capacity |
| Multiple nodes | Several nodes | Separate node | Beyond one node's capacity, or node failover |
For single-node sizing, compare your document size, number of simultaneous editors, and submission frequency with the measurements in Collaboration performance test report.
Single machine
All components run in a single Node.js process, and the browser connects to that process directly.
- The Database Adapter implements the
IDatabaseAdaptercontract. See Database Adapters. - Import and export are provided by Exchange Service and File Service. See Collaboration extension modules.
- Conversion is CPU-bound, so a large file slows collaboration.
Move import and export to a separate node when conversions begin to affect collaboration latency, or when the service must remain responsive for many users.
Split import and export
Import and export run on a dedicated node while collaboration remains on a single node. The gateway routes the two kinds of requests separately, and both sides use the same database.
The import and export node assembles the Database Adapter, a UniverCollabService, File Service, and Exchange Service, and then works directly with the database. The injection points are the same as on a single machine. Both nodes point File Service at the same file storage, and both install the same authorization Middleware on UniverCollabService.
Process memory limits the number of documents that one collaboration node can serve. Move to multiple nodes when that capacity is exceeded, or when failover is required.
Multiple collaboration nodes
Several collaboration nodes run the same code against the same database. A pub/sub adapter relays Rooms, Presence, and broadcasts between the nodes, and a ticket store shares Session Tickets. @univerjs-pro/collaboration-cluster-redis provides the Redis implementation. Every node uses the same License, which covers the number of running nodes; see collaboration nodes. For a reference implementation, see Multi-node.
Each collaboration node passes the Redis pub/sub adapter and ticket store to the Endpoint. The rest of the assembly is unchanged:
import { createClient } from "redis";import { RedisPubSubAdapter, RedisSessionTicketStore } from "@univerjs-pro/collaboration-cluster-redis";import { UniverCollabEndpoint } from "@univerjs-pro/collaboration-endpoint";const client = createClient({ url: process.env.REDIS_URL });const subClient = client.duplicate();await Promise.all([client.connect(), subClient.connect()]);const pubSub = new RedisPubSubAdapter({ pubClient: client, subClient });const ticketStore = new RedisSessionTicketStore({ client });const endpoint = new UniverCollabEndpoint(service, { pubSub, ticketStore });Going further
One very large document slows down requests for small documents on the same node. Split the node pools by document size and let the gateway route large documents to a dedicated pool. The routing key is still the unit ID, and every pool shares the database and pub/sub.
How is this guide?