Cloudflare Workers Data Platform Integration -- Overview
Executive Summary
Company Manager is a multi-tenant SaaS platform (87 packages, 11 apps, 206+ services) running on Next.js 16 + TRPC + Prisma 7 + Neon PostgreSQL. The platform \1 (chat, rate-limiting, gaming, bookings) with Durable Objects and KV. This document set maps every relevant Cloudflare data platform product to concrete integration opportunities.
Current Architecture Snapshot
| Layer | Current | Cloudflare Replacement/Enhancement |
|---|---|---|
| Database | Neon PostgreSQL (Prisma 7) | **Hyperdrive** (connection pooling + cache) |
| File Storage | AWS S3 | **R2** (zero egress, S3-compatible) |
| Cache | Upstash Redis (limited) | **Workers KV** (global edge cache) |
| Message Queue | Bull on Upstash Redis | **Queues** (guaranteed delivery, DLQ) |
| Search | PostgreSQL tsvector | **Vectorize + Workers AI** (semantic) |
| AI Inference | OpenAI API (external) | **Workers AI** (edge inference, 50+ models) |
| Real-time | 4 Workers + basic WebSocket | **Durable Objects** (extend existing) |
| Analytics | Raw SQL aggregations | **Analytics Engine** (time-series) |
| Cron Jobs | Shell scripts (3h intervals) | **Workflows** (durable execution) |
| Edge DB | None | **D1** (per-tenant edge replicas) |
| Data Lake | None | **Data Platform** (Pipelines + R2 SQL) |
Existing Cloudflare Workers
chat-worker -> https://chat-worker.wd29.workers.dev
rate-limit-worker -> https://rate-limit-worker.wd29.workers.dev
gaming-worker -> https://gaming-worker.wd29.workers.dev
bookings-worker -> https://bookings-worker.wd29.workers.dev
These use Durable Objects, KV, and D1 already. The integration path is well-established.
Document Index
| Doc | Product | Priority | Impact |
|---|---|---|---|
| [01-hyperdrive-neon](./01-hyperdrive-neon.md) | Hyperdrive | **P0** | Database latency, connection pooling |
| [02-r2-media-storage](./02-r2-media-storage.md) | R2 | **P0** | File storage cost, zero egress |
| [03-kv-edge-caching](./03-kv-edge-caching.md) | Workers KV | **P0** | Read latency, DB load reduction |
| [04-vectorize-semantic-search](./04-vectorize-semantic-search.md) | Vectorize + Workers AI | **P1** | Search quality, recommendations |
| [05-workers-ai-inference](./05-workers-ai-inference.md) | Workers AI | **P1** | AI cost, latency, autonomy agents |
| [06-queues-background-jobs](./06-queues-background-jobs.md) | Queues | **P1** | Job reliability, observability |
| [07-durable-objects-realtime](./07-durable-objects-realtime.md) | Durable Objects | **P1** | Real-time collaboration, state |
| [08-analytics-engine](./08-analytics-engine.md) | Analytics Engine | **P2** | Metrics pipeline, dashboards |
| [09-workflows-orchestration](./09-workflows-orchestration.md) | Workflows | **P2** | Durable multi-step processes |
| [10-d1-edge-database](./10-d1-edge-database.md) | D1 | **P2** | Edge-local reads, per-tenant DB |
| [11-data-platform-lakehouse](./11-data-platform-lakehouse.md) | Data Platform | **P3** | Data lake, cross-cloud analytics |
| [12-migration-roadmap](./12-migration-roadmap.md) | All | -- | Phased rollout plan |
Priority Legend
- **P0** -- Immediate value, low risk, extend existing patterns
- **P1** -- High value, moderate effort, new capabilities
- **P2** -- Strategic value, requires new architecture patterns
- **P3** -- Long-term vision, experimental
Cost Model (Workers Paid Plan -- $5/mo base)
| Product | Included Free | Overage |
|---|---|---|
| Workers | 10M requests, 30M CPU-ms | $0.30/M req, $0.02/M CPU-ms |
| KV | 10M reads, 1M writes, 1 GB | $0.50/M reads, $5/M writes, $0.50/GB |
| R2 | 10 GB, 1M Class A, 10M Class B | $0.015/GB, $4.50/M writes, $0.36/M reads |
| D1 | 25B rows read, 5 GB | $0.001/M rows, $0.75/GB |
| Durable Objects | 1M requests, 400K GB-s, 5 GB SQLite | $0.15/M req, $12.50/M GB-s, $0.20/GB |
| Queues | Included ops | $0.40/M operations |
| Hyperdrive | Included | No extra charge |
| Vectorize | Free tier (generous) | ~$0.01/M queried dimensions |
| Workers AI | 10K Neurons/day | $0.011/1K Neurons |
| Analytics Engine | Not yet billing | TBD |
| Workflows | Included in Workers | Standard Workers pricing |
\1: Hyperdrive is free. R2 egress is free. This makes the migration from AWS S3 and direct Neon connections a pure cost win.
Multi-Tenant Considerations
Every integration must respect the existing tenant isolation model:
// TRPC context -- source of truth for tenant scope
ctx.tenantId // UUID -- REQUIRED in every query
ctx.siteId // UUID -- optional but recommended
ctx.userId // UUID -- for user-scoped operations
For Workers:
- **KV**: Use key prefixes `{tenantId}:{key}` or separate namespaces
- **R2**: Use bucket-per-tenant or key prefixes
- **D1**: Use per-tenant databases (D1 supports 50K DBs/account)
- **Vectorize**: Use namespace-per-tenant (50K namespaces/index)
- **Durable Objects**: Include tenantId in DO name/ID
- **Queues**: Single queue with tenant routing, or queue-per-tenant
- **Analytics Engine**: Use index field for tenant segmentation
Integration Architecture
Cloudflare Edge
┌─────────────────────────┐
│ Workers (compute) │
│ ├─ KV (cache) │
│ ├─ R2 (files) │
│ ├─ D1 (edge SQL) │
│ ├─ DO (state) │
│ ├─ Vectorize (search) │
│ ├─ Workers AI (models) │
│ ├─ Queues (async) │
│ ├─ Analytics Engine │
│ └─ Workflows (durable) │
└──────────┬──────────────┘
│ Hyperdrive
│ (pooled + cached)
┌──────────▼──────────────┐
│ Neon PostgreSQL │
│ (primary database) │
└─────────────────────────┘
Next.js App (apps/app)
├─ TRPC Routers → Workers (via fetch)
├─ Service Registry → getService() unchanged
└─ Prisma → Neon (via Hyperdrive when from Workers)
Risk Assessment
| Risk | Mitigation |
|---|---|
| Vendor lock-in | Use S3-compatible APIs (R2), standard SQL (D1), abstract behind service interfaces |
| Data consistency | Hyperdrive cache TTL tuning, KV eventual consistency awareness |
| Multi-tenant leak | Enforce tenantId in all KV keys, R2 paths, DO IDs, Vectorize namespaces |
| Migration downtime | Feature flags per integration, gradual rollout per tenant |
| Cost spikes | Set budget alerts, start with free tiers, monitor Analytics Engine |
Next Steps
1. Read each design doc for the specific integration you want to implement 2. Follow the \1 for phased rollout 3. Start with P0 items (Hyperdrive, R2, KV) for immediate wins