A Practical Guide to Serverless and Edge Functions
Running backend code as small functions on demand, either in a cloud region or at CDN edge locations close to users, without managing servers.
On this page
The key figures
- Serverless functions
- run on demand and scale automatically
- Edge functions
- run at CDN locations close to users
- Cold starts
- a delay when a function starts after being idle
- State
- functions should not rely on local memory between requests
Why this is worth getting right
Serverless can reduce operations work and latency for suitable tasks, but it changes how state, cold starts and costs behave.
Do this, not that
Do
- Use functions for event-driven or bursty workloads
- Keep functions small and stateless
- Store state in databases or caches
- Monitor execution time and costs
- Place latency-sensitive logic at the edge
Don’t
- Long-running tasks in functions with short limits
- Assuming serverless is always cheaper
- Database connections exhausted by many function instances
- Moving everything to the edge without need
When to bring in help
Our advice Bring in help when choosing a hosting architecture, or when serverless costs or cold starts become a problem.
Where this comes from
- Cloudflare Learning Center — What is serverless computing?
- Cloudflare Learning Center — What is edge computing?
The figures and practices above come from the sources listed.
Working on something like this?
We take on Web Design & Development work for teams who want it done once, properly. Tell us what you are building and we will tell you honestly whether we are the right studio for it. Start a project.
Where to go next
Spotted something wrong? Report an error on this page. We correct on the page and say what changed.