A CRDT of plain maps, which devices merge in any order without conflict.
A state is a map of collections, each a map of entries, maybe nested by more keys, with the :device that the state belongs to and its :clock. An entry is stamped with :updated-at and :device, and a removed entry is a tombstone with :removed?.
A schema maps the key of each collection to its options:
:depth, the number of keys that lead to each entry
:compact?, to drop its tombstones once every device has seen them
:count-key, the key of a count in each entry, which only grows
{:notes {:depth 1 :compact? true} :listened {:depth 3 :count-key :seconds}}
The registry of devices, under :devices and :retired, needs no schema.
The comments in the code name the source of each part, and where it departs from it:
A CRDT of plain maps, which devices merge in any order without conflict.
A state is a map of collections, each a map of entries, maybe nested by
more keys, with the :device that the state belongs to and its :clock. An
entry is stamped with :updated-at and :device, and a removed entry is a
tombstone with :removed?.
A schema maps the key of each collection to its options:
- :depth, the number of keys that lead to each entry
- :compact?, to drop its tombstones once every device has seen them
- :count-key, the key of a count in each entry, which only grows
{:notes {:depth 1 :compact? true}
:listened {:depth 3 :count-key :seconds}}
The registry of devices, under :devices and :retired, needs no schema.
The comments in the code name the source of each part, and where it
departs from it:
- Shapiro, Preguiça, Baquero and Zawirski, A comprehensive study of
Convergent and Commutative Replicated Data Types, INRIA RR-7506, 2011,
https://inria.hal.science/inria-00555588
- Almeida, Approaches to Conflict-free Replicated Data Types, ACM
Computing Surveys 57(2), 2024, https://arxiv.org/abs/2310.18220
- Johnson and Thomas, The Maintenance of Duplicate Databases, RFC 677,
1975, https://www.rfc-editor.org/rfc/rfc677
- Kulkarni, Demirbas, Madappa, Avva and Leone, Logical Physical Clocks,
OPODIS 2014, https://doi.org/10.1007/978-3-319-14472-6_2
- Almeida, Shoker and Baquero, Delta State Replicated Data Types,
Journal of Parallel and Distributed Computing 111, 2018,
https://arxiv.org/abs/1603.01529Ordered collections in a mind-meld state, e.g. a queue, which devices change in any order without conflict.
An ordered collection is a map of id to an entry with a :rank, a string that sorts by the entry's place. A move can go in a second map of the same ids, whose entries hold only the new rank, so that a move never brings back what another device removed. A schema marks both :ranked?:
{:queue {:depth 1 :ranked? true}
:queue-moves {:depth 1 :ranked? true}}
The comments name the source of each part, and where it departs from it:
Ordered collections in a mind-meld state, e.g. a queue, which devices
change in any order without conflict.
An ordered collection is a map of id to an entry with a :rank, a string
that sorts by the entry's place. A move can go in a second map of the
same ids, whose entries hold only the new rank, so that a move never
brings back what another device removed. A schema marks both :ranked?:
{:queue {:depth 1 :ranked? true}
:queue-moves {:depth 1 :ranked? true}}
The comments name the source of each part, and where it departs from it:
- Wallace, Realtime Editing of Ordered Sequences, Figma, 2017,
https://www.figma.com/blog/realtime-editing-of-ordered-sequences/
- Kleppmann, Gomes, Mulligan and Beresford, Interleaving anomalies in
collaborative text editors, PaPoC 2019,
https://doi.org/10.1145/3301419.3323972
- Kleppmann, Moving Elements in List CRDTs, PaPoC 2020,
https://doi.org/10.1145/3380787.3393677Ranks: strings that sort where an item was put, and always leave room for another between any two.
A rank is digits in base 62, from 0 to 9, A to Z and a to z. It's read as a fraction with no trailing zero, and compared as a string. At either end of a list, the ranks count up or down like numbers, so they stay short however long the list grows.
This is fractional indexing as Wallace describes it in Realtime Editing of Ordered Sequences (Figma, 2017), except that the ranks count like numbers at the ends: https://www.figma.com/blog/realtime-editing-of-ordered-sequences/
Ranks: strings that sort where an item was put, and always leave room for another between any two. A rank is digits in base 62, from 0 to 9, A to Z and a to z. It's read as a fraction with no trailing zero, and compared as a string. At either end of a list, the ranks count up or down like numbers, so they stay short however long the list grows. This is fractional indexing as Wallace describes it in Realtime Editing of Ordered Sequences (Figma, 2017), except that the ranks count like numbers at the ends: https://www.figma.com/blog/realtime-editing-of-ordered-sequences/
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |