12. Edge Config & KV Storage
12.1 Edge Config
A globally replicated key-value store designed for ultra-low latency reads at the edge. Data is replicated to every PoP.
import { get } from '@vercel/edge-config';
// In Middleware (Edge Runtime) — near-zero latency
export async function middleware(request) {
const maintenanceMode = await get('maintenance-mode');
if (maintenanceMode) {
return NextResponse.redirect('/maintenance');
}
}
Use cases:
- Feature flags
- Maintenance mode toggle
- A/B test configuration
- Allowed/blocked IP lists
- Rate limiting configuration
Critical limitation: Write propagation is eventually consistent with seconds of latency. Edge Config is for read-heavy data that changes infrequently. Do not use it for user sessions or real-time data.
12.2 Vercel KV (Redis-compatible)
For general-purpose key-value storage in Serverless Functions:
import { kv } from '@vercel/kv';
// Rate limiting
const requests = await kv.incr(`rate:${userId}`);
await kv.expire(`rate:${userId}`, 60); // reset after 60 seconds
if (requests > 100) return new Response('Too Many Requests', { status: 429 });
12.3 Vercel Blob
Object storage for files — images, videos, documents:
import { put } from '@vercel/blob';
export async function POST(request) {
const form = await request.formData();
const file = form.get('file');
const blob = await put(file.name, file, { access: 'public' });
return Response.json({ url: blob.url });
}
12.4 Vercel Postgres
Managed PostgreSQL (powered by Neon serverless Postgres):
import { sql } from '@vercel/postgres';
const { rows } = await sql`SELECT * FROM users WHERE id = ${userId}`;