Configuration
Use Environment Variables for Secrets
Never hardcode secrets. Use the secrets API:Set Appropriate Timeouts
Configure timeouts based on your function’s needs:Use Descriptive Function Names
Function names become part of your URL. Choose wisely:Performance
Reuse Connections
Initialize clients once at module level, not per request:- JavaScript
- Go
- Python
Minimize Cold Starts
Cold starts happen when a new container spins up. Reduce their impact:- Lazy-load dependencies — Only import what you need, when you need it
- Keep functions small — Smaller code = faster load
- Use lightweight frameworks — Hono over Express, FastAPI over Django
Cache Expensive Operations
Use KV for caching API responses and computed data:Reliability
Handle Errors Gracefully
Always return proper error responses:Set Timeouts on External Calls
Don’t let slow external services hang your function:Implement Retries with Backoff
For critical operations, add retry logic:Security
Validate Input
Never trust user input:Use HTTPS for External Calls
Always use HTTPS when calling external services:Don’t Log Sensitive Data
Be careful what you log:Observability
Add Request IDs
Track requests through your system:Log at Appropriate Levels
Use log levels effectively:Related Resources
- Framework Support — Deploy apps built with popular frameworks
- Testing — Test your functions before deploying
- Observability — Monitor your functions