# How a request reaches your code

> How Ferrite's gateway turns public HTTP traffic into queue messages, filters headers, enforces ingress bounds, and dispatches five route kinds.

In a conventional web service, every application owns its public network edge:
listening sockets, connection limits, payload caps, and raw header parsing all
live inside the same process as your business logic. Ferrite puts a queue
between the public internet and your code. A Ferrite app never listens on a
port. The platform gateway accepts public traffic, matches each request against
the routes declared in `ferrite.json`, and publishes an `IngressRequest` onto
the queue bound to that route. Your app consumes the message, runs its handler,
and publishes an `IngressReply` to the reply queue named in the envelope. The
gateway then sends the HTTP response back to the caller.

Placing the gateway ahead of the queue lets the platform shed invalid or
excessive load before your code ever wakes up. The gateway rejects any request
body larger than 256 KiB with `413` (an [upload route](/docs/large-uploads)
takes files of up to 64 MiB), and once 1,024 requests are already
waiting for replies, it rejects new arrivals with `429` and a `Retry-After`
header. For every bound the gateway enforces, see [Limits](/docs/limits)
and [Ingress limits and status codes](/kb/guide/ingress-limits-429-402/).

## Routes and header forwarding

Here is a trimmed version of the yoga studio's `routes` block showing the two
decisions every route entry makes (the studio's full manifest also forwards
cookie and CSRF headers for sign-in, plus `mcp-protocol-version` once you add
MCP):

```json
"routes": [
  { "prefix": "/__alloy/", "binding": "requests", "kind": "api", "public": true,
    "forward_headers": ["accept", "idempotency-key", "origin", "sec-fetch-site"] },
  { "prefix": "/", "binding": "requests", "kind": "api", "public": true,
    "forward_headers": ["accept"] }
]
```

The `prefix` and `binding` fields determine which queue receives a matching
request. The `forward_headers` list defines an explicit allowlist of caller
headers copied into the request's `headers` map. Every undeclared header is
dropped at the gateway before it reaches your code, with one exception: the
gateway always reads a caller's `idempotency-key` header itself and populates
the envelope's `idempotency_key` field from it.

## Request budgets and rate limiting

Outside the 1,024 in-flight capacity cap, the gateway sets no per-route request
budget on your app. The studio declares no budget, so nothing caps its traffic
below that ceiling. When a route needs a traffic cap across all callers, add
the `http-route-budget` package. It keeps one token bucket per route in one of
your app's stores and answers with `429` when the bucket is empty. In an Alloy
app like the studio, call it from the `request_budget` hook, which `serve`
executes before `answer`. If your app needs per-caller limits, maintain a
counter keyed by an identity your application has verified, such as a signed-in
user.

The manifest format also includes a `rate_limit_per_min` route key. Because
gateway-side enforcement of `rate_limit_per_min` is not active on Ferrite
Cloud, `ferrite deploy` and `ferrite cost` hold any manifest that declares that
key and explain why. Manifests that omit the key deploy without a hold. If a
manifest already carries `rate_limit_per_min`, keep the key as declared and do
not submit through raw `deploy_source` to bypass the CLI hold. Use
`http-route-budget` for route-level traffic budgets, and read
[Rate limits](/docs/rate-limits) for the full details on the hold and
package setup.

## Inside the request envelope

Each `IngressRequest` carries the fields a handler needs to process the call
and send a matching reply:

| Field | What it carries |
| --- | --- |
| `correlation_id` | Per-request identifier generated by the gateway that your `IngressReply` must echo. Every HTTP request receives a fresh `correlation_id`, including client retries. |
| `idempotency_key` | The caller's `idempotency-key` header when supplied, or `correlation_id` when absent. Without an `idempotency-key` header, every HTTP retry looks new and repeats the effect if the original reply was lost. |
| `path`, `method`, `headers`, `body` | Request path with the query string intact, HTTP method, allowlisted headers, and request body. |
| `route`, `reply_to` | The matched route prefix and the queue name where the reply must be published. |
| `deadline_ms` | Absolute deadline in epoch milliseconds after which the gateway stops waiting and answers the caller with `504`. Once past this timestamp, the delivery may be a redelivery and the caller has already timed out, so a handler can skip work whose reply can no longer be delivered. |

The envelope also carries `verified_host` (read with `req.verified_host()`),
which holds the lowercased host and port the gateway served the request under.
The gateway sets this field and callers cannot spoof it, so you can trust it
when constructing absolute URLs. Because `verified_host` is absent when a
request names no host and on WebSocket and stream-close envelopes, keep a
configured fallback such as `PUBLIC_ORIGIN` in
[Let a customer's assistant book a class](/academy/agent-ready/).

## Queue delivery and Alloy's serve loop

In the studio, you do not write the queue polling loop by hand.
`alloy::app::serve` runs it for you: pull a request, call `answer`, publish the
`IngressReply`, and acknowledge the queue message last.

Acknowledging last is intentional because queue delivery is at least once. If
an instance stops after finishing the work and before acknowledging the
message, the queue delivers the same request again, so every handler with side
effects must make that second delivery harmless. On the ingress side, the
gateway itself replays only a stalled `GET`, up to three times, and never
repeats requests of any other HTTP method. Lesson 3 walks through how the
studio makes repeated bookings harmless.

## Route kinds

Each route's `kind` field selects how the gateway handles matching traffic:

| Kind | Behavior |
| --- | --- |
| `api` | Standard request-and-reply HTTP traffic over a bound queue. |
| `content` | Static files served from a blob binding. |
| `stream` | Server-sent events (SSE). |
| `ws` | WebSocket connections. |
| `grpc` | gRPC services over HTTP/2, where `prefix` is the protobuf full service name, such as `/acme.orders.Orders/`. |

Local `ferrite validate` refuses `grpc` routes even though the platform accepts
them, so check manifests with `grpc` routes using `ferrite check --remote`. For
an example combining several route kinds in one app, the live counter from
lesson 1 of [Build a booking app with Alloy](/academy/ship-an-alloy-app/) uses
`content` for its page, `api` for `/api/` and `/health`, and `stream` for its
live feed.

Only `api` and `grpc` routes forward caller headers. A `stream` or `ws` route
receives none, so browser clients opening a stream or WebSocket authenticate
with a query-string value or their first message. If a manifest includes
`forward_headers` on a `stream` or `ws` route, the CLI strips it before
submitting the manifest and reports the removal in its output. For the complete
manifest schema, see [App Manifest](/docs/app-manifest).
