Your JAMstack site is growing, and it's time to add server-side logic without a dedicated backend. Netlify Functions are serverless handlers that deploy alongside your frontend in minutes. Just create a file in netlify/functions/ and the function is ready. A typical problem: a contact form on a static site fails to send data, or you need to handle webhooks from external services. Instead of spinning up a separate server, we use Netlify Functions. Infrastructure cost is nearly zero, and automatic scaling removes headaches.
We have been writing serverless functions for Netlify since the platform launched. Over 5 years, we have implemented 50+ functions for 15 projects: form processing, PDF generation, webhook integrations with CRM and payment systems. Our engineers are JAMstack certified; we guarantee stable function performance under a load of 1000+ requests per minute.
Two types of functions
Sync Functions — standard request/response. Support Node.js 18+, Go, Rust. Timeout 10 seconds (free) / 26 seconds (Pro).
Background Functions — for long-running tasks (up to 15 minutes). Immediately return 202 Accepted, execution continues in the background. File naming: *.mts or *-background.ts.
| Parameter | Sync Function | Background Function |
|---|---|---|
| Execution time | up to 10/26 sec | up to 15 min |
| Response to client | after completion | immediate 202 Accepted |
| Typical use | API, webhooks, forms | PDF generation, data processing, email sending |
How to choose between Sync and Background Functions?
| Scenario | Function type |
|---|---|
| Contact form processing | Sync |
| PDF report generation | Background |
| Webhook from payment system | Sync |
| Mass email sending | Background |
| Frontend API (CRUD) | Sync |
| Image processing | Background |
Benefits and development speed
Netlify Functions deploy 3-5 times faster than a separate server on AWS EC2. You don't need to manage infrastructure: scaling, security patches, and load balancing happen automatically. This reduces administration costs by 2-3 times (saving $500–$2000/month compared to a dedicated server). Git repository integration allows you to deploy functions alongside the frontend with a single git push — no need to set up a separate CI/CD pipeline. Local development via netlify dev mimics the production environment. Cold start can be reduced using esbuild bundling and configuring Warm Functions on the Pro plan.
How to optimize cold start?
Cold start is the delay on the first function invocation when the execution environment is not ready. In Netlify Functions, it defaults to 200–500 ms. To reduce it to 50–100 ms, use esbuild for bundling (it combines dependencies into a single file) and choose the Pro plan with Warm Functions, which keeps functions warm. Also avoid monolithic dependencies: import only the needed modules.
Typical mistakes in Netlify Functions development
- Ignoring cold start: test functions with a warmed environment. - No error handling: always return correct HTTP status. - Not using environment variables: store keys in `.env`, not in code. - Forgetting limits: timeout 10 sec for Sync, 15 min for Background.Example sync function
File netlify/functions/contact.ts:
import type { Handler, HandlerEvent } from "@netlify/functions";
export const handler: Handler = async (event: HandlerEvent) => {
if (event.httpMethod !== "POST") {
return { statusCode: 405, body: "Method Not Allowed" };
}
const data = JSON.parse(event.body || "{}");
const { name, email, message } = data;
// Send via Netlify Email Integration or external API
await fetch("https://api.sendgrid.com/v3/mail/send", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.SENDGRID_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
personalizations: [{ to: [{ email: "[email protected]" }] }],
from: { email: "[email protected]" },
subject: `Message from ${name}`,
content: [{ type: "text/plain", value: `${name} (${email}): ${message}` }],
}),
});
return {
statusCode: 200,
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ ok: true }),
};
};
The function is accessible at /.netlify/functions/contact or via redirect. For example, using netlify.toml: redirect /api/contact to /.netlify/functions/contact.
Background Function for reports
// netlify/functions/generate-report-background.ts
import type { BackgroundHandler } from "@netlify/functions";
export const handler: BackgroundHandler = async (event) => {
const { reportId } = JSON.parse(event.body || "{}");
// Long operation: PDF generation, data processing
const pdf = await generatePDFReport(reportId);
// Save to S3 and notify user
await uploadToS3(pdf, `reports/${reportId}.pdf`);
await notifyUser(reportId);
};
netlify.toml configuration
[build]
command = "npm run build"
publish = "dist"
functions = "netlify/functions"
[functions]
node_bundler = "esbuild"
included_files = ["templates/**"]
[dev]
command = "npm run dev"
port = 8888
node_bundler = "esbuild" speeds up builds and reduces bundle size by 40% compared to zip archive.
Environment variables
Netlify Dashboard → Site Settings → Environment variables. For local development, use a .env file:
SENDGRID_API_KEY=SG.xxx
DATABASE_URL=postgresql://...
Work process and scope of services
We perform the full cycle of serverless function development:
- Analytics — defining required functions, their signatures, and integrations.
- Design — architecture, choice of function types, cold start optimization.
- Implementation — coding with esbuild bundling.
- Testing — local launch via
netlify dev, edge case verification. - Deployment — setting up automatic deployment via Git.
What is included (deliverables)
- Function code with error handling and logging
-
netlify.tomland redirect configuration - Environment variable setup
- Local and production testing
- Call and deployment documentation
- Access to repository and CI/CD pipeline
- 1-hour training session on maintenance
- 30-day support after project delivery
Timeframes and cost
Basic functions (form, webhook) with redirect configuration — 1–2 days, starting from $500. Complex integrations (PDF generation, external APIs) — from 3 days, starting from $1500. Contact us for a free consultation on your serverless architecture.
Official Netlify Functions documentation: Netlify Functions overview







