drift Docs
Pages
drift Docs
Start
What is Drift?
The tour, if you are new here.
Use cases
Whether Drift does your thing.
Getting started
Nothing to deployed, in one command.
Architecture
How a slice is put together.
What it costs
The free grant, four unit prices, two rules.
Moving off Azure
Estimate, snapshot and transform a resource group.
Build
Canvas
Static sites, same origin as your API.
Tools
Operate
Auth
Route gates, API keys and your account.
Teams
More than one person on one account.
Security
Boundaries, sandboxing and hardening.
Troubleshooting
Error codes
What went wrong, and what to do about it.
Legal
Acceptable use
What a slice may not be used for.
Data processing
The DPA, and every sub-processor.

Limits and alerts

A function runs inside three declared bounds, and tells you when it crosses one. The bounds are the Driftfile's; the telling is an alert you define per function.

Limits, and what the caller sees

Three knobs bound a function, and all three are written in the Driftfile. The memory it books is the function's own memory. The function timeout is timeout in the slice's limits block. The request rate for the slice is edge.rate_limit, or requests_per_minute in limits; both write the same figure, so the file states it in one place.

Driftfile
slice "shop" {
  limits {
    timeout = "30s"
  }
}

atomic {
  backend "default" {
    function "POST /checkout" {
      handler = "PostCheckout"
      memory  = "32MiB"
    }
  }
}

edge {
  rate_limit = "600/min"
}

This is what a client gets when one is reached:

X-Drift-ReasonCause, and what to do
  • 504
    X-Drift-Reason
    FUNCTION-TIMEOUT
    Cause, and what to do
    The invocation outlived limits.timeout. It is stopped at that budget rather than left running, so a slow function is ended and not merely abandoned.
  • 429
    X-Drift-Reason
    —
    Cause, and what to do
    The slice passed its requests per minute for the current window. Counted per account and slice, across every request that arrives however it arrives. Raise the limit, or send less.
  • 503 + Retry-After: 1
    X-Drift-Reason
    FUNCTION-MEMORY
    Cause, and what to do
    That function is holding all the memory it booked, so there is no room to start another invocation. It clears on its own as calls finish, and booking more memory raises how many can run at once. Not a 429: your caller did nothing wrong.
  • 503 + Retry-After: 5
    X-Drift-Reason
    SLICE-MEMORY
    Cause, and what to do
    The whole slice is briefly under memory pressure and is shedding new work. It clears on its own.
  • 500
    X-Drift-Reason
    EVICTED
    Cause, and what to do
    One invocation grew past the memory its function booked and was stopped, so everything running beside it kept going. The remedy is a bigger memory: the function was booked too small, not written wrong. Your function's log carries the detail.
  • 500
    X-Drift-Reason
    FUNCTION-FAILED
    Cause, and what to do
    The function ran and produced no response that could be sent: it exited without writing one, or wrote something unreadable. Your function's log carries what it printed.

The body says nothing about Drift. Every response above carries a plain {"error":"service unavailable"} or {"error":"internal error"}, because it is your API answering your users, who can neither read your Driftfile nor act on it. The machine-readable reason rides in the X-Drift-Reason header for your own logging and alerting, and anything actionable (which function, which figure, which remedy) goes to that function's log, where the person who can change it is the person reading.

A 503 and a 500 ask for opposite things. A 503 clears by itself, so a retry is reasonable. A 500 from an eviction repeats identically until the booking changes, which is why it carries no Retry-After: sending your caller round a loop that cannot end would be worse than telling them it failed. See memory and concurrency for how the booking decides both.

A timeout is enforced once, on one clock, so a call cannot be cut off in one place while still running in another. A limit the file leaves out is the platform's figure for it, which for a free slice is the free slice's own: 10 s of runtime and 60 requests per minute, and up to five functions and workers booking 80 MiB between them, in any sizes. A shape bigger than the free slice is refused, naming what is over. A monthly slice books memory per function and sets its own limits.

edge.rate_limit is written per second, minute or hour (10/s, 600/min, 3600/h) and held as a whole number of requests per minute. drift plan and drift apply refuse a rate below one per minute, or one that is not a whole number per minute, before anything is sent. A free slice cannot declare more than its 60 per minute; a monthly slice may declare up to 60,000. See Edge.

Alerts

The slice evaluates alerts once a minute against each function's error count over a sliding window, and fires a webhook on each state change: one POST when it starts firing, one when it resolves, not one per tick. Alert definitions survive a restart.

An alert is declared on the function it watches, in the Driftfile:

Driftfile
function "POST /checkout" {
  handler = "PostCheckout"
  memory  = "32MiB"

  alert "checkout-errors" {
    threshold = 5
    window    = "5m"
    webhook   = env("CHECKOUT_ALERT_HOOK")
  }
}

drift plan shows alerts added, changed and removed, and drift apply sets them once the function is deployed. An alert the file does not name is deleted on apply, after the question every removal asks (--approve-remove "alert checkout-errors" in a script). The webhook URL carries whatever credential its endpoint needs, so it is written env("NAME") and read from the environment when the alert is applied: it is never in the file or in the plan. The alert's name belongs to the slice, not to the function, so two functions cannot both declare checkout-errors. drift atomic alert list shows what the slice holds.

on = "errors" is the whole condition, and the default. threshold (default 1) is how many errors within window (default "5m", at least "1m") fire it. The webhook is an http(s) URL; there is no other way to be told yet. The webhook receives JSON:

JSON
{
  "alert": "checkout-errors",
  "function": "checkout",
  "trigger": "errors",
  "transition": "firing",      // or "resolved"
  "threshold": 5,
  "window": 300,
  "at": "<RFC 3339 timestamp>"
}