Skip to main content
Supabase Edge Functions are server-side TypeScript functions distributed globally at the edge—close to your users. Built on Deno, they provide a portable, TypeScript-first runtime for custom backend logic, webhooks, and API integrations.

Architecture

Edge Functions run on a globally distributed infrastructure:
  1. Kong Gateway: Routes requests and validates authentication
  2. Edge Runtime: Deno-based runtime executing your function code
  3. Regional Distribution: Functions deploy to multiple regions for low latency
  4. Observability: Automatic logging and metrics collection
Edge Functions use the Supabase Edge Runtime, a Deno-compatible runtime that’s portable and open source.

How Edge Functions Work

When a request arrives:
  1. Kong gateway receives the HTTP request
  2. Gateway validates authentication headers and applies rate limits
  3. Request routes to the nearest Edge Runtime node
  4. Edge Runtime executes your function
  5. Function can access Supabase services (Auth, Database, Storage)
  6. Response returns through the gateway to the client

Creating Functions

Basic Function

Create a simple HTTP endpoint:
Deploy the function:
Invoke from your app:

With Supabase Client

Access Supabase services from your function:

With Database Connection

Connect directly to Postgres:

Common Use Cases

Webhook Handler

AI/ML Integration

Image Processing

Scheduled Tasks (with pg_cron)

Environment Variables

Setting Secrets

Accessing in Functions

Default Environment Variables

These are automatically available:
  • SUPABASE_URL: Your project URL
  • SUPABASE_ANON_KEY: Anonymous key for client operations
  • SUPABASE_SERVICE_ROLE_KEY: Service role key for admin operations
  • SUPABASE_DB_URL: Database connection string

CORS Configuration

Local Development

Serve Locally

Test Functions

Background Tasks

For long-running operations, use background tasks:

Monitoring and Debugging

Logging

Error Handling

Performance Optimization

Connection Pooling

Caching

Best Practices

Keep Functions Small

Design functions for specific tasks to improve maintainability.

Use Service Role Wisely

Only use service role key when necessary; prefer user context.

Handle Errors Gracefully

Always implement proper error handling and return meaningful messages.

Monitor Performance

Use logging and metrics to track function performance.

Limitations

  • Execution time: 150 seconds maximum
  • Memory: 512MB per invocation
  • Cold starts: First request may be slower
  • No persistent storage: Use Database or Storage for persistence
  • Limited concurrency: Design for short-lived operations

Next Steps

Quickstart

Get started with your first Edge Function

AI Models

Integrate AI and ML models

Background Tasks

Handle long-running operations

Examples

Explore example functions