Skip to main content
← All Articles Β· Β· 11 min read

Edge Computing Architecture: Deploy Closer to Users 2026

Edge computing architecture 2026: edge vs CDN vs serverless, Cloudflare vs Vercel vs Fastly, data consistency patterns, and edge-native design guide.

edge-computingcloudflarevercelfastlyarchitectureserverless

Edge Computing Architecture: Deploy Closer to Users 2026

The network round-trip is the latency floor. A user in Tokyo making a request to a server in us-east-1 has a minimum of ~180ms just for the network transit β€” before your code runs a single line. Edge computing eliminates this constraint by running code within milliseconds of the user. This guide covers edge architecture patterns, platform comparison, and how to handle the hard parts.

What Is Edge Computing?

Edge computing runs application code at distributed points of presence (PoPs) worldwide, rather than in a centralized cloud region. These PoPs are typically co-located with CDN infrastructure.

The key distinction from traditional CDN:

CDNEdge ComputeRegional Serverless
What runsStatic files + caching rulesProgrammable codeProgrammable code
Latency to user~5-30ms~5-50ms~50-200ms+
StateConfiguration onlyLimited (via edge KV)Full database access
Locations100-500 PoPs35-300 PoPs1 region (chosen at deploy)
Cold startsNone~0-5ms~100-2000ms

Edge compute sits between CDN and regional serverless in the architecture stack β€” providing programmability with near-CDN latency.


Edge Use Cases

1. Authentication and Authorization

Validating JWTs or session tokens at the edge means unauthorized requests never reach your origin. For APIs that receive significant bot or invalid traffic, this can meaningfully reduce origin load.

// Edge auth: validate JWT before hitting origin
// Runs at every CF PoP β€” adds ~5ms, blocks 40% of traffic at edge

import { jwtVerify } from 'jose'; // WASM-compatible JWT library

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const token = request.headers.get('Authorization')?.replace('Bearer ', '');

    if (!token) {
      return new Response(JSON.stringify({ error: 'Missing token' }), {
        status: 401,
        headers: { 'Content-Type': 'application/json' }
      });
    }

    try {
      const secret = new TextEncoder().encode(env.JWT_SECRET);
      const { payload } = await jwtVerify(token, secret);

      // Inject user info into request headers for origin
      const headers = new Headers(request.headers);
      headers.set('x-user-id', String(payload.sub));
      headers.set('x-user-role', String(payload.role));

      return fetch(new Request(request.url, { ...request, headers }));
    } catch {
      return new Response(JSON.stringify({ error: 'Invalid token' }), {
        status: 401,
        headers: { 'Content-Type': 'application/json' }
      });
    }
  }
};

2. Geo-Based Personalization and Routing

Route users to region-specific content, comply with data residency requirements, or serve localized content β€” all without a database query.

// Route EU users to GDPR-compliant infrastructure
export function middleware(request: NextRequest) {
  const country = request.geo?.country ?? '';
  const euCountries = new Set(['DE', 'FR', 'NL', 'ES', 'IT', 'SE', 'PL', 'BE']);

  if (euCountries.has(country) && !request.nextUrl.hostname.startsWith('eu.')) {
    const euUrl = new URL(request.url);
    euUrl.hostname = 'eu.example.com';
    return NextResponse.redirect(euUrl, { status: 302 });
  }

  return NextResponse.next();
}

3. Real-Time Personalization

With edge KV stores (Cloudflare KV, Vercel Edge Config), you can serve personalized content without origin round-trips:

// A/B test variant assignment β€” sub-1ms configuration read
import { get } from '@vercel/edge-config';

export async function middleware(request: NextRequest) {
  const test = await get<{ variants: string[]; active: boolean }>('homepage-test');

  if (!test?.active) return NextResponse.next();

  // Assign variant based on cookie or user ID
  const existingVariant = request.cookies.get('ab-variant')?.value;
  const variant = existingVariant ?? test.variants[Math.floor(Math.random() * test.variants.length)];

  const response = NextResponse.rewrite(new URL(`/${variant}`, request.url));
  response.cookies.set('ab-variant', variant, { maxAge: 60 * 60 * 24 * 30 });
  return response;
}

4. Rate Limiting

Edge-based rate limiting prevents abuse before traffic reaches expensive origin infrastructure.

// Cloudflare Worker rate limiting with KV
export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const ip = request.headers.get('CF-Connecting-IP') ?? 'unknown';
    const key = `ratelimit:${ip}`;
    const limit = 100; // requests per minute

    const current = await env.KV.get(key);
    const count = current ? parseInt(current) : 0;

    if (count >= limit) {
      return new Response('Rate limit exceeded', {
        status: 429,
        headers: {
          'Retry-After': '60',
          'X-RateLimit-Limit': String(limit),
          'X-RateLimit-Remaining': '0'
        }
      });
    }

    // Increment counter (60-second TTL)
    await env.KV.put(key, String(count + 1), { expirationTtl: 60 });

    return fetch(request); // Forward to origin
  }
};

Platform Comparison: Cloudflare vs Vercel vs Fastly vs Deno Deploy

FeatureCloudflare WorkersVercel EdgeFastly ComputeDeno Deploy
PoPs300+~300100+35+
P50 Latency5-30ms5-35ms10-50ms10-60ms
Cold Start<5ms<5ms<1ms (WASM)<5ms
RuntimeV8 IsolatesV8 IsolatesWASMV8 (Deno)
CPU Limit10-50ms~50ms50msNo hard limit
LanguagesJS/TS/WASMJS/TSRust/Go/JS/CJS/TS
StorageKV/R2/D1/DO/QueuesEdge Config/KVKVKV
Pricing (paid)$5/mo + $0.30/MPlatform-bundled$50/mo + $0.30/M$10/mo + $0.30/M
Best forStandalone edge APIsNext.js appsRust/WASM workloadsDeno/TypeScript

Fastly Compute deserves special mention for WASM workloads β€” it is the only platform with first-class WASM support, sub-1ms cold starts via WASM isolation, and full WASI 0.2 compatibility. For Rust developers, Fastly’s fastly-rust SDK provides native integration.


Data Consistency at the Edge

The hardest problem in edge computing is data. Edge PoPs are globally distributed, but your database is typically in one region. This creates fundamental consistency challenges.

Pattern 1: Read-Through Edge Caching

// Cache database results at edge KV with TTL
export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const url = new URL(request.url);
    const productId = url.pathname.split('/').pop();
    const cacheKey = `product:${productId}`;

    // Try edge cache first
    const cached = await env.KV.get(cacheKey, { type: 'json' });
    if (cached) {
      return Response.json(cached, {
        headers: { 'X-Cache': 'HIT', 'Cache-Control': 'public, max-age=60' }
      });
    }

    // Fall through to origin
    const originResponse = await fetch(`https://api.example.com/products/${productId}`);
    const product = await originResponse.json();

    // Cache for 60 seconds
    await env.KV.put(cacheKey, JSON.stringify(product), { expirationTtl: 60 });

    return Response.json(product, {
      headers: { 'X-Cache': 'MISS', 'Cache-Control': 'public, max-age=60' }
    });
  }
};

Pattern 2: Edge for Reads, Origin for Writes

The most pragmatic pattern: serve reads from edge (fast, cached, globally distributed), route all writes to the regional origin (consistent, durable).

Read (GET):
  User ──▢ Edge PoP ──▢ KV Cache ──▢ Response (fast)
                           β”‚
                           └── (miss) ──▢ Origin DB ──▢ Populate KV

Write (POST/PUT/DELETE):
  User ──▢ Edge PoP ──▢ Forward to Origin ──▢ DB
                                β”‚
                                └── Invalidate KV cache

Pattern 3: Edge-Compatible Databases

Use databases designed for edge environments β€” HTTP-driver or globally distributed:

DatabaseProtocolDistributionBest For
PlanetScaleHTTP (edge driver)Global replicasMySQL workloads
Neon PostgresHTTP (serverless driver)Single regionPostgreSQL
TursoHTTP (libSQL)Multi-region replicasSQLite at edge
Cloudflare D1Native Workers bindingCloudflare PoPsSQLite queries
Upstash RedisHTTPMulti-regionCaching, sessions

Edge-Native Patterns

Stale-While-Revalidate (SWR)

Serve stale content immediately while refreshing in the background. Users always get a fast response; data freshness improves asynchronously:

export default {
  async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
    const key = new URL(request.url).pathname;
    const cached = await env.KV.getWithMetadata<{ cachedAt: number }>(key);

    const now = Date.now();
    const staleAfter = 30_000; // 30 seconds
    const expireAfter = 300_000; // 5 minutes

    if (cached.value && cached.metadata) {
      const age = now - cached.metadata.cachedAt;

      if (age < staleAfter) {
        // Fresh β€” serve directly
        return new Response(cached.value, { headers: { 'X-Cache': 'FRESH' } });
      }

      if (age < expireAfter) {
        // Stale β€” serve stale, revalidate in background
        ctx.waitUntil(revalidate(key, env)); // Non-blocking background refresh
        return new Response(cached.value, { headers: { 'X-Cache': 'STALE' } });
      }
    }

    // Expired or miss β€” fetch synchronously
    return revalidate(key, env);
  }
};

When NOT to Use Edge

Edge functions are not a universal solution. Avoid them when:

  1. Database-heavy logic: Every DB query adds a regional round-trip. Edge β†’ DB latency can be 100-300ms depending on proximity, negating edge benefits.

  2. CPU-intensive beyond 50ms: Edge CPU limits are strict. Heavy computation belongs in regional Lambda or containers.

  3. Node.js-specific dependencies: Many npm packages use Node.js built-ins unavailable in edge runtimes. Audit your dependencies before committing to edge.

  4. Stateful coordination: Maintaining state across concurrent edge requests requires Durable Objects (Cloudflare-specific) or external state stores with network overhead.

The best edge architectures offload only what benefits from geographic distribution β€” authentication, routing, lightweight personalization, caching β€” and let complex logic run in well-equipped regional infrastructure.

Free Download

50 CLI Commands That Save Hours Every Week

The exact Git shortcuts, file search tricks, Docker commands, and productivity hacks that senior developers use daily. Compiled from 5+ years of shipping production code.

  • Git mastery (10 cmds)
  • File & search wizardry
  • Docker & DevOps tricks
  • Process & network tools
  • Productivity boosters
  • macOS & Linux install guide

No spam. 1 email/week max. Unsubscribe anytime.

Found this guide useful? Check out our free developer tools.