advanced25 min studyLesson 257 in Engineering

Replicated sequences: identity is more stable than an index

Explain concurrent insertion, deterministic ties, stable references, and the limits of a simple fractional-position illustration.

On this page

What you’ll understand

  • Explain why a numeric array index is not a durable insertion identity.
  • Trace deterministic ordering of two concurrent insertions.
  • Distinguish convergence of a sequence from preservation of editing intent.

A collaborative text buffer changes while replicas are disconnected. An instruction such as insert at index three is ambiguous once other inserts or deletes arrive, because index three names a location in one particular view. Replicated sequences instead use stable element identities and an algorithm-specific ordering relation. The hard part is preserving a deterministic structure while concurrent edits refer to historical context that another replica may no longer display.

Stable identity outlives a visible position

Give each inserted element an immutable unique identity. Depending on the algorithm, an insertion can refer to a predecessor or a pair of neighbors, or allocate an ordered position identifier between existing positions. The displayed index is then derived from the current visible sequence. A delete identifies an element rather than asking each receiver to delete its current third character. Otherwise, replicas that receive operations in different orders could erase different content even when they all received the same human commands.

For a small illustration, attach a rational coordinate plus actor and local counter to an insertion and compare those tuples lexicographically. If two actors independently choose the same midpoint coordinate, the actor/counter suffix resolves their order deterministically. This illustrates ties only; it is not a complete sequence algorithm. A single rational coordinate with a suffix does not automatically let you allocate a new position between every tied pair. Real designs use specified identifier paths or ordering graphs with allocation and integration rules.

id⁡=(p,a,c),pmidpoint=pL+pR2\operatorname{id}=(p,a,c),\qquad p_{\rm midpoint}=\frac{p_L+p_R}{2}
p is a rational illustration coordinate, a is a stable actor tie-breaker, and c is a unique local insertion counter. The midpoint assumes p_L<p_R. This tuple example explains one concurrent tie, not a dense identifier-allocation algorithm for all future edits.↔ Scroll wide equations horizontally.

Deterministic integration needs more than sorting characters

If two inserts reference the same gap, every replica must apply the same tie rule regardless of arrival order. Depending on the type, this may produce stable ordering of identifiers while keeping runs together, or may interleave characters in surprising ways. The visible string is a projection of structural history. Two histories with the same visible string need not have interchangeable metadata, because future edits can still reference different deleted or hidden elements. Check the implementation’s operation and synchronization format rather than rebuilding it from visible text.

Deleting an element can leave structural information needed by later or delayed insertions. Some implementations retain a tombstone, others compress or garbage-collect under specific rules. Moves, rich-text marks, undo, and embedded objects need additional semantics; treating a move as unrelated delete and insert may lose identity or produce unexpected concurrent outcomes. A sequence CRDT guarantees a defined convergent structure under its assumptions, not that every concurrent edit order will read naturally to a human editor.

Nvisible=∣E∖D∣N_{\rm visible}=|E\setminus D|
E is the set of known inserted element identities and D is the set of deleted identities in a simple retained-history illustration. This counts visible elements, not bytes or Unicode user-perceived characters, and does not define a complete ordering algorithm.↔ Scroll wide equations horizontally.

Test histories at the user’s semantic level

Test concurrent inserts into the same gap, adjacent deletes, late references to deleted elements, and reconnecting clients with old state. For Unicode text, distinguish storage units, code points, and grapheme clusters before interpreting a count as characters. A correct user selection or cursor also needs a stable relative position rather than a raw index. Expose the actual behavior of concurrent edits and undo in a product demonstration; convergence alone can hide a consistent but confusing editing experience.

The cache lab illustrates a narrower identity-versus-order distinction. Reset, set capacity C=4 and stride s=8, predict requests alternating between addresses 0 and 8, then Step. Although recency order changes, address identity remains stable and only two addresses occur in the cycle. The lab is a deterministic LRU cache over a fixed address stream, not a replicated sequence or text editor. Use it only to distinguish an item’s identity from its changing position in an ordered view; sequence insertion needs the explicit rules above.

Concurrent midpoint ties

A teaching sequence has L at coordinate 0 and R at coordinate 1. Actors A and B concurrently insert x and y at coordinate 1/2, with IDs (1/2,A,1) and (1/2,B,1). Assume A sorts before B.

  1. Both insertion coordinates lie strictly between zero and one, but the coordinates tie with each other. Arrival order is not used to break that tie.

  2. The specified actor order places x before y at every replica. The resulting visible sequence is LxyR, containing four element identities and four displayed ASCII characters in this example.

  3. Deleting x by its unique identity leaves LyR, with three visible elements. The stored history can still contain four insertions and one deletion; a future insertion between the tied positions requires a real allocation scheme beyond this toy midpoint rule.

The result

A deterministic suffix resolves this concurrent gap tie. It does not turn fractional indexing alone into a complete replicated-sequence protocol.

Explore the model

Interactive lab

Interactive lab · cache

Identity remains while an ordered view changes

Reset, set cache capacity C=4 and request stride s=8, predict alternating addresses 0 and 8, then Step. The LRU cache’s recency order changes while address identities persist. This is not a sequence CRDT, editor, or insertion-allocation model.

Identity remains while an ordered view changesA fully associative LRU cache starts empty and requests address (i·s) mod 16. Hits move an address to the newest position; misses evict the oldest when full. Playback starts with 16 requests and adds two per second, capped at 4096 explicitly simulated requests. This toy stream is not a processor-cache benchmark. Current readings: Hits / requests: 0 / 16; Hit rate: 0%; Address-stream period: 16 addresses. All parameters are adjustable with the labeled controls below.Fully associative LRU cache after 16 deterministic requests: 0 hits and 16 misses.Most recent 16 requestsaddress = i × 3 mod 160M3M6M9M12M15M2M5M8M11M14M1M4M7M10M13MCurrent cache order · oldest → newest471013Latest address 13 · miss: inserted as newestToy address stream · period 16 · starts empty
Cached addressMiss / evictionMost recent request
Hits / requests
0 / 16
Hit rate
0%
Address-stream period
16 addresses
t = 0 s

A fully associative LRU cache starts empty and requests address (i·s) mod 16. Hits move an address to the newest position; misses evict the oldest when full. Playback starts with 16 requests and adds two per second, capped at 4096 explicitly simulated requests. This toy stream is not a processor-cache benchmark. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forAn item’s identity and its current index in a view are separate facts.

Check your understanding

Why is delete element with ID A7 safer than delete current index 3 for replicated editing?

Try it yourself

Five inserted identities are known, and two distinct identities are deleted. How many remain visible in the simple model? If two visible elements share the same rational coordinate, does midpoint allocation alone guarantee an insertion between them?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Count identities separately from their order, then check the strict midpoint precondition.

Compare with the solution

Three identities remain visible. If the two coordinates are equal, their midpoint equals that coordinate too; a suffix can resolve a tie but does not by itself provide arbitrary dense allocation between tied tuples. A complete sequence algorithm must specify how such positions are represented and integrated.

Take it with you

  • Displayed indices are derived views, while element identities remain stable.
  • Concurrent ties need a deterministic algorithm-specific integration rule.
  • Convergence and intuitive editing behavior require separate evaluation.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.