Systemsfor Aravinda
0 / 78 core
Week 12 · Production stories

Figma multiplayer

1 hours · core path

Read first: Networking for request paths, Consistency models

In one sitting

Figma's server is the authority. The last update to reach it wins for that property, unrelated properties both survive, and text is one string with no character merge. Sibling order is a fraction between 0 and 1 stored as a base-95 string, and two clients who insert in the same gap can interleave.

The server is the authority for a Figma file. Clients send updates over a WebSocket, and the server broadcasts them. Several people can edit one file because arrival order at that server is the order of the document, property by property.

The problem

A design file is a tree of objects. Two people are in it at once. They usually touch different objects, and sometimes different fields of the same object. Occasionally they type into the same text, or they insert two new siblings between the same pair.

If every client merges for itself, each replica has to accept updates with no central judge and still converge. That is a CRDT: the merge is designed so replicas agree, and the metadata that makes the merge work grows with the design. Figma has a server on the connection. They used it as the judge and declined the metadata.

The product constraint they state is the other half of the problem. Figma is a design tool. Text on the canvas is a label, not a shared manuscript. A merge that keeps both people’s characters is what a text editor owes you. A design tool can keep one of the two strings.

The design

Arrival order, per property

A WebSocket starts as an HTTP upgrade and then stays full duplex. The process that holds the socket is stateful for as long as the socket lives. Figma’s clients send updates on that socket. The server broadcasts what it has accepted. The next edit from that client wants a server that can order it against everyone else’s edits. In their design that server is the authority, so the order is a single arrival order. You do not need a separate clock to decide which write was last.

Conflict resolution is per property on an object. The last update to reach the server wins for that property. Unrelated properties do not conflict. Take one object with a position and a fill. Alice sets the fill. Bob sets the x position. Both updates are still in the document after the server has broadcast them, because they name different properties. Alice and Bob both set the fill. The fill that reaches the server later is the fill that remains. The earlier fill is gone. There is no merge of the two colors.

This is the shape of a last-writer-wins register. Taught as a CRDT, that register needs a total order, usually a timestamp plus a replica id, because no replica is allowed to be the judge. Figma’s server is the judge. Arrival at that server is the order of the updates. They do not attach a timestamp to break ties. The tie is broken by which update the server applied second.

flowchart LR
  alice[Alice]
  bob[Bob]
  server[Authority server]
  peers[Other clients]
  alice --> server
  bob --> server
  server --> peers

The diagram is the whole consistency story. There is one box that orders updates. Clients that have not yet received the broadcast are behind that box. They catch up when the broadcast arrives. A client does not reconcile a private branch against another private branch.

Text is one property

Text is a single property value. Two people editing the same text can end with one of the two strings. They do not get a character-level merge.

Alice sends text = "Checkout"
Bob sends text   = "Check-out"
server applies Alice, then Bob
stored text      = "Check-out"

Reverse the arrival and the stored value is “Checkout”. Nothing in the design produces “Check-out” by splicing the hyphen into Alice’s word, and nothing produces a concatenation. The property is replaced. They say that is acceptable because Figma is a design tool, not a text editor. If the product were a manuscript, this trade would be the bug. The product is the reason the trade is honest.

Fractional indexes

Siblings in a list need an order: which layer is in front, which row is above which other row. An integer rank of 1, 2, 3 forces a renumber when someone inserts between 1 and 2. Every later sibling changes. Figma stores a fractional index instead: a fraction strictly between 0 and 1.

The fraction is stored as a string so they do not run out of precision. A fixed-width fraction has a fixed set of representable values. Average two values that are already neighbors in that set and the average rounds back to one of them. The gap has closed. You cannot insert there anymore. A string can grow. One more character still sorts between the two neighbors, so the gap reopens.

The string is base 95, and it is stored without the leading “0.”. The value is the digits of a fraction between 0 and 1. Comparison of those strings is the comparison of the fractions. This page does not list the 95-character alphabet. You do not need the alphabet to use the idea.

Inserting between two siblings averages their indexes. A decimal stand-in makes the average visible. The stored form is the base-95 string, not these decimals.

decimal stand-in, not the stored encoding
left sibling   = 0.20
right sibling  = 0.60
inserted index = (0.20 + 0.60) / 2 = 0.40

A second insert between the new sibling and the right neighbor averages 0.40 and 0.60 and lands at 0.50. Each insert needs a value strictly between its neighbors. The string exists so that “between” remains possible after many inserts in the same region of the list.

How much room does an extra digit buy? Base 95 gives 95 symbols at the next position.

one extra digit  = 95 slots inside a gap
two extra digits = 95 * 95 = 9025 slots

That is a derivation from the base they published, not a measurement of their lists. It is why they accepted a variable-length string instead of a machine float. You can keep bisecting.

Concurrent inserts interleave

The average is computed from the siblings the client can see. Two clients can insert between the same pair before either one has seen the other’s broadcast.

both clients see neighbors 0.20 and 0.60
client A computes (0.20 + 0.60) / 2 = 0.40
client B computes (0.20 + 0.60) / 2 = 0.40

The server accepts both inserts. They are different objects, each with an index property, so this is not last-writer-wins on one property. Both siblings exist. They carry the same index, so the index does not say which one is first. They interleave. That is the trade Figma accepted.

If client B had already received A’s insert, B would average 0.40 and 0.60 and store 0.50. The tie happens because both averages used the same parents. Both objects stay in the document. The shared index does not put one ahead of the other, which is the interleaving they accepted.

What happened What the document holds afterward
Two updates, two properties of one object Both properties change
Two updates, one property of one object The later arrival at the server
Two updates to the same text One of the two full strings, the later arrival
Two inserts between the same siblings, before either broadcast Both new siblings, and equal indexes do not order them

Hold those four rows apart. The first three are last arrival on a property. The fourth is two creates that happen to pick the same fraction. Treating the fourth as last-writer-wins would delete one of the siblings. That is not the published design.

What they traded

Choice What they gained What they spent
One server orders every update A total order with no replica metadata and no timestamp A client the server cannot see has no way to merge on its own
Last arrival wins per property An edit to fill survives an edit to position Two edits to the same property keep only the later one
Text is a single property The same rule as every other field, which matches a design tool No character-level merge, so one of the two strings is discarded
Fractional index, averaged, stored as a base-95 string Insert between siblings without renumbering the rest of the list Two clients who average the same pair can tie, and those inserts interleave

The first row is the CRDT decision stated as a cost. A CRDT pays metadata so that replicas with no central authority still converge. Figma has a central authority. Paying the metadata would buy a merge they can already get by waiting for the server. They did not pay it.

The last row is the one people skip when they retell the design as “the server orders everything, so the list is always ordered.” The server orders the updates it applies. The index values were chosen on the clients, from the siblings those clients had seen. Equal indexes are a real outcome. Interleaving is the published consequence, and they accepted it.

What to steal

If your system has a server on the write path, let that server be the authority. Order updates by arrival. Split conflicts by field so two people who touched different fields both keep their work. Say, out loud, which fields are last-arrival and which creates can tie. Text on a canvas can be last-arrival. A manuscript cannot, and you should not pretend a design-tool rule is a document rule.

Copy the list idea in its small form. Give each sibling an order key, and allocate a new key between two neighbors so an insert does not rewrite every later row. Know that two clients who allocate from the same neighbors can pick the same key. If that tie would corrupt the product, the server has to assign the key, or the second client has to recompute after it sees the first insert. Figma let the tie stand. You have to decide whether your list can stand it.

Leave the rest. Do not build a CRDT for a five-person app that already has one orderer. The metadata is the cost they looked at and refused, and your app has the same reason to refuse it until the day you actually have replicas with no central authority. Do not implement a base-95 fraction on the first ordered list you ship. A string rank, or integers with gaps, copies the idea that insert-between beats renumber-everyone. Base 95 is how you keep precision after a float would have collapsed. You get there when a gap has actually collapsed, not on the first schema. Do not character-merge a label.

In five minutes: the server is the authority, last arrival wins per property, text is one of the two strings, sibling order is a fraction between 0 and 1 stored as a base-95 string without the leading “0.”, and concurrent inserts that average the same pair can interleave. If you remember nothing else, remember that the system is inspired by CRDTs and has a central authority, so it is not one.

Check yourself

Alice changes the fill of an object and Bob changes its x position, and both updates reach the server. What does the object hold?

Both changes. Fill and x are different properties, and unrelated properties do not conflict. Last arrival matters only inside a single property. The server broadcasts both updates. Neither one is discarded because of the other.

Alice and Bob both set the text of that same object, Alice to one string and Bob to a different string. What can the stored text be?

One of the two full strings. Text is a single property, so the update that reaches the server later replaces the property. The earlier string is gone. The design does not splice characters from the two strings into a third string. Figma calls that acceptable because the product is a design tool, not a text editor.

Two siblings have decimal stand-in indexes 0.20 and 0.60. What index does an insert between them get, and what happens if two clients do that before either sees the other?

The insert averages the neighbors, (0.20 + 0.60) / 2 = 0.40. The stored form is a base-95 string of a fraction strictly between 0 and 1, without the leading 0., and the decimals here are only a stand-in. If both clients compute that average from the same pair, both new siblings store 0.40. Both objects exist. Equal indexes do not order them, so the inserts interleave. That is the trade they accepted.

A last-writer-wins register is something people teach next to CRDTs. Why is Figma's per-property rule still not a CRDT?

A CRDT is built so replicas with no central authority can accept updates and converge, and that design costs metadata. A last-writer-wins register in that setting needs a total order, usually a timestamp plus a replica id, because nobody is allowed to be the judge. Figma has a judge. The server defines the order by arrival, so they do not need a timestamp, and they do not pay the metadata. The design is inspired by CRDTs. The running system has a central authority.

Why store the fractional index as a base-95 string, and how many new slots does one extra digit add inside a gap?

A fixed-width fraction runs out of distinct values. Once two neighbors are adjacent in that set, their average is not a new index. A string can grow by one character and still sort between them. Base 95 means the next character has 95 symbols, so one extra digit adds 95 slots inside a gap. Two extra digits add 95 times 95, which is 9025. That is a derivation from the base, not a count of their layers. The leading 0. is omitted because the stored key is the digits.

Based on: Figma multiplayer posts.