Building with Edge KV
Consistency, TTLs, and a pattern for session data at the edge.
Edge KV is eventually consistent. A write from NRT is readable in NRT immediately and in other colos within a couple of seconds. That is enough for session blobs, feature flags, and HTML fragments. It is the wrong tool for a bank ledger.
Write from a Worker
export default {
async fetch(request, env) {
if (request.method === "POST") {
const sid = crypto.randomUUID();
await env.SESSIONS.put(sid, await request.text(), { expirationTtl: 1800 });
return new Response(null, { status: 204, headers: { "set-cookie": `sid=${sid}; Path=/; HttpOnly; Secure` } });
}
const sid = request.headers.get("cookie")?.match(/sid=([^;]+)/)?.[1];
const session = sid ? await env.SESSIONS.get(sid) : null;
return new Response(session || "{}", { headers: { "content-type": "application/json" } });
},
};
Create the namespace
$ gitflare kv namespace create SESSIONS
$ gitflare kv put SESSIONS welcome '{"v":1}' --ttl 3600
$ gitflare kv get SESSIONS welcome
Keys are UTF-8, up to 512 bytes. Values are 25 MiB on paid plans. List is paginated; see the 2026-06-02 changelog for cursor.