Latest / The CTO Podcast with Fexingo: Technical Leadership, Architecture, and Engineering Org / How Figma Scales Real-Time Collaboration With CRDTs
Transcript
- Lucas: If you've ever used Figma — and if you're in design or product, you almost certainly have — you've probably noticed that when someone else is on the same file, their cursor moves smoothly, shapes appear almost instantly, and you never see a loading spinner. That's not magic. That's a pretty sophisticated piece of distributed systems engineering. Luna: And the really wild part is that Figma does all of this in the browser, not a native app. So you're dealing with WebSocket connections, JavaScript, and still needing sub-100-millisecond sync. Lucas: Exactly. So today I want to unpack how Figma actually handles real-time collaboration under the hood. Specifically, their move from Operational Transform — which was the classic approach for years — to something called CRDTs, Conflict-Free Replicated Data Types. And why that switch matters for anyone building collaborative features. Luna: Before we dive deep — CRDTs have been around academically for a while. Why did Figma only migrate to them relatively recently? Lucas: Good question. Figma started around 2012, and at that time Operational Transform, or OT, was the proven approach. Google Docs used it. The theory was well-understood for text-based collaboration. But Figma isn't text — it's a vector graphics editor. You're moving rectangles, changing stroke widths, adjusting gradients. The operations are much more complex than inserting a character. Luna: So OT started to show its limits as Figma scaled from a few designers on a file to dozens or even hundreds? Lucas: Yes. OT requires a central server to order operations and transform them against each other. That works fine for two or three users, but as you add more collaborators, the transformation logic becomes a combinatorial explosion. You also have to handle undo, redo, version history — all of which become nightmare scenarios with OT. Figma's engineering team wrote about hitting a wall where the complexity of their OT algorithm was making it hard to add new features. Luna: So they switched to CRDTs. But CRDTs aren't a single thing — there are state-based and operation-based variants. Which one did Figma use? Lucas: They built their own custom operation-based CRDT. The key idea is that each change — like 'set the fill color of layer X to red' — is an operation that contains enough metadata to be applied in any order across replicas and converge to the same state. No central ordering needed. Each client maintains its own copy of the document, and operations are broadcast to all peers. Because the data type is designed to be conflict-free, merging is deterministic. Luna: But if there's no central server ordering, how do you handle two people editing the same property at the same time? Say, one sets the fill to red and the other sets it to blue. Lucas: That's where the 'conflict-free' part comes in. The CRDT defines a merge rule — usually a last writer wins strategy based on timestamps or some other total order. In Figma, each operation has a Lamport timestamp — a logical clock — and if two operations conflict, the one with the later timestamp wins. But because it's a CRDT, both clients will independently compute the same result. No server needed to arbitrate. Luna: So latency drops dramatically because you don't have to wait for a server to process and return the transformation. But what about consistency? If I'm offline for a bit and then reconnect, do I see the correct state? Lucas: Yes, and that's another advantage. CRDTs are inherently eventually consistent. When you reconnect, you send your backlog of operations, and the other peers merge them using the same deterministic rules. As long as the CRDT is designed correctly, everyone converges. Figma also uses a technique called 'squashing' to compress the operation log. If you've moved a layer ten times while offline, they don't replay all ten moves — they compute the net effect and send that. Luna: That's smart for bandwidth. But I remember reading about a Figma outage a couple years ago where some users lost data. Was that related to the CRDT implementation? Lucas: It was. In early 2022, Figma had an incident where a bug in their CRDT merge logic caused some vector networks to become corrupted. The issue was subtle: when two users both deleted and recreated a layer with the same ID in a certain order, the merge algorithm could produce a state where the layer existed but was disconnected from the parent. It affected a small percentage of files, but it was a reminder that CRDTs are mathematically elegant but still have edge cases in production. Luna: So how did they fix it? Did they patch the algorithm or add validation layers? Lucas: They added a multi-layered approach. First, they introduced an integrity check that runs after every merge — essentially a set of invariants that must hold. If the check fails, the client reverts to a known good state and re-fetches from the server. Second, they built a replay system that can reconstruct the exact sequence of operations for a file and verify the merge result. Third, they added more extensive fuzz testing to catch edge cases before deployment. Luna: That sounds like the kind of infrastructure you only build after you've been burned. But it also shows that even with a theoretically sound CRDT, you need robust production safeguards. Lucas: Absolutely. And this is where the engineering discipline really shines. Figma doesn't just rely on the math — they monitor merge latency, conflict rates, and divergence metrics in real time. They have dashboards that show, for every file, how far apart replicas are in terms of operation count. If that number exceeds a threshold, an alert fires and they can investigate before users notice. Luna: So they're treating collaboration almost like a database replication problem. Monitoring lag, conflict resolution, consistency checks — that's very database-like. Lucas: Exactly right. And that's the framing I think is most useful for engineers listening. If you're building any collaborative feature — even a simple shared todo list — you're effectively building a distributed database. The questions are the same: how do you handle concurrent writes, what consistency model do you promise, how do you recover from partition. Figma's CRDT approach is one answer, but it's not the only one. Luna: And speaking of building things — a quick honest thing. If these conversations about real-world systems are useful for what you're building or running, there's a small way to keep them coming. A handful of listeners chip in monthly through buy me a coffee dot com slash fexingo, and that's literally what funds making this many episodes. No ads, no sponsors — just listener support. Lucas: Yeah, it's a simple model. And it works because even a small number of people choosing to contribute makes the whole thing sustainable. If that's something you'd want to be part of, the link is easy to find. But back to Figma. Luna: So if someone wants to learn more about CRDTs — beyond what Figma did — where should they start? Lucas: I'd point them to Martin Kleppmann's work. He wrote a great paper called 'A CRDT Primer' and also has a talk on CRDTs for local-first software. Also, the Figma engineering blog has a three-part series on how they built their real-time infrastructure. That series goes into the specifics of their operation model, the serialization format, and the undo system — which is surprisingly tricky with CRDTs. Luna: Undo — right. If every operation is a CRDT operation that gets merged, how do you undo a specific change without breaking the merge? Lucas: Figma's approach is to treat undo as a new operation that reverses the effect of the original. So instead of literally removing the operation from history, you emit a counter-operation. That counter-op is itself a CRDT operation, so it merges correctly with concurrent changes. But you have to be careful about what 'undo' means in a multi-user context. If I undo my last action, but someone else already edited that same layer, the undo might not produce the state I expect. Figma handles this by scoping undo to the user's own actions and using a stack per user. Luna: That's a lot of complexity for a feature that most users take for granted. But it's the kind of detail that separates a polished product from a barely-working prototype. Lucas: Exactly. And I think that's the takeaway for today: building real-time collaboration isn't just about picking a library. It's about understanding the consistency model, the failure modes, and the operational overhead of your chosen approach. Figma made a deliberate bet on CRDTs, invested heavily in testing and monitoring, and it paid off with one of the smoothest collaborative experiences on the web. Luna: And now that they've proven it at scale, we're seeing more products adopt similar architectures. Even Google Docs has been experimenting with CRDTs for some features. So this isn't just a Figma story — it's a trend. Lucas: Absolutely. Next time you're on a Figma file with five other people and everything just works, you'll know there's a battle-tested CRDT under the hood. And if you're building something similar, you have a blueprint to learn from.