CRDTs: The Hard Parts [video]
Great talk! I look forward to diving into &quot;Interleaving anomalies in collaborative text editors&quot; to see how Kleppmann et al fixed the RGA interleaving issue.<p>The section on moving items in a list makes my mind jump to Causal Trees (≈RGA). The problem here is that a) we need the concept of a list bucket or slot, and b) we also need to preserve the sequential integrity of runs of items as in text editing. In CT&#x2F;RGA, each letter&#x2F;item is simultaneously a list bucket and its contents. I wonder if this problem could be solved by adding a &quot;reanchor&quot; op that moves the &quot;contents&quot; (and some&#x2F;all children) of a letter op to the &quot;bucket&quot; of another letter op?<p>Each reanchor op would have the job of &quot;moving&quot; a subtree of text to a new parent bucket. (Under the hood, the subtree would obviously remain topologically unchanged for convergence purposes, but the reanchor op would inform how the tree is parsed and turned into a user-visible list or string.) First, the reanchor op would need to reference the start and end letter&#x2F;item ops in a given subtree; and second, the reanchor op would need to reference the letter&#x2F;item op into whose bucket the subtree contents will be moved. If the set of subtrees for a range of text&#x2F;items contains multiple independent subtrees, they would each need their own reanchor op. Concurrent moves of the same subtree would be resolved as LWW, similar to the Kleppmann proposal.<p>Let&#x27;s say you have a graph for string &quot;ABCD&quot; that looks roughly like this, sans metadata:<p><pre><code>        +---+
        | A |
        ++-++
         | |
      v--+ +--v
    +---+   +---+
    | B |   | C |
    +---+   +-+-+
              |
              v
            +-+-+
            | D |
            +---+
</code></pre>
If you wanted to move &quot;CD&quot; after &quot;A&quot;, you would add the following op:<p><pre><code>        +---+
        | A +&lt;---------+
        ++-++          |
         | |           |
      v--+ +--v        |
    +---+   +---+      |
    | B |   | C +&lt;---+ |
    +---+   +-+-+    | |
              |      | |
              v      | |
            +-+-+   ++-++
            | D +&lt;--+ m |
            +---+   +---+
</code></pre>
&quot;m&quot; references &quot;C&quot; and &quot;D&quot; as the subtree range, and &quot;A&quot; as the target bucket. The string would render as &quot;ACDB&quot;.<p>We can get cycles with this scheme, but as far as strings or lists are concerned, this doesn&#x27;t actually matter, since the parent references aren&#x27;t reflected in the output (as they would be with an explicit tree data structure). If, concurrently to this, another device wanted to move &quot;A&quot; after &quot;C&quot;, the merged graph would look like this:<p><pre><code>    +---+   +---+
    | m +--&gt;+ A +&lt;---------+
    +-+-+   ++-++          |
      |      | |           |
      |   v--+ +--v        |
      | +---+   +---+      |
      | | B |   | C +&lt;---+ |
      | +---+   +-+-+    | |
      +---------^ |      | |
                  v      | |
                +-+-+   ++-++
                | D +&lt;--+ m |
                +---+   +---+
</code></pre>
How does this get resolved? Well, we can simply read this as &quot;move the contents of &#x27;A&#x27; to the bucket for &#x27;C&#x27;, and move the contents of subtree &#x27;C&#x27; through &#x27;D&#x27; to the bucket for &#x27;A&#x27;.&quot; The string would consequently render as &quot;CDBA&quot;, as we would expect.<p>This is just a sketch, not sure if it would actually work in practice. Pain points are a) moving multiple subtrees in a somewhat atomic way (when the range to be moved covers more than a single run of items), b) sane results when overlapping ranges are moved concurrently, c) moving items to a bucket whose contents had already been moved before, and d) parsing performance, especially given the fact that we&#x27;ll now have ops (and their children) whose contents might end up in arbitrary places in the output string or list. Might just end up with a slow, confusing, and labyrinthine data structure.<p>There&#x27;s also the question of intent: does the user want to move a range of items to the slot currently occupied by a different item, or do they want to move that range to the right of that item? Lists of notes will want the former, while strings will usually want the latter. Perhaps the reanchor op could explicitly differentiate between these two cases.