Latest / The CTO Podcast with Fexingo: Technical Leadership, Architecture, and Engineering Org / How Figma Uses Real-Time Sync Without Breaking Git
Transcript
- Lucas: Figma is one of those rare products where the user experience feels like magic — two people moving pixels on the same canvas, seeing each other's cursors in real time. But behind that magic is a genuinely hard engineering problem: how do you synchronize state across dozens of clients without losing history or introducing conflicts? Luna: And they chose CRDTs — conflict-free replicated data types — over the operational transform approach that Google Docs made famous. That's a pretty fundamental bet. Lucas: Right. CRDTs let each client operate independently and merge later without a central conflict resolver. Figma's team wrote a custom implementation called 'Figma Sync' that sits on top of WebSockets. It's not a library you can just pull off the shelf. Luna: Before we go deep on that — we should mention that this show stays ad-free by design. If you find these deep dives useful for what you're building, you can support the no-ads choice at buy me a coffee dot com slash fexingo. Lucas: Yeah, it's a small way to keep the conversation focused on engineering decisions rather than sponsor interruptions. Back to Figma — the interesting part is how they layer Git on top of a real-time system. Luna: Git is deterministic and snapshot-based. Real-time sync is continuous and conflict-tolerant. Those are almost opposite paradigms. Lucas: Exactly. Figma's solution is to treat the real-time state as a 'working tree' — every keystroke or drag updates an in-memory CRDT buffer. Then periodically — or on explicit save — that buffer gets flattened into a snapshot that Git can track. The Git history doesn't record every cursor move; it records meaningful checkpoints. Luna: So the CRDT handles the fine-grained sync, and Git holds the coarse version history. That's clean architecturally, but it means the merge logic has to bridge two different consistency models. Lucas: And that bridge broke in 2022. There was an incident where a specific race condition in the CRDT merge caused about ten percent of users to lose access to their files for a few hours. Figma published a postmortem that's worth reading. Luna: What was the root cause? I remember the outage but not the details. Lucas: The sync protocol uses Lamport clocks to order operations. But the merge logic had a bug where two clients could produce operations with identical timestamps on different branches — and the resolution logic didn't handle that case correctly. It created a cycle in the dependency graph, and the merge couldn't complete. Luna: So the file essentially froze. That's the nightmare scenario for a collaborative tool. Lucas: The fix was to add a deterministic tiebreaker — not based on client ID, but on a hash of the operation content itself. That way, identical timestamps always resolve to the same merged state regardless of which client processes it first. It's a small change with big implications for correctness. Luna: And they also improved their testing around concurrent operations — I think they introduced a fuzzing framework specifically for the sync layer. Lucas: Yes. They built a simulator that generates random sequences of edits across virtual clients, then checks that the final state is deterministic and consistent. That's the kind of investment you make when your core differentiator is real-time collaboration. Luna: Let's talk about the performance side. Figma runs in the browser, but it's doing heavy vector rendering. How do they keep the WebSocket layer snappy? Lucas: They offload the rendering to a WebAssembly module written in Rust. The Wasm module handles all the canvas operations — path calculations, hit testing, bezier curves — while the JavaScript layer manages the DOM and the sync protocol. That split is critical. Luna: Rust gives them memory safety and predictable performance. But compiling to Wasm means the sync code has to communicate across that boundary efficiently. Lucas: Right. They use a shared memory buffer — essentially a typed array that both JS and Wasm can access. The CRDT operations are encoded as a sequence of integers in that buffer, so the Wasm layer can apply them without serialization overhead. It's a bespoke protocol, not JSON over the wire. Luna: That's a big contrast from most web apps, which default to JSON. Figma's approach is closer to how game engines handle network state. Lucas: And that's intentional. The team has said they looked at how multiplayer games like Fornite handle state synchronization — lockstep simulation, delta compression, interest management. They borrowed the concept of 'interest sets' — you only sync the parts of the canvas that are visible to each user. Luna: So if you're zoomed into one corner of a massive design file, you're not receiving updates about elements on the other side. That's smart bandwidth management. Lucas: Exactly. And it ties back to the CRDT design: each element in the document has its own unique ID and its own CRDT instance. So the sync layer only subscribes to the IDs in the current viewport. When you pan or zoom, it subscribes to new IDs and unsubscribes from old ones. Luna: That sounds straightforward, but maintaining consistency when you're joining mid-session must be tricky. You have to catch up on the state you missed. Lucas: They call that 'snapshot sync'. When a client subscribes to a new element ID, the server sends a compressed snapshot of that element's current state — not the full operation log. Then subsequent operations are streamed incrementally. It's a hybrid of snapshot and log-based replication. Luna: So the server acts as both a state store and an operation relay. That's a lot of responsibility on the backend. Lucas: And they chose to run that on AWS using a mix of EC2 and Lambda for different workloads. The WebSocket connections are managed by a fleet of 'sync servers' — stateless nodes that maintain in-memory state for active sessions. If a sync server fails, clients reconnect to another server and rebuild state from snapshots. Luna: Stateless but with in-memory state? That sounds contradictory. Lucas: The state is ephemeral — it only exists for the duration of a session. Persistent storage is in DynamoDB and S3. So the sync servers can be replaced without data loss. The trade-off is that reconnecting after a failure takes a few seconds because you have to replay the snapshot. Luna: That's acceptable for design work. A two-second reconnection is better than losing your edits. Lucas: And they've optimized that path heavily. The snapshot format is a flat buffer — no nested JSON — so it can be deserialized in a single pass. The Wasm module handles that too, which keeps the main thread free for user interaction. Luna: So the real-time sync architecture is deeply intertwined with the rendering pipeline. They're not separate concerns — they're designed together. Lucas: That's the key insight. Figma's engineering team has a strong culture of 'design-driven development' — they start with the user interaction and work backward to the system design. The CRDT choice, the Wasm rendering, the interest sets — all of it is in service of making collaborative editing feel like working locally. Luna: Let's talk about the engineering org structure that made this possible. Figma's CTO, Dustin Brayshaw, has spoken about how they organize into small, autonomous teams around specific user workflows — not around technical layers. Lucas: Right. There's no 'sync team' or 'rendering team' in the traditional sense. Instead, you have a 'canvas team' that owns everything related to the design surface — rendering, input handling, zoom, pan, and the sync for those operations. They're responsible for the end to end experience. Luna: That prevents the 'handoff problem' where one team builds a feature and another team has to make it fast. The canvas team owns both the feature and the performance. Lucas: Exactly. And each team includes designers and product managers, not just engineers. That's the 'design-driven' part — the people who understand the user's workflow are embedded in the team that builds the technology. Luna: It's interesting that they've maintained this structure as they've grown from a small startup to a company with over a thousand employees. Many orgs fracture into specialized silos at that scale. Lucas: They've had to adapt. Early on, a single team owned the entire product. Now, teams own 'verticals' — like the prototyping team, the commenting team, the plugin platform. But the principle remains: each vertical has full ownership of its slice of the stack. Luna: What about cross-cutting concerns like the sync protocol? If every team touches it, how do you avoid inconsistency? Lucas: They have a small 'platform team' that maintains the core CRDT library and the WebSocket infrastructure. That team sets the API contracts and performance benchmarks. But the vertical teams decide how to use those primitives in their features. So the sync layer is a shared service, not a shared codebase. Luna: That's a subtle but important distinction. Shared services can evolve independently as long as the interface is stable. Luna: So the CRDT becomes a kind of universal data model for the entire product. That's a powerful abstraction, but it also means that mistakes in the CRDT design propagate everywhere. Lucas: Which brings us back to the 2022 outage. That bug was in the core CRDT merge logic — the part that's maintained by the platform team. It took them about three hours to fix and deploy, but the impact was broad because every team's features rely on that merge logic. Luna: They've since added invariant checks that run on every merge — essentially a 'sanity check' that the resulting state is internally consistent. If the check fails, the merge is rejected and the operation is retried with a different ordering. Lucas: That's a good example of building resilience into the protocol itself, not just relying on monitoring. The system can detect its own errors and recover without human intervention. Luna: So what's next for Figma's architecture? They're investing heavily in performance for larger files — files with thousands of artboards and complex vector networks. Lucas: They've been working on a feature called 'layered rendering' where elements outside the viewport are rendered at lower fidelity until you pan to them. And they're exploring server-side rendering for certain operations, so the client doesn't have to compute everything locally. Luna: That could be a big shift — moving some of the CRDT processing to the server side. Currently, the merge is fully client-driven, with the server acting as a relay. If the server starts doing merges, it changes the trust model and the latency profile. Lucas: It does. But it could also enable new use cases, like real-time collaboration on mobile devices with less powerful hardware. Offloading computation to the server would let Figma expand its user base. Luna: It's a fascinating trade-off. Figma's architecture is a case study in how to build real-time systems that feel local. The choices they made — CRDTs over OT, Wasm for rendering, interest sets, snapshot sync — are all lessons in prioritizing user experience over engineering simplicity. Lucas: And the lesson for CTOs is that your org structure needs to match your architecture. If you build a system with tight coupling between sync and rendering, you need teams that own both. Figma's design-driven verticals are the organizational mirror of their technical decisions. Luna: It's rare to see that level of coherence between product design, system architecture, and team structure. Most companies have at least one dimension misaligned. Lucas: Figma is the exception. And that's why their product feels like magic — the magic is the result of deliberate, consistent choices across every layer.