An Interactive Intro to CRDTs
7 hours ago
- #collaboration
- #CRDT
- #distributed-systems
- CRDTs (Conflict-free Replicated Data Types) are data structures that allow peers to update their own state without immediate network synchronization, eventually converging to a single state.
- There are two types of CRDTs: state-based (transmit full state) and operation-based (transmit only actions). State-based CRDTs are simpler but require more data transfer.
- A CRDT must implement a merge function that is commutative, associative, and idempotent to ensure consistent state across peers.
- The Last Write Wins Register (LWW Register) is a simple CRDT that uses timestamps and peer IDs to resolve conflicts, always keeping the last written value.
- The Last Write Wins Map (LWW Map) is a more complex CRDT built using LWW Registers for each key, allowing collaborative editing of key-value pairs.
- CRDTs use tombstones (null values) to track deletions, ensuring that deletions are correctly propagated and not mistaken for missing keys.
- CRDTs are monotonically increasing data structures, meaning they can only add information, not remove it, which can lead to growing state size.
- The article demonstrates building a collaborative pixel art editor using CRDTs, showcasing their practical application in real-time collaborative apps.