Documentation

Cloudflare Edge Infrastructure

XTND Vantage • Distributed Edge Computing, Workers & Storage Bindings


1. Edge Architecture Overview

XTND Vantage leverages Cloudflare's global anycast network to achieve sub-10ms telemetry ingestion and zero-latency AI proxying. The infrastructure consists of:

  • 3 Dedicated Cloudflare Workers: Edge APIs for ingestion, AI proxying, and web analytics.
  • 2 static-asset Workers: the Argus dashboard (argus.xgi.io) and the Vantage portal & documentation (vantage.xgi.io).
  • Cloudflare KV: Ephemeral storage for P0 urgent alerts and incident records.
  • Cloudflare Analytics Engine: Columnar time-series store for high-throughput batch metrics.
flowchart LR
    subgraph EdgeWorkers["Cloudflare Edge Workers"]
        W1["xtnd-vantage-api\n(api.vantage.xgi.io)"]
        W2["xtnd-sonar-api\n(api.sonar.vantage.xgi.io)"]
        W3["xtnd-radar-api\n(api.radar.vantage.xgi.io)"]
    end

    subgraph StorageLayer["Cloudflare Storage Bindings"]
        KV["VANTAGE_KV\n(Fast KV with TTL)"]
        AE["VANTAGE_ANALYTICS\n(Analytics Engine)"]
    end

    subgraph PagesHosting["Static-asset Workers"]
        P1["xtnd-argus-web\n(argus.xgi.io)"]
        P2["xtnd-vantage-web\n(vantage.xgi.io)\nportal & docs"]
    end

    W2 -- "ctx.waitUntil(fetch)" --> W1
    W3 -- "ctx.waitUntil(fetch)" --> W1
    W1 --> KV
    W1 --> AE
    P1 -.-> W1
    P2 -. system access .-> P1

2. Worker Specifications & Wrangler Configurations

All Workers use the standard wrangler.jsonc specification with nodejs_compat enabled:

2.1 Central Vantage API (xtnd-vantage-api)

  • Account ID: b4a9d6d55078009ff75dfac01f83fe80
  • Compatibility Date: 2025-04-01
  • Compatibility Flags: ["nodejs_compat"]
  • Routes: api.vantage.xgi.io (Custom Domain)
  • Environment Variables:
    • ENVIRONMENT = "production"
  • Bindings:
    • VANTAGE_KV: Cloudflare KV namespace binding.
    • VANTAGE_ANALYTICS: Cloudflare Analytics Engine dataset binding.
  • Observability: Enabled ("observability": { "enabled": true })

2.2 Sonar AI Gateway (xtnd-sonar-api)

  • Routes: api.sonar.vantage.xgi.io (Custom Domain)
  • Environment Variables:
    • ENVIRONMENT = "production"
    • CENTRAL_VANTAGE_API = "https://api.vantage.xgi.io"
  • Bindings:
    • SONAR_KV (Optional local quota cache)

2.3 Radar Web Gateway (xtnd-radar-api)

  • Routes: api.radar.vantage.xgi.io (Custom Domain)
  • Environment Variables:
    • ENVIRONMENT = "production"
    • CENTRAL_VANTAGE_API = "https://api.vantage.xgi.io"
  • Bindings:
    • RADAR_KV (Optional local session cache)

3. Asynchronous Non-Blocking Execution via ctx.waitUntil()

A critical pattern across all Vantage Workers is the use of ctx.waitUntil().

When an edge worker intercepts an AI request (Sonar) or a web visitor request (Radar):

  1. The origin fetch completes, and the HTTP response is returned to the user immediately.
  2. The telemetry calculation and upstream dispatch to api.vantage.xgi.io are wrapped in ctx.waitUntil().
  3. The Cloudflare Worker isolate keeps running in the background until the upstream promise resolves, ensuring 0ms added latency to the client's perceived response time.
// Pattern in xtnd-sonar-api & xtnd-radar-api:
ctx.waitUntil(
  (async () => {
    try {
      const centralEndpoint = env.CENTRAL_VANTAGE_API.replace(/\/$/, '');
      await fetch(`${centralEndpoint}/v1/events/batch`, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json', 'X-Module-Source': 'sonar' },
        body: JSON.stringify({ events: [telemetryEvent] }),
      });
    } catch (err) {
      console.warn('[Telemetry Forwarding Error]', err);
    }
  })()
);

4. Cloudflare Storage Layer Details

Cloudflare KV (VANTAGE_KV)

Used exclusively for P0_CRITICAL urgent events that require immediate inspection, alert propagation, and deduplication:

  • Key Schema: event:urgent:${eventId}
  • TTL: 604,800 seconds (7 days expiration)
  • Use Cases: Quota exhaustion kill-switch triggers, circuit breaker trips, outage declarations.

Cloudflare Analytics Engine (VANTAGE_ANALYTICS)

Used for high-volume, low-cost time-series telemetry data:

  • writeDataPoint() Structure:
    • blobs: [event.type, event.source || 'gateway', event.priority]
    • doubles: [1] (Counter / volume metric)
    • indexes: [event.type] (Enables sub-second indexing by event type)
  • Benefits: Near-infinite write scalability, zero indexing latency, SQL-queryable via Cloudflare API.

5. Global CORS Configuration

All Vantage endpoints expose uniform, security-hardened CORS headers supporting cross-origin clients and AI frameworks:

export function getCorsHeaders(): Record<string, string> {
  return {
    'Access-Control-Allow-Origin': '*',
    'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
    'Access-Control-Allow-Headers':
      'Content-Type, Authorization, X-Vantage-Client, X-Module-Source, anthropic-version, x-api-key',
  };
}

Preflight OPTIONS requests are answered at edge with HTTP 204 No Content.