← Lessons

quiz vs the machine

Gold1420

System Design

CRDT for Sequences

Ordering items in a shared list so concurrent inserts never collide.

5 min read · core · beat Gold to climb

The sequence problem

Text is one example of a sequence, but the same idea applies to lists of tasks, slides, or table rows. The core challenge is stable ordering: when two users insert between the same two neighbors at once, both items must appear and everyone must agree on their order.

Fractional positions

A popular technique assigns each element a fractional position between its neighbors. To insert between positions one and two, a client picks something like one and a half. Ties from concurrent inserts are broken by appending the author's replica id.

Avoiding interleaving

Naive fractional indexing can run out of precision after many inserts at one spot, so real systems use dense identifier trees that can always allocate a new id between any two existing ids.

The replica id tiebreak guarantees a total order, so even simultaneous inserts at the identical gap converge.

Key idea

Sequence CRDTs place items at stable positions between neighbors and break ties by replica id so all replicas agree on order.

Check yourself

Answer to earn rating on the learn ladder.

1. What is the core challenge for sequence CRDTs?

2. How are ties between two concurrent inserts at one spot resolved?