Architecture
Edge Functions run on a globally distributed infrastructure:- Kong Gateway: Routes requests and validates authentication
- Edge Runtime: Deno-based runtime executing your function code
- Regional Distribution: Functions deploy to multiple regions for low latency
- Observability: Automatic logging and metrics collection
How Edge Functions Work
When a request arrives:- Kong gateway receives the HTTP request
- Gateway validates authentication headers and applies rate limits
- Request routes to the nearest Edge Runtime node
- Edge Runtime executes your function
- Function can access Supabase services (Auth, Database, Storage)
- Response returns through the gateway to the client
Creating Functions
Basic Function
Create a simple HTTP endpoint: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 URLSUPABASE_ANON_KEY: Anonymous key for client operationsSUPABASE_SERVICE_ROLE_KEY: Service role key for admin operationsSUPABASE_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
