When we built the Universal Clipboard, we needed a way to push data from one device to another in real-time. We chose Server-Sent Events (SSE) over WebSockets. Here is why.
Standard HTTP requests are unidirectional: the client asks, the server answers. To create a "sync" effect, most apps use one of three techniques:
When you open a room in Universal Clipboard, your browser establishes a persistent connection to our relay server using the EventSource API.
const eventSource = new EventSource('/api/relay?room=YOUR_ROOM_ID');
eventSource.onmessage = (event) => {
const newClip = JSON.parse(event.data);
updateClipboard(newClip);
};Because SSE is lightweight, our relay servers can handle thousands of concurrent "listening" devices with minimal CPU overhead. When you "Submit" a new clip, we use a standard POST request to the server, which then broadcasts that data through the active SSE streams to all other devices in the room.