Back to Blog
Guide7 min read2025-01-01

Edge Functions Explained: What They Are and Why Your App Needs Them

Edge functions run your code at network locations closest to your users, delivering sub-millisecond cold starts and global performance. Here's everything you need to know.

What Are Edge Functions?

Traditional serverless functions run in a single cloud region. When a user in Tokyo requests your Node.js API hosted in us-east-1, that request travels across the Pacific Ocean — adding 150-200ms of latency before your code even starts executing.

Edge functions solve this problem by running your code at Points of Presence (PoPs) distributed globally — often within milliseconds of your end users. The "edge" refers to the edge of the network, closest to users.

How Edge Functions Differ from Traditional Serverless

AspectTraditional LambdaEdge Functions
RuntimeNode.js, Python, Go, etc.V8 isolates (JavaScript/TypeScript)
Cold start100ms - 3sSub-millisecond
Execution locationSingle region50+ global PoPs
Memory limitUp to 10GB128MB (typical)
Execution timeUp to 15 minutesMilliseconds to seconds
Use caseComplex computationsRequest/response, A/B testing, auth

Key Use Cases for Edge Functions

1. A/B Testing and Feature Flags

Instead of loading feature flag libraries in the browser (slow, flickering), run your A/B logic at the edge:

export default function handler(request) {
  const variant = Math.random() > 0.5 ? 'a' : 'b';
  const response = fetch(request);
  response.headers.set('X-Variant', variant);
  return response;
}

2. Authentication and Authorization

Validate JWTs and redirect unauthorized users before the request reaches your origin:

export default async function handler(request) {
  const token = request.headers.get('Authorization');
  const valid = await validateJWT(token);
  
  if (!valid) {
    return new Response('Unauthorized', { status: 401 });
  }
  
  return fetch(request);
}

3. Geolocation-Based Routing

Redirect users to region-specific content or APIs:

export default function handler(request) {
  const country = request.headers.get('CF-IPCountry') || 'US';
  const apiUrl = country === 'EU' 
    ? 'https://eu-api.example.com' 
    : 'https://api.example.com';
  
  return fetch(apiUrl + request.url.pathname);
}

4. Image and Content Transformation

Resize images, add watermarks, or convert formats on the fly based on device type.

5. Rate Limiting and DDoS Protection

Implement per-IP rate limiting at the edge before requests hit your servers.

PandaStack Edge: Pricing and Features

PandaStack Edge is built on V8 isolates with global distribution across 45+ PoPs.

Pricing:

  • Free tier: 100,000 invocations/month
  • Beyond free tier: $0.000002 per invocation (that's $2 per million)
  • Compute: Included (no separate charges for CPU time)

For comparison:

  • AWS Lambda@Edge: $0.0000006/request + $0.00005001/GB-second compute
  • Cloudflare Workers: Free up to 100K/day, then $5/month for 10M requests
  • Vercel Edge Functions: Included in plan but limited

PandaStack Edge pricing at scale:

  • 1 million invocations/month: $2
  • 10 million invocations/month: $20
  • 100 million invocations/month: $200

Compare that to AWS Lambda@Edge at 100 million requests: ~$60 in request fees alone, plus compute charges.

AWS Lambda vs Cloudflare Workers vs PandaStack Edge

ProviderCold StartPrice/MillionPoPsMax Runtime
AWS Lambda@Edge100ms+~$0.60220+30s
Cloudflare Workers<1ms$0.50 (after 10M free)270+30s
Vercel Edge<1msIncluded30+25s
PandaStack Edge<1ms$245+60s

PandaStack Edge stands out for its generous free tier, simple per-invocation pricing with no separate compute charges, and longer maximum runtime (60s).

Getting Started with PandaStack Edge

// src/edge/my-function.js
export default async function handler(request, context) {
  const url = new URL(request.url);
  
  // Access request data
  const country = context.geo?.country || 'US';
  const ip = context.ip;
  
  // Return a response
  return new Response(JSON.stringify({ 
    message: 'Hello from the edge!',
    country,
    timestamp: Date.now()
  }), {
    headers: { 'Content-Type': 'application/json' }
  });
}

Deploy with:

pandastack edge deploy src/edge/my-function.js --name my-function

When NOT to Use Edge Functions

Edge functions are powerful but have constraints:

  • No persistent connections — can't hold WebSocket connections
  • Limited memory — 128MB means no heavy ML models
  • No file system access — code must be stateless
  • V8 isolate only — can't use native Node.js modules

For heavy computation, long-running tasks, or full Node.js APIs, use traditional serverless or containers.

Conclusion

Edge functions are no longer a niche technology — they're essential for modern web applications that need global performance. PandaStack Edge makes it easy to get started with a generous free tier and the simplest pricing model in the industry.

[Try PandaStack Edge for free →](https://dashboard.pandastack.io/edge)

Ready to deploy?

Start free on PandaStack — no credit card required.

Start free on PandaStack

More in Guide

Browse all Guide articles →

See also