What Are Serverless Functions?

Serverless functions – often called Function‑as‑a‑Service (FaaS) – let you run discrete units of code without provisioning or managing servers. Instead of launching a VM or container, you simply upload your function, declare an event trigger, and the cloud provider takes care of scaling, maintenance, and billing.

Why Use Serverless?

Popular Providers

AWS Lambda
First‑mover with tight integration to the AWS ecosystem.
Azure Functions
Seamless with Microsoft stack, C# support.
Google Cloud Functions
Great for event‑driven workloads, built on Cloud Run.
Vercel Edge Functions
Ultra‑fast, globally distributed, perfect for front‑end hooks.

A Minimal Example (Node.js)

Below is a simple HTTP handler that returns the current UTC time.


// index.js
exports.handler = async (event, context) => {
  const now = new Date().toISOString();
  return {
    statusCode: 200,
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ currentTime: now })
  };
};
    

Upload index.js to your provider, set the handler to index.handler, and bind it to an HTTP trigger.

Cold Starts – The Achilles’ Heel

When a function hasn't run in a while, the platform must boot a new container – that's a cold start. It can add 200‑500 ms of latency. Mitigation tactics include:

  1. Keep the function warm by scheduling a tiny “heartbeat” invocation.
  2. Use provisioned concurrency (if available).
  3. Minimize package size – tree‑shake dependencies.
  4. Prefer runtime languages with fast startup (e.g., Go, Node 14+).

When Not to Use Serverless

Resources to Deep‑Dive