Cloudflare Workers Roadmap
Roadmap for expanding Cloudflare Workers across the Arlem stack. Workers run at the edge (~50ms latency vs 500ms+ for Vercel/Azure), cost effectively nothing at our scale, and bypass ad blockers when deployed on first-party subdomains.
Current State
| Worker | Subdomain | Purpose |
|---|---|---|
telegram-proxy | telegram-proxy.arlem.com.au | Proxies Telegram Bot API calls from Azure Functions |
cdn-api | - | CDN image management API |
edge-analytics | edge.arlem.com.au | Edge analytics ingestion + segment cache |
Tier 1: Quick Wins (Done / Ready)
Edge Analytics (Done)
Worker: edge-analytics at edge.arlem.com.au
- Replaces Vercel
/api/pingproxy for analytics event ingestion - Geo enrichment from
request.cf(country, region, city, lat/lon, timezone) - Bot filtering before events reach Azure
- KV segment lookup returns visitor segment code in ~5ms
ctx.waitUntil()forwards enriched events to Azure asynchronously- Client-side fallback to
/api/pingif Worker is unreachable
Impact: Eliminates Vercel function invocation per page view, reduces latency from ~500ms to ~50ms, bypasses most ad blockers.
KV Segment Cache (Done)
- Hourly
scheduledBigQuerySyncwrites segment codes toVISITOR_SEGMENTSKV namespace - 2-hour TTL ensures stale data self-cleans if sync breaks
- Bulk writes via Cloudflare API (up to 10,000 per batch)
D1 Feature Flags + A/B Test Config
Effort: Low | Impact: Medium
Store feature flags and A/B test configurations in D1 (Cloudflare’s SQLite-at-edge database). The edge analytics Worker reads them on every request and returns active experiments alongside the segment code.
- No external service dependency (LaunchDarkly, Statsig, etc.)
- Configuration changes propagate globally in seconds
- A/B test assignment happens at the edge, not in client JS
- Reference: Philip Walton’s A/B testing at the edge pattern
Schema:
CREATE TABLE feature_flags (
key TEXT PRIMARY KEY,
enabled BOOLEAN,
segments TEXT, -- JSON array of segment codes this applies to
percentage REAL -- rollout percentage (0-100)
);
CREATE TABLE experiments (
id TEXT PRIMARY KEY,
variants TEXT, -- JSON array of variant configs
allocation TEXT, -- JSON allocation weights
active BOOLEAN
);Tier 2: Medium Effort, High Value
Edge Personalisation Manifest
Effort: Medium | Impact: High
Return a personalisation manifest from the edge worker alongside the segment code. The manifest tells the client what to show without additional API calls.
{
"segment": 3,
"personalisation": {
"hero_cta": "See what others are saying",
"show_social_proof": true,
"discount_code": null,
"exit_intent": true
}
}- Manifest keyed by segment + experiment variants
- Stored in KV or D1 alongside segment data
- Client reads manifest once on page load, applies all personalisation client-side
- Eliminates multiple round-trips for personalisation decisions
Smart Image Serving (CDN Worker Enhancement)
Effort: Medium | Impact: Medium
Enhance the existing cdn-api Worker to handle smart image transformations:
- WebP/AVIF format negotiation based on
Acceptheader - Responsive image serving based on
CF-Device-Typeheader - Art direction (crop/resize) at the edge using Cloudflare Images
- Cache transformed variants in R2 or Workers Cache API
- Reference: Cloudflare’s R2 image reference architecture
Cloudflare Queues for Event Buffering (Done)
Edge analytics Worker produces to a Cloudflare Queue. A consumer Worker batches events and forwards to Azure in bulk. Service Bus remains for Telegram, financial, and other non-analytics queues.
Tier 3: Ambitious / Future
Durable Objects for Real-Time Visitor State
Effort: High | Impact: High
Use Durable Objects to maintain real-time visitor state at the edge:
- Each active visitor gets a Durable Object (created on first event, garbage collected after inactivity)
- Tracks session state: pages viewed, time on site, cart contents
- Can compute journey stage in real-time instead of hourly BigQuery batch
- Enables real-time triggers: “visitor has been on product page for 60s, show social proof”
- Reference: Similar to how Shopify Oxygen uses Workers for storefront personalisation
Workers AI + Vectorize for Product Search
Effort: High | Impact: Medium
- Embed product descriptions and customer reviews using Workers AI
- Store vectors in Vectorize
- Semantic search at the edge: “something soft for a modern bedroom”
- Could power a conversational product finder
Cloudflare Workflows for Checkout Orchestration
Effort: High | Impact: Medium
Use Workflows (durable execution on Workers) for multi-step checkout flows:
- Cart abandonment sequences triggered at the edge
- Inventory reservation with automatic release
- Payment processing orchestration with retry logic
Workers Analytics Engine for Real-Time Dashboards
Effort: Medium | Impact: Low-Medium
Write analytics events to Workers Analytics Engine (columnar storage at edge) alongside Azure forwarding:
- Real-time query API for dashboards
- No BigQuery cost for operational queries
- 90-day retention, SQL-like query interface
- Good for “what’s happening right now” views
What Stays on Azure
Not everything should move to Workers. These stay on Azure Functions:
| Function | Why |
|---|---|
| Scheduled syncs (BigQuery, Shopify, Meta Ads, Wise) | Long-running, needs Node.js ecosystem, accesses multiple APIs |
| AI summarisation (GPT-4 visitor summaries) | CPU-intensive, needs OpenAI SDK |
| Telegram bot | Bidirectional, needs Cosmos DB, complex state |
| Financial system | Sensitive data, Wise API integration, receipt processing |
| MCP endpoints | Complex tool implementations, multiple API integrations |
Principle: Workers handle the hot path (every page view). Azure handles the warm path (hourly syncs, AI processing, financial ops).
Deployment Notes
KV Namespace Setup
# Create production namespace
wrangler kv namespace create VISITOR_SEGMENTS
# Create preview namespace for local dev
wrangler kv namespace create VISITOR_SEGMENTS --preview
# Update wrangler.toml with returned IDsSecrets
# Edge analytics Worker
cd workers/edge-analytics
wrangler secret put AZURE_FUNCTION_CODE
# Azure Functions (for KV sync)
# Set in Azure Portal > Function App > Configuration:
# CLOUDFLARE_ACCOUNT_ID
# CLOUDFLARE_KV_NAMESPACE_ID
# CLOUDFLARE_API_TOKEN (needs Workers KV write permission)DNS
Add a CNAME record for edge.arlem.com.au pointing to the Worker. Cloudflare handles this automatically when using custom domains in wrangler.toml, but the domain must be on a Cloudflare-managed zone.
Monitoring
- Workers analytics dashboard shows request count, latency percentiles, error rates
- Azure Function logs show forwarded events arriving
- KV metrics show read/write patterns and cache hit rates