Skip to main content

Vercel Edge Config: Setup, SDK & Feature Flags Guide

Vercel Edge Config delivers configuration data to your edge functions in under 1ms — no database round-trip, no origin latency. This guide covers setup, the @vercel/edge-config SDK, feature flag patterns, and when to use Edge Config vs Vercel KV.

✓ Sub-1ms edge reads ✓ Feature flags & killswitches ✓ A/B testing at the edge ✓ Edge Config vs KV vs env vars

Setting Up Edge Config

# 1. Create Edge Config via Vercel CLI
vercel edge-config create my-feature-flags

# 2. Install SDK
npm install @vercel/edge-config

# 3. Add connection string to .env.local
# EDGE_CONFIG=https://edge-config.vercel.com/ecfg_xxxxx?token=xxxxx

# 4. Populate via Vercel API
curl -X PATCH \
  "https://api.vercel.com/v1/edge-config/${EDGE_CONFIG_ID}/items" \
  -H "Authorization: Bearer ${VERCEL_TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{
    "items": [
      { "operation": "upsert", "key": "new-checkout", "value": { "enabled": true, "rollout": 50 } },
      { "operation": "upsert", "key": "dark-mode", "value": { "enabled": false } },
      { "operation": "upsert", "key": "maintenance", "value": false }
    ]
  }'

Reading Edge Config with the SDK

// middleware.ts — feature flag routing at edge
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
import { get, has } from '@vercel/edge-config';

export async function middleware(request: NextRequest) {
  // Check maintenance mode killswitch (~0.5ms)
  const inMaintenance = await get('maintenance');
  if (inMaintenance) {
    return NextResponse.rewrite(new URL('/maintenance', request.url));
  }

  // Feature flag: new checkout flow
  const checkoutFlag = await get<{ enabled: boolean; rollout: number }>('new-checkout');
  if (checkoutFlag?.enabled && request.nextUrl.pathname === '/checkout') {
    const userId = request.cookies.get('userId')?.value ?? '';
    // Simple hash-based rollout
    const hash = userId.split('').reduce((a, c) => a + c.charCodeAt(0), 0);
    if (hash % 100 < (checkoutFlag.rollout ?? 0)) {
      return NextResponse.rewrite(new URL('/checkout-v2', request.url));
    }
  }

  return NextResponse.next();
}

export const config = {
  matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
};

A/B Testing Pattern with Edge Config

// A/B test assignment at the edge
import { get } from '@vercel/edge-config';
import { NextResponse } from 'next/server';

interface ABTest {
  variants: Array<{ id: string; weight: number; path: string }>;
}

export async function middleware(request: NextRequest) {
  const homeTest = await get<ABTest>('homepage-ab-test');

  if (!homeTest || request.nextUrl.pathname !== '/') {
    return NextResponse.next();
  }

  // Check if user already assigned
  const existing = request.cookies.get('ab-homepage');
  if (existing) {
    const variant = homeTest.variants.find(v => v.id === existing.value);
    if (variant) return NextResponse.rewrite(new URL(variant.path, request.url));
  }

  // Assign new variant
  const rand = Math.random();
  let cumWeight = 0;
  for (const variant of homeTest.variants) {
    cumWeight += variant.weight;
    if (rand < cumWeight) {
      const response = NextResponse.rewrite(new URL(variant.path, request.url));
      response.cookies.set('ab-homepage', variant.id, { maxAge: 86400 * 30 });
      return response;
    }
  }

  return NextResponse.next();
}

Storage Options Comparison

Option Read Latency Write Latency Max Size Best For
Edge Config<1msVia API (async)512KBFeature flags, config
Vercel KV (Redis)5-50ms5-50ms256MB+Sessions, cache
Environment Variables0ms (in-process)Requires redeploy4KBStatic config, secrets
Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Related Articles

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →

Frequently Asked Questions

What is Vercel Edge Config?▼

Vercel Edge Config is an ultra-low-latency key-value data store that is read at the edge, without requiring a round-trip to your origin server or database. It is designed for configuration data that must be read on every request — feature flags, killswitches, A/B test assignments, allow/denylists — where even 10ms of latency matters. Reads are served from memory at the nearest Vercel edge PoP.

How fast is Vercel Edge Config compared to a database?▼

Vercel Edge Config reads typically complete in under 1ms because the data is pre-loaded into memory at every edge PoP globally. In contrast, a database query — even a fast one — requires a network round-trip: 20-100ms for a regional database, and 100-500ms if the database is in a different region than the edge function. Edge Config eliminates this latency for configuration reads.

What are the size limits for Edge Config?▼

Each Edge Config store can hold up to 512KB of total data on the Hobby plan and 512KB on Pro (extendable). Individual item values are limited to 64KB. The store is read-only at runtime — you write to it via the Vercel API or dashboard, and reads are served from the edge. It is not suitable for frequently changing data or user-generated content.

What is the difference between Edge Config, Vercel KV, and environment variables?▼

Environment variables are baked into your deployment and require a redeploy to change. Vercel KV (Redis) is a persistent key-value store with read latency of 5-50ms — good for session data and caching. Edge Config is the fastest option (sub-1ms reads) but is limited to small configuration data. Use Edge Config for feature flags and killswitches, KV for session/cache data, and environment variables for static configuration.

Can I use Edge Config outside of Vercel?▼

Edge Config is a Vercel-specific service and requires the @vercel/edge-config SDK. It works in Vercel Edge Functions, Vercel Serverless Functions, and Vercel Edge Middleware. It does not work outside Vercel deployments. If you need similar functionality across platforms, consider Cloudflare Workers KV (for CF deployments) or a managed Redis service with geographic distribution.

How do I set up feature flags with Edge Config?▼

Store feature flag data as a JSON object in Edge Config with flag names as keys and objects containing enabled boolean and optional rollout percentage as values. Read flags in Edge Middleware to make routing decisions before the request reaches your application. This pattern allows you to enable or disable features globally within seconds, without redeployment, and with zero added latency.