Serverless Edge Functions

Writing backend logic, payment processing, and API webhooks running on high-speed edge compute.

Edge Compute & Serverless Runtime Architecture

Serverless Functions in Rayvotech Tools execute on globally distributed edge isolates. Unlike traditional container-based lambda functions that suffer from 2-5 second cold starts, edge isolates boot in under 5 milliseconds worldwide.

< 5ms Cold Start Latency
15s Execution Timeout
128 MB Isolate Memory Limit

Complete TypeScript Edge Function Example

Here is an edge function handling inbound Stripe webhook events, verifying cryptographic signatures, and updating user subscription status in the database:

import { db } from '@/lib/rayvotech';
import Stripe from 'stripe';

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);

export async function POST(req: Request) {
  const sig = req.headers.get('stripe-signature')!;
  const body = await req.text();

  let event: Stripe.Event;
  try {
    event = stripe.webhooks.constructEvent(body, sig, process.env.STRIPE_WEBHOOK_SECRET!);
  } catch (err: any) {
    return new Response(`Webhook Error: ${err.message}`, { status: 400 });
  }

  if (event.type === 'customer.subscription.updated') {
    const sub = event.data.object as Stripe.Subscription;
    await db.from('subscriptions')
      .where('stripe_subscription_id', '==', sub.id)
      .update({ status: sub.status, current_period_end: new Date(sub.current_period_end * 1000) });
  }

  return new Response(JSON.stringify({ received: true }), { status: 200 });
}
No documentation found for ""
Type a keyword like database, custom domain, SDK, or prompting.