Supabase Edge Functions deploy globally on Deno Deploy, co-located with Supabase Postgres. UUID v7 generated at the edge flows directly into the database as a primary key — no server round-trip, no coordination. See UUID v7 in Supabase Realtime for the full integration guide.

Edge Function with UUID v7 request ID

// supabase/functions/create-order/index.ts
import { serve }         from 'https://deno.land/std@0.177.0/http/server.ts';
import { createClient }  from 'https://esm.sh/@supabase/supabase-js@2';
import { v7 as uuidv7 }  from 'https://esm.sh/uuid';

const supabase = createClient(
  Deno.env.get('SUPABASE_URL')!,
  Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!,
);

serve(async (req) => {
  const requestId = uuidv7(); // UUID v7 — edge generation time embedded
  const start     = Date.now();

  try {
    const body = await req.json();
    const { data, error } = await supabase
      .from('orders')
      .insert({
        id:          requestId,  // UUID v7 — same ID in DB and logs
        customer_id: body.customer_id,
        total:       body.total,
        status:     'pending',
      })
      .select()
      .single();

    if (error) throw error;

    console.log({ requestId, path: '/create-order', ms: Date.now() - start });

    return new Response(JSON.stringify(data), {
      status:  201,
      headers: {
        'Content-Type':    'application/json',
        'X-Request-Id':    requestId,  // UUID v7 in response header
        'X-Response-Time': String(Date.now() - start),
      },
    });
  } catch (err) {
    console.error({ requestId, error: String(err) });
    return new Response(JSON.stringify({ error: String(err), requestId }), {
      status:  500,
      headers: { 'Content-Type': 'application/json' },
    });
  }
});

Cursor pagination from the edge

// supabase/functions/list-orders/index.ts
import { serve }        from 'https://deno.land/std@0.177.0/http/server.ts';
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';

serve(async (req) => {
  const url    = new URL(req.url);
  const cursor = url.searchParams.get('cursor');
  const limit  = Number(url.searchParams.get('limit') ?? '20');

  let query = supabase
    .from('orders')
    .select('id, total, status')
    .order('id', { ascending: true })
    .limit(limit);

  // UUID v7 lexicographic sort = chronological — no created_at needed
  if (cursor) query = query.gt('id', cursor);

  const { data } = await query;
  const nextCursor = data?.length === limit ? data.at(-1)?.id : null;

  return Response.json({ items: data, nextCursor });
});

Further reading

External references

Frequently asked questions

How do I generate UUID v7 in a Supabase Edge Function?

Supabase Edge Functions run on Deno. Import the uuid npm package via esm.sh: import { v7 as uuidv7 } from "https://esm.sh/uuid". Call uuidv7() to generate a UUID v7 string. See UUID v7 in Supabase Realtime for the full Supabase guide.

Can I pass UUID v7 as a Postgres primary key from an Edge Function?

Yes. Generate UUID v7 in the Edge Function and pass it to your Supabase client insert: supabase.from('orders').insert({ id: uuidv7(), ...data }). The UUID v7 string is cast to PostgreSQL's uuid type automatically. Time-ordering means recent records appear at the end of the B-tree index — fewer page splits than UUID v4. See UUID in PostgreSQL.

How does UUID v7 help correlate Edge Function logs with database rows?

Generate one UUID v7 per request at the start of the Edge Function. Use it as both the database row ID and the log correlation token: console.log({ requestId, path, ms }). Because UUID v7 embeds the creation timestamp, you can reconstruct when a request arrived without querying the database. See UUID v7 for Audit Logging.