Cloudflare Services Utilized
9.1 Service Summary
| Service | Purpose | Scale Considerations |
|---|---|---|
| Workers | HTTP routing, API, authentication | Unlimited requests, auto-scaling |
| Durable Objects | Connection state, price aggregation, health monitoring | One DO per workload + global aggregators |
| D1 | Workload metadata, customer data, audit logs | Multiple databases for sharding if needed |
| KV | Routing cache, token cache, price cache | Global replication, ~60s propagation |
| Queues | Async processing (notifications, billing) | Automatic batching and retry |
| R2 | Artifact storage (logs, workload configs) | Unlimited storage, zero egress |
| Workflows | Long-running provisioning/termination | Durable execution with retries |
| Spectrum | TCP traffic routing | Enterprise feature for non-HTTP |
| Load Balancing | Health checks, failover | Per-workload health monitoring |
9.2 Wrangler Configuration
# wrangler.toml
name = "compute-arbitrage"
main = "src/index.ts"
compatibility_date = "2024-01-01"
compatibility_flags = ["nodejs_compat"]
# Workers configuration
[env.production]
name = "compute-arbitrage-prod"
routes = [
{ pattern = "api.computearbitrage.com/*", zone_name = "computearbitrage.com" },
{ pattern = "*.workloads.computearbitrage.com/*", zone_name = "computearbitrage.com" },
]
# D1 Databases
[[d1_databases]]
binding = "DB"
database_name = "compute-arbitrage-main"
database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
[[d1_databases]]
binding = "AUDIT_DB"
database_name = "compute-arbitrage-audit"
database_id = "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy"
# KV Namespaces
[[kv_namespaces]]
binding = "ROUTING_KV"
id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
[[kv_namespaces]]
binding = "AUTH_KV"
id = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
[[kv_namespaces]]
binding = "PRICES_KV"
id = "cccccccccccccccccccccccccccccccc"
# R2 Buckets
[[r2_buckets]]
binding = "ARTIFACTS"
bucket_name = "compute-arbitrage-artifacts"
[[r2_buckets]]
binding = "LOGS"
bucket_name = "compute-arbitrage-logs"
# Queues
[[queues.producers]]
queue = "notifications"
binding = "NOTIFICATION_QUEUE"
[[queues.producers]]
queue = "billing"
binding = "BILLING_QUEUE"
[[queues.producers]]
queue = "events"
binding = "EVENTS_QUEUE"
[[queues.consumers]]
queue = "notifications"
max_batch_size = 100
max_batch_timeout = 30
[[queues.consumers]]
queue = "billing"
max_batch_size = 100
max_batch_timeout = 60
# Durable Objects
[[durable_objects.bindings]]
name = "ARBITRAGE_ENGINE"
class_name = "PriceCollector"
[[durable_objects.bindings]]
name = "HEALTH_MONITOR"
class_name = "HealthMonitor"
[[durable_objects.bindings]]
name = "CONNECTION_MANAGER"
class_name = "ConnectionManager"
[[migrations]]
tag = "v1"
new_sqlite_classes = ["PriceCollector", "HealthMonitor", "ConnectionManager"]
# Workflows
[[workflows]]
name = "provision-workload"
binding = "PROVISION_WORKFLOW"
class_name = "ProvisionWorkflow"
[[workflows]]
name = "terminate-workload"
binding = "TERMINATE_WORKFLOW"
class_name = "TerminateWorkflow"
# Cron triggers for price collection
[triggers]
crons = ["*/1 * * * *"] # Every minute
# Secrets (configured via wrangler secret put)
# - JWT_PRIVATE_KEY
# - JWT_PUBLIC_KEY
# - KIVERA_USERNAME
# - KIVERA_PASSWORD
# - CREDENTIALS_ENCRYPTION_KEY