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.
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 | <1ms | Via API (async) | 512KB | Feature flags, config |
| Vercel KV (Redis) | 5-50ms | 5-50ms | 256MB+ | Sessions, cache |
| Environment Variables | 0ms (in-process) | Requires redeploy | 4KB | Static config, secrets |
Related Products
on GumroadDeveloper Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad →AI Prompt Engineering Toolkit
58 structured prompt templates for Claude, ChatGPT, and Gemini — organized by use case. Code Review, Debugging, Documentation, Architecture, and 10 model-specific tips. Stop writing prompts from scratch.
Buy on Gumroad →Developer Cheat Sheet Bundle
10 print-ready cheat sheets for the tools developers use every day: Git, Docker, Linux CLI, SQL, Regex, HTTP Status codes, VS Code shortcuts, Bash scripting, jq/JSON, and Markdown.
Buy on Gumroad →You Might Also Need
Web Performance Checklist
Interactive web performance checklist covering images, fonts, JavaScript, CSS, caching, and server. Check off items to track your score out of 100 and export as Markdown.
Open free tool →
Lighthouse Score Simulator
Estimate Lighthouse performance scores based on JS bundle size, CSS, images, TTFB, and render-blocking resources. Get LCP, FID, CLS, FCP estimates.
Open free tool →
Web Vitals Budget Planner
Plan Core Web Vitals budgets. Set LCP/CLS/INP targets for e-commerce, blog, SaaS, or custom pages. Get resource size limits, JS execution budget, and third-party script allowances.
Open free tool →
More Free Tools
Related Articles
Cloudflare Workers vs Vercel Edge Functions: 2026 Comparison
Deep comparison of Cloudflare Workers vs Vercel Edge Functions in 2026: runtime differences, limits, pricing, storage options, developer experience, and when to choose each.
Performance Optimization 2026: Complete Guide to Frontend, Backend, and Infrastructure
Comprehensive performance optimization guide for 2026 covering Core Web Vitals, JavaScript bundle optimization, server-side rendering, caching strategies, database query optimization, CDN configuration, and real-world benchmarks.
Web Performance and Core Web Vitals 2026: Complete Optimization Guide
Complete guide to Core Web Vitals optimization in 2026. Covers LCP, INP, CLS, TTFB optimization with real code examples. Includes Next.js, React, Vite, Cloudflare Workers, and backend optimization strategies for achieving 90+ Lighthouse scores.
WebAssembly in Production: Edge Functions & Runtime Performance 2026
How to run WebAssembly in production edge functions in 2026: Cloudflare Workers, Fastly Compute, building with Rust and wasm-pack, performance benchmarks, WASM Component Model, and WASI.
AWS Lambda vs Cloudflare Workers vs Vercel Edge Functions: 2026 Comparison
Deep comparison of AWS Lambda, Cloudflare Workers, and Vercel Edge Functions in 2026. Cold starts, latency, cost, DX, and a decision guide for every use case.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$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.
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.