A deep dive into building a real-time, encrypted clipboard system across devices.
Copy-paste feels simple until you try to extend it across devices. What starts as a utility quickly becomes a distributed system.
The moment you introduce real-time sync and encryption, complexity increases dramatically.
Polling is too slow. WebSockets provide a persistent connection and real-time updates.
const socket = new WebSocket("wss://example.com");
socket.onmessage = (event) => {
const data = JSON.parse(event.data);
updateClipboard(data);
};Even 200ms delay can break the experience. Clipboard UX is extremely latency sensitive.
Security is critical because clipboard data often contains sensitive information.
import crypto from "crypto";
function encrypt(text: string, key: string) {
const cipher = crypto.createCipher("aes-256-cbc", key);
return cipher.update(text, "utf8", "hex") + cipher.final("hex");
}type ClipboardState = {
content: string;
updatedAt: number;
deviceId: string;
};We use timestamps to determine which clipboard version is the latest.
Each of these problems required careful trade-offs between performance and reliability.
This project taught me that real-time systems are deceptively complex, and UX expectations define architecture more than anything else.