ADR-011: Static World Replication (v0)
Metadata:
- ID: ADR-011
- Status: Accepted
- Date: 2025-03-21
- Tags: [replication, networking, regions, prims]
- Decision Type: architecture_pattern
- Related: [ADR-002, ADR-009, ADR-010, ADR-012, ADR-013]
- Supersedes: []
- Superseded By: []
Context
Problem: Clients need regions and prims from the authoritative store (ADR-002) without opening SQLite over the network (ADR-013).
Requirements:
- Snapshot on join (after handshake, ADR-009)
- Minimal deltas for v0 (coarse-grained acceptable)
- Server-assigned ids for any entity created at runtime
- No CRDT / full distributed editing in this ADR
Decision
Replicate static world as DTOs (RegionDto + PrimDto) over ADR-009: an initial WorldSnapshot { tick, regions, prims, avatars }, then small delta messages as edits occur.
As built (crates/cartopolis_core/src/protocol.rs):
- Deltas:
PrimUpsert { prim: PrimDto }(whole-prim replace after create/update) andPrimRemoved { id: i64 }(delete-by-id) — no field-level bitfields. - Ids:
i64, stable in the DB and server-assigned; the server never trusts client-proposed ids for new objects. - Serialization:
serdeDTOs incartopolis_core, postcard-encoded (same codec as ADR-009). - Evolution: per-client dirty masks / fine-grained component sync are out of scope here.
Rationale
Primary Reasoning:
- Matches current data model: regions and prims already map to SQLite rows.
- Fast to ship: DTO snapshot is simpler than full component-attribute replication.
- Room to optimize: field-level sync can come later without blocking v0.
Alternatives Considered:
| Alternative | Pros | Cons | Rejected Because |
|---|---|---|---|
| Full EC-attribute replication | Fine-grained | Huge spec + code | Too ambitious for v0 |
| CRDT scene graph | Offline-friendly | Complexity | Wrong problem for authoritative sim |
| Filesync assets | Simple | Not real-time | Separate asset ADR later |
Consequences
Positive:
- Client can spawn Bevy entities from DTOs (ADR-003)
- Clear extension toward fine-grained sync
Negative:
- Large worlds = large snapshots (mitigation: ADR-012 interest + chunking)
- Duplicate data in memory on server and clients (mitigation: acceptable for early scale)