Design Patterns

Proven patterns for structuring collaborative data that scales and handles concurrent edits gracefully.

Overview

These patterns emerge from real-world collaborative applications. They solve common problems like maintaining order while allowing concurrent edits, organizing complex hierarchies, and keeping data structures efficient.

Topics

Pattern Selection Guide

Your Need Recommended Pattern
Items that can be reordered ID-Based Storage + Ordering Arrays
Many small entities vs complex objects JSON vs Y.Map Tradeoffs
Hierarchical data (trees) ID-Based Storage with parent references
Large documents with many object types Separate Content Maps
Theming or default values Style Inheritance
Simple key-value storage Direct Y.Map (no special pattern needed)

The Most Important Rule

Never store complex objects in arrays that will be reordered.

This single rule prevents the most common and destructive CRDT bugs. When you need to reorder items:

  1. Store the actual content in a Y.Map keyed by ID
  2. Store only the IDs in a Y.Array for ordering
  3. Reorder by moving IDs in the array, not the content

See ID-Based Storage for complete examples.