Skip to main content

How Edge Computing Is Changing API Architecture

·APIScout Team
edge computingcloudflare workersapi architectureperformancelatency

How Edge Computing Is Changing API Architecture

Edge computing moves your API logic closer to users — from a single data center to 300+ locations worldwide. The result: sub-50ms response times everywhere. But it changes how you think about data, state, and architecture.

What Edge Computing Means for APIs

Traditional API Architecture

User (Tokyo) → CDN (static) → Origin server (US-East) → Database (US-East)
Latency: ~200ms

Edge API Architecture

User (Tokyo) → Edge function (Tokyo) → Edge database (Tokyo) → Response
Latency: ~20ms

The API logic runs at the edge location closest to the user. No round-trip to a central data center.

The Edge Platform Landscape

PlatformRuntimeLocationsCold Start
Cloudflare WorkersV8 Isolates300+<5ms
Vercel Edge FunctionsV8 Isolates30+<25ms
Deno DeployDeno/V835+<10ms
Fastly ComputeWasm90+<5ms
AWS Lambda@EdgeNode.js30+~100ms
Netlify Edge FunctionsDeno30+<25ms

Why V8 Isolates Win

Traditional serverless (Lambda) uses containers. Each container takes 100-500ms to cold start. V8 isolates share the same process, creating new execution contexts in <5ms.

Container (Lambda):    Pull image → Start runtime → Load code → Execute
                       [~200ms cold start]

V8 Isolate (Workers):  Create isolate → Execute
                       [~5ms cold start]

Edge API Patterns

1. API Gateway at the Edge

Route, authenticate, and rate-limit at the edge before hitting your origin:

// Cloudflare Worker as API gateway
export default {
  async fetch(request: Request) {
    const url = new URL(request.url);

    // Auth check at edge (fast)
    const apiKey = request.headers.get('Authorization')?.replace('Bearer ', '');
    if (!apiKey || !await validateKey(apiKey)) {
      return new Response('Unauthorized', { status: 401 });
    }

    // Rate limit at edge
    const { success } = await env.RATE_LIMITER.limit({ key: apiKey });
    if (!success) {
      return new Response('Rate limited', { status: 429 });
    }

    // Route to appropriate origin
    if (url.pathname.startsWith('/api/v1')) {
      return fetch(`https://api-origin.example.com${url.pathname}`, request);
    }

    return new Response('Not found', { status: 404 });
  },
};

Benefits: Authentication and rate limiting happen in <5ms at the edge, before the request ever reaches your origin server.

2. Full API at the Edge

For simple APIs, run the entire stack at the edge:

// Full CRUD API on Cloudflare Workers + D1
export default {
  async fetch(request: Request, env: Env) {
    const url = new URL(request.url);

    if (url.pathname === '/api/products' && request.method === 'GET') {
      const { results } = await env.DB.prepare(
        'SELECT * FROM products WHERE active = 1 ORDER BY created_at DESC LIMIT 50'
      ).all();
      return Response.json(results);
    }

    if (url.pathname === '/api/products' && request.method === 'POST') {
      const body = await request.json();
      const result = await env.DB.prepare(
        'INSERT INTO products (name, price, description) VALUES (?, ?, ?)'
      ).bind(body.name, body.price, body.description).run();
      return Response.json({ id: result.meta.last_row_id }, { status: 201 });
    }

    return new Response('Not found', { status: 404 });
  },
};

3. Edge Caching Layer

Cache API responses at the edge with intelligent invalidation:

export default {
  async fetch(request: Request, env: Env, ctx: ExecutionContext) {
    const cacheKey = new Request(request.url, request);
    const cache = caches.default;

    // Check edge cache
    let response = await cache.match(cacheKey);
    if (response) {
      return response; // Cache hit — ~1ms
    }

    // Cache miss — fetch from origin
    response = await fetch(request);
    response = new Response(response.body, response);
    response.headers.set('Cache-Control', 'public, max-age=60');

    // Store in edge cache (async, doesn't block response)
    ctx.waitUntil(cache.put(cacheKey, response.clone()));

    return response;
  },
};

4. Edge Data Patterns

PatternHowBest For
KV StoreCloudflare KV, Vercel KVConfig, feature flags, cached data
Edge DatabaseD1, Turso, NeonFull SQL at the edge
Durable ObjectsCloudflare Durable ObjectsStateful edge logic, coordination
Edge CacheCache APIHTTP response caching
Read replicaOrigin DB → edge replicasRead-heavy, write-rare

5. Geo-Routed APIs

Return different results based on user location:

export default {
  async fetch(request: Request) {
    const country = request.headers.get('cf-ipcountry') || 'US';
    const city = request.cf?.city || 'Unknown';

    // Pricing by region
    const pricing = getPricingForRegion(country);

    // Content by region
    const content = await getLocalizedContent(country);

    // Compliance by region
    const features = getAvailableFeatures(country);

    return Response.json({
      pricing,
      content,
      features,
      meta: { country, city, edge_location: request.cf?.colo },
    });
  },
};

When to Use Edge vs Origin

Use CaseEdgeOriginWhy
Auth/rate limitingBlock bad traffic before it reaches origin
Static API responsesCacheable, no origin needed
Read-heavy dataEdge replicas serve reads fast
Full-text searchSearch indexes don't distribute well
Complex transactionsNeeds single database for consistency
AI inference⚠️GPU availability (Cloudflare Workers AI is an exception)
Write-heavyWrites need to go to primary database
Real-time WebSocketsDurable Objects handle WebSocket state
Geolocation routingDecision made before hitting origin
A/B testingFeature flags at the edge

Performance Impact

Real-World Latency

ArchitectureP50 LatencyP99 Latency
US-East origin (global users)150ms400ms
Multi-region origins (3 regions)80ms200ms
Edge functions + origin50ms150ms
Full edge (no origin)15ms50ms

The Edge Tax

Edge has constraints:

ConstraintOriginEdge
CPU time per requestMinutes10-50ms
MemoryGBs128MB
Request body sizeGBs100MB
Database optionsAnyLimited (KV, D1, Turso)
Node.js APIsFullPartial (no fs, net, etc.)
NPM packagesAllWeb-compatible only
Cold start100-500ms<5ms

Common Mistakes

MistakeImpactFix
Moving everything to the edgeSome workloads need originUse edge for what benefits from it
Ignoring cold starts on Lambda@Edge200ms+ on first requestUse V8 isolate platforms instead
Treating edge KV as a databaseKV is eventually consistentUse D1/Turso for strong consistency
Not measuring latency by regionFast in US, slow in AsiaTest from multiple regions
Ignoring edge compute limitsWorker killed at 50ms CPUOffload heavy work to origin

Compare edge platforms and their APIs on APIScout — Cloudflare Workers vs Vercel Edge vs Deno Deploy, with benchmarks, pricing, and DX ratings.

Comments