Latest / The CTO Podcast with Fexingo: Technical Leadership, Architecture, and Engineering Org / How Figma Rebuilt Its Multiplayer Engine for 500 Users per File
Transcript
- Lucas: If these conversations are useful for what you're building or running, there's a quiet way to keep them going. We deliberately don't run ads on this show. If you want to support that choice, the link is buy me a coffee dot com slash fexingo. Luna: Yeah, it's a simple way to keep the episodes ad-free. Appreciate anyone who chips in. Lucas: Alright — so, Figma. It's a design tool, sure, but underneath it's a real-time multiplayer system that hundreds of people can edit at once. And recently they rebuilt that engine from the ground up. Luna: I remember when they first launched multiplayer — it was a huge differentiator. But what drove them to rebuild? Lucas: Scale. Their original engine used operational transform, the same technique Google Docs popularized. But it was designed for maybe 10 to 50 concurrent users. Figma now sees files with over 500 people editing simultaneously. OT just couldn't keep up without conflicts piling up. Luna: So they switched to CRDTs? That's the trendy approach for conflict-free replication. Lucas: They actually went a different route. CRDTs are great for avoiding conflicts, but they have trade-offs — especially around memory and undo/redo. Figma built something they call a 'change tree'. It's a custom data structure that records every edit as a node in a tree, so the system can merge changes from different users without locking. Luna: A tree instead of a list. That's interesting. How does that help with undo? Lucas: Undo in a multiplayer system is notoriously tricky. If user A undoes something, user B might have built on top of that change. The change tree lets each user maintain their own undo stack. When you undo, it only affects your own branch of the tree. Other users see their own state preserved. Luna: That's clever. But managing branches for 500 users must create a huge graph. How do they keep it performant? Lucas: They prune aggressively. The change tree is ephemeral — it only exists in memory during a session. Once a change is synced and acknowledged by all clients, older nodes can be collapsed. They also moved away from WebSockets to WebRTC data channels for peer to peer sync. Luna: WebRTC — so they're not going through a central server for every edit? Lucas: Exactly. The server still coordinates presence and persistence, but the actual change propagation happens directly between clients. That cuts latency. They aim for sub-200 milliseconds for any edit to appear on another user's screen. Luna: What about the client-side? Figma is a web app — they can't control the user's hardware. How do they handle a browser with a garbage collector that might freeze? Lucas: That was actually one of the biggest bottlenecks. The browser's garbage collector runs unpredictably, and if it kicks in during a sync cycle, it can cause dropped frames. Figma engineers spent months profiling memory allocation patterns and reducing object churn. They moved frequently allocated objects to a pool and reused them. Luna: So they're basically writing JavaScript like it's a game engine. Why not use Rust compiled to WebAssembly for that part? Lucas: They considered it. But the team decided that the overhead of crossing the js wasm boundary for every small edit wasn't worth it. Since most of the collaboration logic is fine-grained — each keystroke or drag — the cost of marshalling data back and forth would wipe out any performance gain. Luna: That makes sense. So they optimized the JavaScript instead. Did they also change how they handle cursors — seeing where other people are typing? Lucas: Cursors are a great example of the trade-off. In the old system, every cursor position was sent as an OT operation. That generated a ton of small messages. In the new system, cursor positions are sent over a separate, lower-priority channel using WebRTC's data channel with partial reliability. You don't need every cursor update — you just need the latest. Luna: So they accept that some cursor updates might be dropped. That's fine because it's ephemeral state. Lucas: Right. And they batch cursor updates on a 50-millisecond timer, so no more than 20 per second per user. That keeps the network traffic manageable even with 500 people. Luna: Let's talk about conflict resolution in practice. Two users edit the same text layer at the same time. How does the change tree handle that? Lucas: Figma uses a technique called 'intent-preserving merge'. The change tree records not just what changed, but also the user's intent — like 'insert character X at position Y'. If two users insert at the same position, the system decides an order based on a deterministic tiebreaker, like user ID. But it also checks if one insertion would break the other. If they're in the same word, it might merge them. Luna: That sounds like a lot of ad-hoc rules. How do they test it? Lucas: They built a simulation framework that replays millions of real editing sessions from beta users. They run the new merge logic against the old one and compare outcomes. They also fuzz-test random sequences of edits from multiple virtual users to find edge cases. Luna: And after all that, what's the biggest lesson they learned? Lucas: The lesson was that you can't just pick a theoretical algorithm and assume it works at scale. The real world has network partitions, browser bugs, users who paste 10,000 characters at once. You need to design for those edge cases from day one. Figma's change tree evolved from months of observing what actually broke in production. Luna: It's a reminder that the hardest problems in distributed systems aren't the algorithms — they're the boundaries. Lucas: Exactly. And that's what makes Figma's approach worth studying, whether you're building collaboration features or just dealing with any real-time multi-user system. The trade-offs they made apply far beyond design tools.