Serverless
01 / 02

Core Concepts & Triggers

Core Concepts & Triggers

What "Serverless" Actually Means

Servers still run the code — "serverless" means the developer never provisions, manages, or scales them. FaaS (Functions as a Service — AWS Lambda, Cloud Functions, Azure Functions) is the compute model: deploy individual functions that run in response to events, with no persistent server process to manage.

// AWS Lambda handler — event-driven, stateless
exports.handler = async (event) => {
  const userId = event.pathParameters.id;
  const user = await db.getUser(userId);  // state lives in an external store —
  return {                                 // never trust in-memory state to persist
    statusCode: 200,
    body: JSON.stringify(user),
  };
};

Common Triggers

HTTP requests via an API Gateway, a message on a queue, a file uploaded to storage, a scheduled cron-like timer, or a database change event. API Gateway routes requests to the right function and can handle auth/rate-limiting/transformation before the function even runs.

Cold Starts & Warm Instances

A cold start is the added latency when no already-initialized ("warm") instance is available — the platform must provision and initialize one first. Interpreted runtimes typically cold-start faster than JVM-based ones. "Provisioned concurrency" pays to keep a set number of instances permanently warm, trading away some of the pure pay-per-use economics for latency guarantees.

Idempotency

// Queue-triggered functions commonly get at-least-once delivery —
// the SAME event can invoke the function more than once
exports.handler = async (event) => {
  for (const record of event.Records) {
    const alreadyProcessed = await db.wasProcessed(record.messageId);
    if (alreadyProcessed) continue;  // safe no-op on redelivery

    await chargeCustomer(record.body);
    await db.markProcessed(record.messageId);
  }
};

Keep your own version of these notes — editable, searchable, and organised by your stack.

Start free