Serverless
You might say
I only have a small feature. Is there a way to run code on demand without buying or managing a server?
Run backend code on demand without managing a long-running serverA serverless function is deployed to a managed platform and starts when an HTTP request, schedule, or event triggers it. It reduces server operations for small independent tasks, but runtime limits, cold starts, regions, and stateless execution still shape the design.
Know first
When to use it
- Small API endpointGood for short, event-driven tasksHTTPSubmit formWebhookPayment webhookCronDaily summary
- Webhook handlerDeploy frontend and functions togethergit push→Build page + API→Get a URLThe platform can host the runtime, but you still manage configuration, monitoring, and cost.
- Scheduled taskKeep state in an external serviceRequest→Short-lived function→Database / storage
- Event-driven processing with irregular trafficPut secrets in platform settingsEnvironment variablesAI_API_KEY = ••••••••Git repositoryNo secrets included
When NOT to use it
- Keep important state only in function memoryTask exceeds the function time limitVideo transcodingEstimated 10 minutes → Function limitTimes out after 10 seconds
- Run a long job beyond the platform limitThe next request may use a different instanceInstance A memorycount = 8 → Instance B memorycount = 0Data that must persist should go into a database or cache.
- Assume there is no infrastructure or cost to manageCheck platform limits before launchTimeout10sRegionsin1Concurrency100Calls this month82%
- Split a simple workflow into too many tiny functionsBusiness logic is wrapped in platform APIsvercel.only.doBusinessRule()cloudflare.only.saveOrder()Too many platform-specific APIs raise the cost of migrating or refactoring core rules.
Anatomy
API gateway→Function instance→External status
The platform handles URLs, HTTPS, scaling, and request routing.
Your code runs when a request or event arrives.
Persistent state lives in databases or storage, not function memory.
Typical use cases
Contact form API
Next.js API RouteDeploys with the frontend project
git push→Platform build→/api/contact available
Depends on the repository branch and deployment settings
Payment webhook
Contact formRequest one email at a time
Send
Function resultEmail sent
Scheduled email
Payment callbackUpdate orders after receiving platform events
payment.succeeded→Verify signature→Order changed to paid
should be designed to be idempotent to avoid repeated accounting for the same callback
Image processing trigger
Scheduled tasksAutomatically perform a summary every day
ScheduleEvery day at 09:00ActionGenerate yesterday's dataRecent run✓ 12.4s
