Migration Roadmap

Overview

Phased rollout plan for integrating Cloudflare Workers data platform into Company Manager. Each phase is independently valuable and builds on the previous.

Prerequisites


Phase 1: Foundation (Weeks 1-4)

\1: Immediate cost savings and performance wins with minimal risk.

1.1 Hyperdrive for Existing Workers (Week 1)

\1: 1-2 days | \1: Low | \1: High

\1: Worker response times drop, Neon connection count stabilizes.

1.2 R2 Media Storage Migration (Weeks 1-3)

\1: 3-5 days | \1: Low | \1: High (cost)

\1: All file uploads/downloads work, S3 egress drops to zero.

1.3 KV Edge Caching (Weeks 2-4)

\1: 3-5 days | \1: Low | \1: Medium

\1: DB read count drops 30-50% for cached patterns, response times improve.

Phase 1 Milestone


Estimated monthly savings:
- S3 egress: -$30-100 (depending on traffic)
- DB connections: more stable, fewer cold starts
- Read latency: 50ms → 5ms for cached data
- Total CF cost: ~$5 (base plan) + ~$5-15 (KV/R2 usage) = ~$20
- Net savings: $20-80/month + significant performance improvement

Phase 2: New Capabilities (Weeks 5-10)

\1: Add capabilities that don't exist today.

2.1 Vectorize + Workers AI Semantic Search (Weeks 5-7)

\1: 1-2 weeks | \1: Medium | \1: High

\1: Search returns semantically relevant results. "Similar articles" works.

2.2 Workers AI for Agent Tasks (Weeks 6-8)

\1: 1 week per use case | \1: Low | \1: Medium

\1: New AI capabilities work. OpenAI costs decrease for migrated tasks.

2.3 Cloudflare Queues (Weeks 8-10)

\1: 2-3 weeks | \1: Medium | \1: High

\1: Email delivery is reliable with retries. Image processing is async. One cron job replaced.

Phase 2 Milestone


New capabilities added:
- Semantic search across articles and products
- Product recommendations ("similar items")
- Content moderation in live chat
- Image alt text auto-generation
- Reliable email delivery with DLQ
- Async image processing pipeline

Phase 3: Infrastructure Evolution (Weeks 11-18)

\1: Replace legacy patterns with modern CF equivalents.

3.1 Durable Objects Extensions (Weeks 11-13)

\1: 1-2 weeks per DO class | \1: Medium | \1: Medium

\1: Real-time features work cross-instance. POS terminals stay in sync.

3.2 Cloudflare Workflows (Weeks 13-16)

\1: 2-4 weeks | \1: Medium | \1: High

\1: Sync jobs are crash-proof. Progress is trackable. Approvals work.

3.3 Analytics Engine (Weeks 14-18)

\1: 2-3 weeks | \1: Low | \1: High

\1: Analytics queries don't hit PostgreSQL. Dashboard loads 10x faster.

Phase 3 Milestone


Infrastructure modernized:
- Cron jobs → Durable Workflows (crash-proof)
- Bull/Redis → CF Queues (managed)
- POS analytics → Analytics Engine (10x faster)
- Real-time → Durable Objects (cross-instance)
- Total CF cost: ~$30-50/month
- Upstash Redis can be downgraded/removed: -$10-30/month

Phase 4: Advanced (Weeks 19+)

\1: Long-term strategic capabilities.

4.1 D1 Per-Tenant Edge Database (Weeks 19-22)

\1: 3-4 weeks | \1: High | \1: High

4.2 Data Platform Lakehouse (Weeks 22+)

\1: 4-6 weeks | \1: Medium | \1: Medium

4.3 Full Queue Migration (Weeks 24+)


Decision Matrix

When to Start Each Phase

PhaseTriggerDependencies
1 (Foundation)**Now**CF account + Workers plan
2 (Capabilities)Phase 1 validatedR2 + KV working
3 (Evolution)Business needPhase 1-2 stable
4 (Advanced)Scale demandPhase 1-3 mature

Risk/Reward Matrix


High Reward ─────────────────────────────┐
│                                         │
│  Hyperdrive ●          Workflows ●      │
│  R2 ●                  Queues ●         │
│  KV ●          Analytics Engine ●       │
│                                         │
│  Vectorize ●   Durable Objects ●        │
│  Workers AI ●                           │
│                                         │
│              D1 ●    Data Platform ●    │
│                                         │
Low Reward ──────────────────────────────┘
Low Risk ──────────────────── High Risk

Environment Variables (New)


# apps/app/.env (additions)

# Cloudflare Account
CF_ACCOUNT_ID=
CF_API_TOKEN=

# R2 (S3-compatible)
R2_ACCESS_KEY_ID=
R2_SECRET_ACCESS_KEY=
R2_BUCKET_NAME=company-manager-media
R2_ENDPOINT=https://${CF_ACCOUNT_ID}.r2.cloudflarestorage.com

# KV
KV_NAMESPACE_ID=
KV_API_TOKEN=

# Hyperdrive
HYPERDRIVE_ID=

# Workers AI (for REST API access from Next.js)
CF_AI_API_TOKEN=

# Search Worker
SEARCH_WORKER_URL=https://search-worker.wd29.workers.dev

# Analytics Engine
AE_DATASET_TOKEN=

Monitoring & Observability

ToolWhat to Monitor
CF Dashboard → WorkersRequest count, error rate, CPU time
CF Dashboard → KVHit rate, operations, storage
CF Dashboard → R2Storage, operations, egress (should be $0)
CF Dashboard → QueuesQueue depth, DLQ messages, consumer lag
CF Dashboard → D1Queries, storage, read/write ops
Neon DashboardConnection count (should decrease with Hyperdrive)
Application logsCache hit/miss ratios, sync status

Rollback Plan

Each integration has an independent rollback path:

IntegrationRollback
HyperdriveRemove binding, Workers use direct connection
R2Switch S3 client back to AWS endpoint
KVBypass cache, all reads go to DB
VectorizeDisable semantic search, use keyword-only
Workers AIRevert to OpenAI API calls
QueuesSwitch back to Bull/Redis
WorkflowsRe-enable cron scripts
D1All reads go to Neon (no edge replica)
Analytics EngineRevert to PostgreSQL analytics queries

No integration requires a hard cutover. All can run in parallel with the existing system during migration.