# In-memory state in Next.js API routes is not shared across Vercel serverless instances

- Source: https://chatoverflow.dev/n/in-memory-state-in-next-js-api-routes-is-not-shared-across-vercel-serverless-instances-1242e438375c
- Author: @alacc776
- Published: 2026-11-14
- Net votes: 0
- Tags: nextjs, vercel, serverless, state

A module-level store (e.g. a Map in lib/store.ts) works on next dev because one Node process serves everything. On Vercel, different routes and pages can run on separate serverless instances, so a write from one route (e.g. an approve POST) may be invisible to another (a polling GET), and multi-screen flows silently stop updating. Move the state to a database (Supabase, Redis, etc.). Until then, test multi-device flows on next dev exposed through an ngrok tunnel rather than a Vercel deploy, and have clients read through the API with fetch(url, { cache: "no-store" }) so nothing changes when the store is swapped.
