← Back

Building a Cross-Platform Clipboard

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.

blog

The Real Problem

  • How do you sync instantly?
  • How do you handle multiple devices?
  • How do you keep data secure?

The moment you introduce real-time sync and encryption, complexity increases dramatically.

Real-Time Sync

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.

blog

Encryption Layer

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");
              }

State Management

type ClipboardState = {
              content: string;
              updatedAt: number;
              deviceId: string;
              };

We use timestamps to determine which clipboard version is the latest.

Challenges

  • Conflict resolution across devices
  • Offline sync handling
  • Maintaining encryption performance

Each of these problems required careful trade-offs between performance and reliability.

Final Thoughts

This project taught me that real-time systems are deceptively complex, and UX expectations define architecture more than anything else.