Skip to content
Now accepting new projects — limited slots available. Get started →
Architecture · Updated Jul 30, 2026

What is Serverless Functions?

Serverless functions are event-driven compute units that run backend code without managing servers.

What is a Serverless Function?

A serverless function is a stateless, event-driven unit of backend code that executes on demand without requiring you to provision or manage servers. The cloud provider (AWS Lambda, Vercel Functions, Cloudflare Workers, Google Cloud Functions) handles scaling, patching, and infrastructure automatically. AWS Lambda launched the model in November 2014, and by 2026 every major cloud and frontend platform supports some flavor of it. Functions typically respond to HTTP requests, queue messages, or scheduled cron triggers. Cold start latency — the delay when a function hasn't been invoked recently — ranges from ~50ms on Cloudflare Workers to 200-800ms on AWS Lambda with Node.js 20, depending on bundle size and runtime. We use serverless functions on virtually every Next.js project we ship, most commonly for API routes that handle form submissions, webhook ingestion, or third-party API proxying.

How it works

When a request hits a serverless function endpoint, the platform spins up an execution environment (if one isn't already warm), loads your handler code, runs it, and returns the response. The lifecycle looks like this:

  1. Trigger — An HTTP request, a message on a queue, or a cron schedule fires.
  2. Cold start (if needed) — The runtime initializes. The platform loads your function bundle, boots the runtime (Node.js, Python, Go, etc.), and runs any top-level initialization code.
  3. Execution — Your handler function runs. It has access to the event payload and a context object with metadata like remaining execution time.
  4. Response — The function returns a result. For HTTP triggers, this is a status code, headers, and body.
  5. Freeze or teardown — The execution environment is either kept warm for subsequent invocations or destroyed after an idle timeout.

In Next.js App Router (v14+), any route.ts file inside app/api/ becomes a serverless function on Vercel by default:

// app/api/contact/route.ts
import { NextResponse } from 'next/server';

export async function POST(request: Request) {
  const body = await request.json();
  // validate, store, send email, etc.
  return NextResponse.json({ ok: true }, { status: 200 });
}

Each function is isolated — it doesn't share memory or filesystem state with other invocations. If you need shared state, you reach for an external store: a database, Redis, or KV namespace.

When to use it

Serverless functions are a strong default for most backend work in a Jamstack or Next.js architecture. We've shipped them on 50+ projects and here's our mental model:

Use serverless functions when:

  • You need API endpoints for form handling, auth callbacks, or webhook receivers
  • Traffic is spiky or unpredictable — you don't want to pay for idle servers
  • You want zero-ops infrastructure with automatic scaling
  • You're building a prototype or MVP and speed-to-deploy matters

Skip serverless functions when:

  • You have long-running tasks (>30s on Vercel, >15min on Lambda) — use a queue + worker instead
  • You need persistent WebSocket connections — use a dedicated server or Durable Objects
  • Cold start latency is unacceptable for your use case — consider edge runtime or a long-running container
  • You have heavy CPU/memory workloads like video transcoding — a dedicated compute instance is cheaper at scale

Serverless Functions vs alternatives

Serverless Functions Edge Runtime Traditional Server Containers (ECS/Fly)
Cold start 50-800ms <10ms (V8 isolates) None (always on) 2-15s
Max execution 10s–15min 30s (typical) Unlimited Unlimited
Node.js API support Full Subset (no fs, limited) Full Full
Scaling Automatic, per-request Automatic, per-request Manual or auto-scaled Auto-scaled
Cost at zero traffic $0 $0 $5-50+/mo $0-5+/mo
Best for API routes, webhooks Auth, redirects, personalization Stateful apps, WebSockets Long-running or GPU tasks

Our preferred stack at Social Animal is Next.js API routes deployed as serverless functions on Vercel for standard backend work, with Cloudflare Workers (edge runtime) for latency-critical middleware like geo-redirects or A/B test assignment.

Real-world example

On a recent e-commerce project, we needed to validate discount codes against a Shopify Storefront API before checkout. We built a single serverless function at /api/validate-discount in Next.js 15. It receives a POST with the code, calls Shopify's GraphQL endpoint, and returns validity + discount percentage. On Vercel's Pro plan (us-east-1), p50 response time was 120ms and p99 was 310ms. The function handles 0 to 12,000 invocations per hour during flash sales without any scaling configuration. Monthly cost: under $3 on Vercel's included usage tier. Before this, the client ran a $40/month Express server on Railway that sat idle 22 hours a day.

Frequently asked questions about Serverless Functions

Are serverless functions the same as edge functions?
No. Serverless functions typically run in a single region on a full Node.js runtime (or Python, Go, etc.) with access to the complete standard library. Edge functions run on a distributed network of points of presence using a lighter runtime — usually V8 isolates like Cloudflare Workers or Vercel Edge Runtime. Edge functions have lower latency (sub-10ms cold starts) but a restricted API surface: no native `fs` module, no spawning child processes, and typically stricter execution time limits (30 seconds vs. 10-15 minutes). Use edge functions for lightweight, latency-sensitive work like redirects or header manipulation. Use serverless functions when you need full Node.js APIs or heavier computation.
When did serverless functions become standard?
AWS Lambda launched in November 2014 as the first major serverless compute platform, initially supporting Node.js 0.10. Google Cloud Functions followed in 2016, and Azure Functions arrived the same year. The model went mainstream in frontend-adjacent development around 2019-2020 when Vercel (then ZEIT) and Netlify made deploying serverless functions a zero-config default for Next.js and Gatsby projects. By 2022, serverless was the default deployment model for Next.js API routes on Vercel. As of April 2026, it's the assumed backend compute layer for most Jamstack and hybrid SSR architectures.
What's the alternative to serverless functions?
The main alternatives are long-running containers (Docker on AWS ECS, Fly.io, Railway), traditional VPS servers (running Express, Fastify, or similar), and edge runtimes (Cloudflare Workers, Vercel Edge Functions). Containers give you persistent processes, full filesystem access, WebSocket support, and no cold starts — but you pay for idle time and handle scaling yourself. A VPS is the simplest mental model but the most ops-heavy. Edge runtimes are the lightest option but have the most API restrictions. For most web app backends, serverless functions hit the sweet spot of cost, simplicity, and capability.
How do you reduce cold start times for serverless functions?
Keep your function bundle small — tree-shake aggressively, avoid importing large SDKs you don't need, and use ESM where the platform supports it. On AWS Lambda, use provisioned concurrency to keep a set number of instances warm (this costs more). On Vercel, functions in regions closer to your database reduce round-trip time which matters more than the cold start itself. Move expensive initialization (like database connection pooling) outside the handler so it persists across warm invocations. If cold starts are truly critical, consider edge runtime for eligible workloads — Cloudflare Workers cold starts are typically under 5ms because they use V8 isolates instead of full container boots.
Get in touch

Let's build
something together.

Whether it's a migration, a new build, or an SEO challenge — the Social Animal team would love to hear from you.

Get in touch →