The Serverless + Database Problem
AWS Lambda + RDS: cold starts + database connections = slow. Vercel Functions + Neon: two platforms to manage. Every combo has a latency tax.
Supabase Edge Functions run on Deno Deploy — in the same infrastructure as your database. Minimal latency. TypeScript native.
What Supabase Edge Functions Give You
Simple Function
import { serve } from 'https://deno.land/std/http/server.ts';
serve(async (req) => {
const { name } = await req.json();
return new Response(
JSON.stringify({ message: `Hello ${name}!` }),
{ headers: { 'Content-Type': 'application/json' } },
);
});
Direct Database Access
import { createClient } from 'https://esm.sh/@supabase/supabase-js';
serve(async (req) => {
const supabase = createClient(
Deno.env.get('SUPABASE_URL')!,
Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!,
);
const { data: users } = await supabase
.from('users')
.select('*')
.limit(10);
return new Response(JSON.stringify(users));
});
Database client is pre-configured. No connection string management.
Webhooks
serve(async (req) => {
const payload = await req.json();
// Process Stripe webhook
if (payload.type === 'checkout.session.completed') {
const supabase = createClient(/* ... */);
await supabase.from('orders').insert({
stripe_session: payload.data.object.id,
amount: payload.data.object.amount_total,
});
}
return new Response('OK');
});
Scheduled Functions (Cron)
-- In Supabase dashboard, schedule a cron job
select cron.schedule('cleanup', '0 * * * *', $$
select net.http_post(
url := 'https://your-project.supabase.co/functions/v1/cleanup',
headers := '{"Authorization": "Bearer ..."}'::jsonb
);
$$);
Deploy
supabase functions deploy my-function
One command. Deployed globally.
Free Tier
- 500K invocations/month
- 2M edge function requests
- Direct database access included
Quick Start
supabase init
supabase functions new hello-world
supabase functions serve # Local dev
supabase functions deploy hello-world
Why This Matters
Serverless functions should be as close to your data as possible. Supabase Edge Functions eliminate the network hop between your function and your database.
Need web data in your Supabase database? Check out my web scraping actors on Apify Store — automated data import. For custom solutions, email spinov001@gmail.com.
Top comments (0)