Skip to content
Tutorials Center
My learning

Topics

Lesson 25 of 37 ยท Storage and Data

Edge Config and Key-Value Stores

Use Vercel Edge Config for tiny read-heavy settings, Redis key-value stores for counters and caches, and Netlify Blobs as a key-value layer. Includes TTL, rate limiting and feature-flag stand-ins.

Some data is small and read constantly: feature flags, a maintenance-mode switch, a redirect table, a rate-limit counter. A full database is overkill, and a file in the repository means a redeploy for every change. A key-value store (KV) answers "give me the value for this key" in a millisecond or two, and fits these jobs well.

The products cannot run on this site. APIs are sketched from documentation and can change, so check the current docs. The runnable code is made of JavaScript stand-ins that model the ideas.

Two different tools

Vercel Edge Config is a global, read-optimized store of JSON values. Reads happen at the edge, usually in well under a millisecond, but writes are slow to propagate and capped in size, so it is for settings that change rarely:

JavaScript
import { get } from "@vercel/edge-config";

const maintenance = await get("maintenanceMode");   // read-only sketch

You update values from the dashboard, the API or a CLI, and no redeploy is needed. It is a natural fit for middleware that checks a flag on every request.

Redis-compatible KV (on Vercel through Marketplace integrations such as Upstash; on other platforms through any hosted Redis) supports frequent reads and writes: counters, sessions, caches with expiry, queues and leaderboards.

JavaScript
import { Redis } from "@upstash/redis";
const redis = Redis.fromEnv();                       // read-only sketch
await redis.incr("page:home:views");
await redis.set("session:abc", user, { ex: 3600 });  // expires in an hour

Vercel's older built-in "KV" product was moved to these Marketplace providers, so new projects add one from the dashboard's Storage or Marketplace area. On Netlify, Netlify Blobs works as a key-value store from functions, and external Redis services work from any function.

Need Reach for
Rarely changing flags and config read at the edge Edge Config
Counters, sessions, caching with TTL Redis KV
Larger values, files Blob storage
Relational data a database

Time to live

A TTL removes a key automatically after N seconds. It is the core of caching with KV: store an expensive result, set a TTL, and recompute when the key is gone. The stand-in below shows the pattern with a fake clock so the output is stable.

JS KV with TTL stand-in

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Rate limiting with a counter

Serverless functions have no memory shared between instances, so a request counter must live in KV. The usual recipe is a fixed window: key = rate:{user}:{minute}, increment, give the key a TTL slightly longer than the window, and refuse requests over the limit. (Sliding window and token bucket variants are smoother but need more logic; libraries such as Upstash's ratelimit implement them.)

JS Rate limiter stand-in

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Pick a store

Edge Config Flags read at the edge.
Redis KV Counters, caches, sessions.
Blobs Files and large values.
Database Relations and queries.

Match the store to the access pattern.

1 / 2

Feature flags from a config store

A flag lets you ship code switched off and turn it on without a redeploy. Real platforms and libraries add targeting rules; the core is a lookup with a default. The stand-in also shows a percentage rollout using a stable hash of the user ID, so the same user always gets the same answer.

JS Feature flag stand-in

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Practical advice

  • Choose key names with a pattern (type:id:field) so you can find and expire them.
  • Always set a TTL on cache keys, or the store fills up with stale entries.
  • Handle a missing store: if KV is down, a rate limiter should usually fail open (allow) for public pages and fail closed for security checks.
  • Never store secrets unencrypted in a store that other tools can read.
  • Mind the free-tier request quotas; a counter incremented on every page view adds up. See Limits, Quotas and Costs.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which store is best for a flag that is read on every request but changes a few times a week?

    Edge Config is optimized for very fast global reads of small, rarely changed values.
  2. 2. Why must a rate-limit counter live in KV rather than in a function variable?

    Each concurrent instance would count separately, and counts vanish when instances are recycled.
  3. 3. What does a TTL do on a cached key?

    Expiry lets stale results disappear so the next request recomputes them.
  4. 4. For a rollout to 20 percent of users, why hash the user ID instead of using Math.random?

    A stable hash keeps each user's experience consistent between requests.

Summary

  • Edge Config is for tiny, read-heavy settings; Redis KV handles frequent writes.
  • TTLs make caching safe by expiring stale values.
  • Shared counters in KV enable rate limiting across function instances.
  • Flags with stable percentage rollouts let you release gradually.
  • Decide fail-open or fail-closed for each use.

Next: Databases from Serverless