# Function as a Service (FaaS)

Function as a Service (FaaS) is a cloud computing execution model where the cloud provider manages the server infrastructure and dynamically allocates resources to run individual functions in response to events or HTTP requests. Developers write discrete pieces of logic -- functions -- and deploy them without provisioning or maintaining servers.

## How FaaS works

In a FaaS environment, each function is typically triggered by an event such as an HTTP request, a database change, a message queue event, or a scheduled timer. The cloud provider spins up an execution environment, runs the function, returns the result, and then tears down or freezes the environment. Billing is based on actual execution time and the number of invocations rather than reserved capacity.

Common FaaS platforms include AWS Lambda, Google Cloud Functions, Azure Functions, and Cloudflare Workers. Each differs in supported runtimes, cold start behavior, execution limits, and pricing models, but they share the core principle: the developer supplies code, and the platform handles everything else.

## Key characteristics

* **Event-driven execution**: Functions run only when triggered, making FaaS well suited for workloads with variable or unpredictable traffic patterns.
* **Automatic scaling**: The platform scales function instances up and down based on demand, including scaling to zero when there is no traffic.
* **Pay-per-use pricing**: Costs are tied to the number of executions and their duration, which can reduce expenses for infrequent or bursty workloads.
* **Stateless by default**: Each function invocation is independent. Persistent state must be stored externally in a database, cache, or object store.

## FaaS and API gateways

An API gateway is a natural companion to FaaS. The gateway receives inbound HTTP requests, applies policies such as authentication and rate limiting, and routes traffic to the appropriate function or backend. This separation lets developers keep business logic in lightweight functions while the gateway handles cross-cutting concerns.

Serverless API Gateway runs on Cloudflare Workers -- itself a FaaS platform -- and can route requests to backend services running on any cloud provider's FaaS offering. Because both the gateway and the backend functions are serverless, the entire request path can operate without fixed infrastructure, scaling on demand and incurring costs only when requests are processed.

## When to use FaaS

FaaS is a strong fit for API backends, webhook handlers, scheduled jobs, data transformations, and event processing pipelines. It is less suited for long-running processes, workloads with sustained high throughput where reserved capacity is more cost-effective, or applications that depend heavily on in-memory state between requests.

## Related documentation

* [Getting Started](/getting-started/introduction.md) - Deploy your first serverless API gateway
* [Servers Configuration](/configuration/servers.md) - Configure upstream servers including FaaS backends
* [Service Binding](/configuration/service-binding.md) - Bind Cloudflare Workers services together


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.serverlessapigateway.com/glossary/f/function-as-a-service-faas.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
