---
title: "Custom backend, MailKaro Docs"
description: "Custom backend in MailKaro: bring your own realtime server. For React, Vue, Angular and plain JavaScript."
---

# Custom backend

Collaboration & history

# Custom collaboration backend

Bring your own realtime server.

Wire the WebSocket collaboration adapter to a small relay on your own server, so documents sync through infrastructure you control. See [collaboration](https://docs.mailkaro.com/collaboration).

## What your server has to do

`createYjsWebSocketCollaborationAdapter({ url, protocols })` opens one WebSocket per editor and sends JSON text messages. It does not speak the y-websocket protocol. Your server only has to pass every message it receives to the other sockets in the same session; the editors merge the Yjs updates themselves. A message that comes back to its sender is ignored, so broadcasting to everyone in the room is fine.

`url` can be a function of the session id, which gives each design its own room:

ts

```
const adapter = createYjsWebSocketCollaborationAdapter({
 url: (sessionId) => `wss://collab.example.com/rooms/${encodeURIComponent(sessionId)}`
});
```

## Messages

- `sync-request` is sent when a socket opens. Any peer answers with `sync-state`.
- `sync-state` and `doc-update` carry a Yjs update as an array of numbers in `update`.
- `presence` and `presence-leave` carry who is here and what they selected.
- Every message has a `from` field with the sender's peer id.

## Limits

- The adapter does not reconnect. When the socket closes, the status becomes `disconnected`.
- A relay stores nothing. Each editor seeds the shared document from the design it was loaded with, so load the same saved design in every editor and keep saving through your own save flow.

Source: https://docs.mailkaro.com/custom-backend
