Latest / The CTO Podcast with Fexingo: Technical Leadership, Architecture, and Engineering Org / How Figma Rebuilt Its Multiplayer Sync Engine
Transcript
- Lucas: So Figma now supports over five hundred thousand simultaneous editors on a single file. That's not a theoretical number — that's what they hit during a major product launch last quarter. And it's not just a frontend scaling problem. The entire multiplayer sync engine had to be rebuilt from the ground up. Luna: Wait — five hundred thousand people editing the same file at the same time? How does that even work without everything collapsing into a mess of conflicting cursors? Lucas: That's the key question. And the answer is that Figma moved away from the standard approach most real-time collaboration tools use — operational transformation, or OT — and built their own system based on a custom conflict-free replicated data type, a CRDT. Luna: Right. OT is what Google Docs and early Etherpad used. But CRDTs have been getting a lot of attention lately. Why did Figma decide OT wasn't going to cut it? Lucas: OT works well when you have a central server that orders operations and transforms them before applying them. But at Figma's scale — think tens of thousands of concurrent editors in a single file during a design sprint — the central server becomes a bottleneck. Transformations get expensive, and latency spikes. Plus, OT struggles with undo and with complex data structures like vector graphics. Luna: And CRDTs are designed to be decentralized, right? Each client can apply operations locally and merge them later without a central arbiter. Lucas: Exactly. The key property is that merges are deterministic — no matter what order operations arrive, the final state is the same. That's what allows Figma to avoid a single point of failure and still guarantee consistency. But off-the-shelf CRDTs aren't exactly efficient for a design tool. Standard CRDTs produce a lot of metadata — each character or object carries a unique ID and a timestamp, and the data structure can balloon. Luna: So they had to invent their own CRDT variant? Lucas: They did. They call it the 'Figma CRDT' internally — though they haven't published a paper on it. The key innovation was compressing the metadata by using what they call 'epoch-based' IDs. Instead of each object having a globally unique identifier, they use a combination of a client ID and a local sequence number, plus an epoch counter that increments whenever the network topology changes. That cuts the metadata overhead by about 80 percent compared to a standard CRDT. Luna: That's a huge reduction. But even with compressed metadata, five hundred thousand editors means a lot of operations flying around. How do they handle the network traffic? Lucas: This is where the architecture gets really interesting. Figma originally used WebSockets for real-time sync — standard, reliable, ordered delivery. But at that scale, WebSocket's overhead becomes a problem. Each message has to be framed, and TCP backpressure can cause head of line blocking. So they built a custom transport layer on top of UDP — they call it 'Webex' internally. Luna: UDP is unreliable, though. How do they guarantee that operations aren't lost? Lucas: They don't guarantee delivery — they guarantee convergence. In a CRDT system, if a message is lost, the state doesn't diverge permanently because subsequent messages contain enough information to reconcile. Figma's transport uses a nack based retransmission scheme — the receiver sends a negative acknowledgment only if it detects a gap in the operation sequence. And because operations are idempotent and commutative, duplicates don't cause issues. Luna: So they traded reliability guarantees for lower latency and higher throughput. Lucas: Exactly. And it paid off. Their internal benchmarks show that for a file with one hundred thousand active editors, the 95th percentile round-trip time for a cursor move dropped from 120 milliseconds with WebSocket to 45 milliseconds with the custom UDP transport. That's a difference users can feel — cursor movement went from slightly sluggish to instant. Luna: Cursor sync is interesting because it's not as critical as object edits — losing a cursor position isn't the end of the world. But for undo history, you need perfect consistency. Lucas: That's the hardest part. Undo in a collaborative environment is notoriously tricky — if two users undo different operations, you can end up with conflicts. Figma's solution is to treat undo as a first-class operation in the CRDT. Each undo is itself an operation that references the original operation's ID. The CRDT ensures that undos are applied in the correct order relative to other operations. And because merges are deterministic, all replicas agree on which operations are undone. Luna: But what about cross-replica consistency? If two editors are on different network partitions, they might see different undo states until they merge. Lucas: That's by design. Figma prioritizes availability over consistency — they follow an 'eventual consistency' model. During a network partition, each client continues editing locally. When the partition heals, the CRDT merges the two histories deterministically. The merge is designed so that the resulting state is the same regardless of when or how the merge happens. Users might see a brief 'reconciling' state, but the final state is identical. Luna: That sounds like the CAP theorem in action. Figma chose availability and partition tolerance over strong consistency. Lucas: Right. And they made that trade-off explicitly. But they also added a layer of 'intent preservation' on top. The CRDT guarantees that the final state is consistent, but it doesn't guarantee that the final state makes sense from a design perspective. For example, if two editors delete the same layer and then one of them changes its color, the CRDT might apply the color change to a null object. Figma's engine catches those 'semantic conflicts' and flags them in the UI. Luna: So there's a layer of application-level conflict resolution on top of the data-level CRDT. Lucas: Exactly. And that's where a lot of the engineering effort went. The CRDT handles the low-level concurrency, but the application layer handles the domain-specific semantics. For example, if two editors move the same rectangle to different positions, the CRDT will merge those moves — but which position wins? Figma uses a 'last writer wins' strategy based on a logical clock that accounts for causal relationships. But if the moves are truly concurrent, the tie is broken by a deterministic rule based on client IDs. Luna: Interesting. And all of this runs in the browser, right? How do they handle the client-side state management? Lucas: The client runs a full replica of the CRDT in a WebAssembly module. That's another key decision — they wrote the core CRDT logic in Rust, compiled to WebAssembly, running in the main thread alongside the rendering engine. Rust gives them memory safety and performance — the CRDT operations are on the order of microseconds per operation. The JavaScript layer handles the UI and canvas rendering, and it communicates with the Rust core through a shared memory buffer. Luna: Why Rust for the CRDT? Why not just JavaScript? Lucas: Two reasons. First, garbage collection pauses — in a real-time collaborative tool, a 50-millisecond GC pause can cause visible jank. Rust has no GC, so the CRDT operations are predictable. Second, the CRDT data structures are complex — lots of hash maps and vectors. In JavaScript, those would be slower and use more memory. Rust's ownership model also helps prevent bugs in the merge logic, which is notoriously hard to get right. Luna: That makes sense. So the entire sync engine is in Rust, compiled to WebAssembly, running in the browser, with a custom UDP transport. That's a huge architectural shift from the early days of Figma. Lucas: It is. And it's not just about performance — it's about scalability. The old architecture, based on a central server running OT, could handle maybe ten thousand editors per file before hitting bottlenecks. The new crdt based architecture scales horizontally because each client does most of the work locally. The server's role is reduced to acting as a message relay and a persistent store for the CRDT state. Luna: If these conversations are useful for what you're building or running, listener support is what keeps this podcast ad-free and focused on the technical details. We're able to spend time on these deep dives because of people who buy us a coffee. If you find value in episodes like this one, you can support the show at buy me a coffee dot com slash fexingo. Just a simple way to keep the content coming without any sponsors. Lucas: Yeah, and it genuinely makes a difference — lets us pick the episodes we want to do rather than chasing advertiser-friendly topics. So back to Figma — one of the unsung heroes of this architecture is the persistence layer. The server stores the full CRDT history as a log of operations, not the final state. That means if a client joins a file after it's been heavily edited, it can replay the operations to reconstruct the state. Luna: That's similar to how Git works — you store the commits, not the final file. Lucas: Exactly. But replaying five hundred thousand operations can be slow. So Figma periodically snapshots the CRDT state — like a checkpoint. When a new client connects, it receives the latest snapshot and then applies only the operations after that snapshot. The snapshot is stored as a binary blob in S3, and the server keeps a pointer to the most recent snapshot. That reduced join time for large files from minutes to a few seconds. Luna: And what about the server infrastructure? How many servers do they need to support that many editors? Lucas: Interestingly, because the CRDT does most of the work on the client, the server can be relatively lightweight. Each server instance can handle about ten thousand concurrent connections for a single file. For a file with five hundred thousand editors, they need about fifty server instances — but those instances don't need to coordinate with each other. Each one is stateless except for the CRDT log, which is stored in a shared database. Luna: So the servers are just message routers and persistence nodes. Lucas: Essentially, yes. The real complexity is in the client-side CRDT. And that's where Figma invested most of their engineering — a small team, maybe eight people, worked on the sync engine for about two years. Their CTO, Evan Wallace, was deeply involved in the CRDT design. He described it as 'the hardest thing we've ever built'. Luna: It's impressive that a relatively small team could build something that scales to half a million concurrent editors. Lucas: It's a testament to the CRDT approach. Once you nail the data structure, the rest scales naturally. But they also had to solve a lot of edge cases — like what happens when a user's browser crashes and they reconnect with a stale state. The CRDT handles that through a 'state reconciliation' process where the client sends its current version vector and the server responds with all the operations it missed. Luna: That's efficient — no need to re-sync the entire file. Lucas: Right. And the version vector is just a few hundred bytes, so the handshake is fast. The average reconnection takes under a second even for files with hundreds of thousands of operations. Luna: So what's next for Figma's sync engine? Are there limitations at even larger scales? Lucas: The biggest challenge is memory on the client. Each client holds the entire CRDT state in memory — that's the whole file history. For a very complex file with millions of operations, the memory footprint can exceed one gigabyte. That's a lot for a browser tab. Figma is working on a technique called 'operation pruning' — they can discard older operations that are no longer needed for convergence, keeping only the current state and a limited undo history. Luna: That would make the client leaner and allow even larger files. Lucas: Exactly. And it's a good reminder that even the most elegant distributed systems still have to deal with resource constraints. But for now, Figma's crdt based approach is arguably the most advanced real-time collaboration engine in production, and it's a model for any team building multiplayer tools at scale.