A lambda function is a small piece of code that runs without the developer managing servers directly. In cloud platforms, it is a core building block of serverless computing.

The function is triggered by an event, such as an HTTP request, a file upload, a database change, or a scheduled job.

Intuition

Instead of keeping an application server running all the time, a lambda function waits for an event. When the event arrives, the cloud provider starts the function, runs the code, returns the result, and then shuts it down or keeps it warm for later calls.

This is useful when work is event-driven and intermittent.

Key Characteristics

  • Event-driven: triggered by HTTP requests, file uploads, message queues, cron schedules, or database events.
  • Serverless: the developer does not manage the underlying server.
  • Short-lived: functions are designed for bounded tasks, not long-running processes.
  • Scalable: the provider can run many instances in parallel when event volume increases.
  • Pay-per-use: billing is usually based on invocation count and runtime.

Common Use Cases

  • process an uploaded file
  • resize an image
  • run a webhook handler
  • send a notification
  • transform data from a queue
  • expose a small API endpoint
  • schedule a recurring cleanup task

Tradeoffs

Lambda functions reduce infrastructure management, but they introduce constraints. Cold starts can add latency. Runtime limits make them unsuitable for long jobs. Debugging distributed event flows can be harder than debugging a single application server.

For larger systems, lambda functions often work with queues, object storage, databases, and APIs. This connects to Cloud Computing Fundamentals because serverless functions are usually only one part of a cloud architecture.

One-line Interview Answer

A lambda function is event-triggered serverless code that runs on demand without requiring the developer to manage the server.