Edge runtimes — Cloudflare Workers, Vercel Edge Functions, Deno Deploy — implement the Web Crypto API rather than full Node.js. crypto.randomUUID() is available globally; the uuid npm package runs without Node.js polyfills. UUID v7 works everywhere. The constraints are network — no long-lived DB connections — which shapes how you assign IDs at the edge.
Cloudflare Workers
export default {
async fetch(request: Request, env: Env): Promise<Response> {
// UUID v4 — built-in, no import
const requestId = crypto.randomUUID();
// UUID v7 — install: npm install uuid
const { v7 as uuidv7 } = await import('uuid');
const recordId = uuidv7();
// Pass to D1 (Cloudflare's edge SQLite)
await env.DB.prepare('INSERT INTO events (id, request_id) VALUES (?, ?)')
.bind(recordId, requestId)
.run();
return Response.json({ id: recordId }, {
headers: { 'x-request-id': requestId },
});
},
};
Cloudflare D1 stores UUID as TEXT. UUID v7 sorts chronologically even in TEXT columns — ORDER BY id gives creation order. See UUID in SQLite for the underlying storage mechanics (D1 is SQLite-compatible).
Vercel Edge Functions (Next.js)
// app/api/orders/route.ts
import { NextResponse } from 'next/server';
import { v7 as uuidv7 } from 'uuid';
export const runtime = 'edge'; // required for Web Crypto globals
export async function POST(request: Request) {
const orderId = uuidv7();
// Propagate as a correlation ID through downstream services
const response = await fetch(process.env.API_URL + '/orders', {
method: 'POST',
headers: {
'x-correlation-id': orderId,
'content-type': 'application/json',
},
body: JSON.stringify({ id: orderId, ...(await request.json()) }),
});
return NextResponse.json(await response.json());
}
export const runtime = 'edge' opts the route into the V8 edge runtime. Without it, Next.js defaults to Node.js runtime where crypto is also available but imported differently. See UUID in React and Next.js.
Deno Deploy
// Deno has uuid in its standard library
import { v7 } from 'jsr:@std/uuid';
Deno.serve(async (req) => {
const id = v7.generate();
return Response.json({ id });
});
Deno’s @std/uuid module provides RFC 9562-compliant UUID v7. No npm install needed. See the JSR @std/uuid documentation.
Correlation IDs at the edge
Assign a UUID v7 at the edge and propagate it as x-correlation-id through every downstream call — databases, queues, third-party APIs. Because UUID v7 encodes creation time, log aggregators can sort all requests chronologically by correlation ID alone. See UUID v7 in Distributed Systems.
Which UUID version at the edge?
- UUID v7 for record IDs, event IDs, correlation IDs — sortable, time-stamped, collision-safe
- UUID v4 (
crypto.randomUUID()) for idempotency keys and public-facing tokens — no timestamp leakage (UUID Security)
Further reading
- crypto.randomUUID() runtime support
- UUID in React and Next.js
- UUID v7 in Distributed Systems
- UUID Security
- UUID in JavaScript — full guide
External references
- Cloudflare Workers Web Crypto API
- Vercel Edge Functions documentation
- Deno @std/uuid on JSR
- RFC 9562 — UUID standard
Frequently asked questions
Does crypto.randomUUID() work in Cloudflare Workers?
Yes. Cloudflare Workers implement the Web Crypto API including crypto.randomUUID() as a global. It is available in all Workers without any compatibility flags. The uuid npm package also works in Workers — Cloudflare's runtime implements the Web Crypto primitives that uuid uses internally. See crypto.randomUUID() support matrix.
Can I use UUID v7 in Vercel Edge Functions?
Yes. Vercel Edge Functions run on the V8-based edge runtime which supports the Web Crypto API. Import { v7 as uuidv7 } from 'uuid' and it works without Node.js polyfills. If you see a crypto is not defined error in older Next.js edge middleware, add export const runtime = 'edge' to your route — this opts into the Web Crypto globals. See UUID in React and Next.js for the Next.js-specific pattern.