Data Storage Pattern
Data Storage Patterns & Tenant Isolation
1. Executive Summary & Core Storage Patterns
SiteSwarm’s storage patterns align with its capability hosting model (CAPABILITY_MANAGEMENT.md) while avoiding unnecessary worker sprawl:
- App-Hosted Storage (
app-hosted— Dedicated Per-Client Resources):- Direct Binding on the Client Worker: When an
app-hostedorcustomcapability is lightweight and does not warrant the overhead of a separate Cloudflare Worker, the client application worker (apps/<client>) can bind directly to its dedicated Cloudflare D1 database or R2 storage—provided doing so does not bloat the worker bundle or interfere with our edge caching and content-serving strategy (APP_SERVING_CACHE.md). - Isolated Backing Service Worker: When an
app-hostedcapability carries heavy dependencies or an administrative studio (such as the client’s CMS), the dedicated D1 and R2 bindings attach to a separateapp-hostedservice worker invoked over a Cloudflare Service Binding (MULTI_WORKER_PLATFORM_SERVICES.md).
- Direct Binding on the Client Worker: When an
- Platform-Hosted Shared Storage (
platform-hosted): Central platform services that client applications plug into via Service Bindings (such as Critiques) manage state in shared platform storage partitioned by verifiedtenant_id. - Enterprise External Storage via Cloudflare Hyperdrive (Anticipated Future Pattern): While no active clients use this model yet, we anticipate that future clients bringing pre-existing external databases (e.g., PostgreSQL) will connect via Cloudflare Hyperdrive for edge connection pooling and query caching.
flowchart LR ClientWorker["Client Public Worker\n(apps/<client>)"] -->|"Direct Binding\n(Lightweight App-Hosted / Custom)"| DirectStore["Dedicated Client D1 / R2"] ClientWorker -->|"Service Binding\n(Heavy App-Hosted, e.g. CMS)"| AppService["App-Hosted Service Worker"] AppService --> AppStore["Dedicated Client D1 / R2"] ClientWorker -->|"Service Binding\n(Platform-Hosted)"| PlatService["Shared Platform Worker"] PlatService --> PlatStore["Tenant-Partitioned Storage"]2. Core Storage Invariants
- Preserve Edge Caching & Fast Serving: Any direct storage binding on the public client worker must remain compatible with our edge caching and content-serving strategy (
APP_SERVING_CACHE.md); heavy administrative or mutation-heavy workloads belong behind Service Bindings. - Tenant Scoping on Shared Services: All multi-tenant queries in
platform-hostedservices require parameterized statements scoped by verifiedtenant_id. - Data Integrity & Built-in Recovery: Cloudflare D1 provides continuous 30-day Point-in-Time Recovery (PITR) for tenant databases, and client data can be exported cleanly at any time via the offboarding procedure in
CLIENT_OFFBOARDING.md.