Cloudflare Services Utilized

9.1 Service Summary

ServicePurposeScale Considerations
WorkersHTTP routing, API, authenticationUnlimited requests, auto-scaling
Durable ObjectsConnection state, price aggregation, health monitoringOne DO per workload + global aggregators
D1Workload metadata, customer data, audit logsMultiple databases for sharding if needed
KVRouting cache, token cache, price cacheGlobal replication, ~60s propagation
QueuesAsync processing (notifications, billing)Automatic batching and retry
R2Artifact storage (logs, workload configs)Unlimited storage, zero egress
WorkflowsLong-running provisioning/terminationDurable execution with retries
SpectrumTCP traffic routingEnterprise feature for non-HTTP
Load BalancingHealth checks, failoverPer-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