How instantdb/instant works
Main Components
a. Client-Side Components:
• Client SDK Layer (with variants for React, React Native, and Vanilla JS)
• Client-side Triple Store
• Local Storage (IndexedDB/AsyncStorage)
• Query Interface
• Transaction Manager
b. Server-Side Components:
• Sync Server (Clojure)
• Query Engine (InstaQL/Datalog)
• Permissions System (CEL)
• WAL Listener
• Multi-tenant PostgreSQL Database
Key Relationships to Highlight
a. Data Flow:
• Client to Sync Server communication
• WAL change propagation
• Query invalidation paths
• Transaction synchronization
• Real-time updates flow
b. Storage Relationships:
• PostgreSQL to Triple Store mapping
• Local cache synchronization
• Offline data persistence
┌─ Client Layer ──────────────────────────────────┐
• ┌─ SDK Implementation ─┐ ┌─ Local Storage ───┐ │
• React │ │ - IndexedDB │ │
• React Native │──│ - AsyncStorage │ │
• Vanilla JS │ └──────────────────┘ │
• ┘ │
• ┌─ Client Store ───────────────────────────┐ │
• Triple Store │ │
• Query Cache │ │
• Transaction Queue │ │
• ┘ │
• ┘
┌───────────────────▼──────────────────────────┐
• ┌─ Sync Server ──────┐ ┌─ Query Engine ───┐ │
• Real-time Sync │ │ - InstaQL │ │
• Query Handler │──│ - Datalog │ │
• WAL Listener │ └────────────────┘ │
• ┘ │
• ┌─ Security Layer ────────────────────────┐ │
• CEL Permissions │ │
• Authentication │ │
• ┘ │
• ┘
┌───────────────────▼──────────────────────────┐
• ┌─ Database Layer ────────────────────────┐ │
• Multi-tenant PostgreSQL │ │
• Triple Store Schema │ │
• WAL │ │
• ┘ │
• ┘
Additional Elements
• Version indicators for different SDK implementations
• Offline capability paths
• Multiplayer synchronization flows
• Optimistic update paths
• Permission check points
Implementation Details to Note
• The system uses a triple store model for data storage
• WAL tailing for change detection
• CEL-based permission system
• Multi-tenant architecture
• Client-side caching strategy
• Real-time synchronization mechanisms