Meri Leeworthy

Roomy Sync Server

CRDT Sync

https://github.com/muni-town/roomy-services/blob/main/roomy-syncserver/main.ts

The code shows a thoughtful approach to building a CRDT sync server with some particularly interesting architectural decisions:

Most Notable Design Choices:

  1. AT Protocol Integration - Using decentralized identity (DIDs) instead of traditional user accounts is forward-thinking and aligns with web3 principles
  2. Two-Stage Authentication - The JWT → short-lived token → WebSocket flow is clever for security while maintaining performance
  3. Binary WebSocket Protocol - Smart choice for CRDT operations that need high throughput and low latency

The Good: The separation of concerns is clean, the security model is well-thought-out, and the use of Deno KV provides a simple but effective storage solution.

The Concerning: The missing DID caching (which they acknowledge) could become a major bottleneck, and the error handling is quite generic which could make debugging difficult in production.

Overall, this feels like a solid MVP architecture that could scale with some additional production hardening around caching, monitoring, and connection management.


CRDT Sync Server Architecture Review

Summary

This is a Deno-based CRDT synchronization server that provides real-time collaborative data sync capabilities. It integrates with the AT Protocol (ATProto) ecosystem for identity management and uses WebSockets for real-time communication. The server acts as a relay/coordination point for CRDT-based collaborative applications.

Key Components

Core Technologies

Authentication Flow

  1. JWT Validation: Uses ATProto JWT tokens verified against DID documents
  2. Token Exchange: Converts JWT to short-lived WebSocket tokens (30s TTL)
  3. WebSocket Auth: Uses Sec-WebSocket-Protocol header for token passing

Architectural Decisions Analysis

✅ Strengths

1. Decentralized Identity Integration

2. Security Design

3. Binary Protocol Efficiency

4. Clean Separation of Concerns

5. Development Ergonomics

⚠️ Areas of Concern

1. Token Storage Architecture

const tokenDid = (await kv.get<string>(["tokens", token])).value;

2. Error Handling

} catch (e) {
  console.error("Error validating JWT:", e);
  return error(403, "Could not validate authorization JWT.");
}

3. DID Resolution Performance

// TODO: add a DID cache using Deno KV
const idResolver = new IdResolver();

4. Resource Management

socket.addEventListener("close", () => {
  backend.cleanup();
});

5. Configuration Validation

🔄 Suggested Improvements

1. Implement DID Caching

// Cache DID documents with TTL
const didCache = new Map();
async function getCachedSigningKey(did: string) {
  // Implementation with cache-aside pattern
}

2. Enhanced Token Security

// Use cryptographically secure token generation
// Implement token revocation
// Separate token storage namespace

3. Connection Management

// Add connection limits per DID
// Implement heartbeat/keepalive
// Graceful shutdown handling

4. Observability

// Structured logging
// Metrics collection
// Health check endpoints

5. Error Granularity

// Distinguish between different error types
// Provide actionable error messages
// Rate limit error responses

Production Readiness Assessment

Ready ✅

Needs Work ⚠️

Missing ❌

Overall Assessment

This is a well-architected foundation for a CRDT sync server with thoughtful integration of modern decentralized identity systems. The core design decisions are sound, particularly the choice to use AT Protocol for identity and binary WebSocket transport for efficiency.

The main areas for improvement are around production hardening: caching, error handling, resource management, and observability. The TODO comment about DID caching shows awareness of the key performance bottleneck.

For a prototype or early-stage system, this architecture provides a solid foundation. For production deployment, addressing the identified concerns around performance, error handling, and resource management would be essential.

I live and work on the land of the Wurundjeri people of the Kulin Nation. I pay respect to their elders past and present and acknowledge that sovereignty was never ceded. Always was, always will be Aboriginal land.

This site uses open source typefaces, including Sligoil by Ariel Martín Pérez, and Vercetti by Filippos Fragkogiannis