# The platform

This page says what runs under an app on durablesdk.com, which of it
the engine binds, and what it never counts on. Nothing here is a
setting of yours: every promise below is the platform's, bound in
`durable.config.ts` by the template, and every limit is a number the
engine already keeps.

## The compute model

An app's functions run on a compute model where one instance serves
many invocations at once and scales to zero between them. Three things
follow, and the engine binds each:

- **The deadline.** Every invocation has a deadline the runtime states
  (`getDeadline()`); the engine reads it first and the pinned limit
  second, and parks a run before it (`functionDeadlineAt`,
  [time and waits](https://durablesdk.com/docs/guide/time-and-waits.md)). A step that would outlive the function is
  resumed by the next invocation, not killed mid-write.
- **The hold.** Work handed to the platform after the answer
  (`waitUntil`) keeps the invocation alive: the inline drain, the
  observers' hooks and the pool's idle client all ride it, so nothing
  is cut at the response.
- **The stop.** An instance is told 500 ms before it is scaled down
  (`SIGTERM`). `installShutdown()` runs your hooks together under a
  400 ms grace and `attachPool` ends the pool in it; an attempt in
  flight is the lease's, never a hook's concern: another instance claims
  it when the lease lapses.

An uncaught exception is isolated to its request. Bytecode caching is
production's alone, so a preview's first invocation is colder.

## The tick

The scheduled tick (`/jobs/dispatch`, every minute) runs on the
production deployment alone. A preview has no cron: it ticks on a
request (`tick: request-only`), so a timer parked on a preview resumes
at its next request, and a schedule under a minute is refused at the
definition door. Timers run at minute precision on every environment
(no queue: a delayed wake is the cron minute's).

## The body

A request or answer body is at most 4.5 MB. The upload is in parts of
4 MiB for that reason ([deploy](https://durablesdk.com/docs/hosting/deploy.md)), the operator
API's answers are bounded at 4 MB, and a door of yours that takes a
larger body answers 413 before your code runs.

## The firewall and failover

Every app sits behind the platform's DDoS mitigation at no cost;
blocked traffic is never billed. A firewall baseline per app project
(exploit probes denied, the operator API rate-limited by address) is
coming (DS-041). Failover across availability zones and regions is the
platform's and needs nothing of the engine: an app runs in one region,
next to its database ([regions](https://durablesdk.com/docs/hosting/regions.md)).

## The metrics

The engine's five boundaries are the platform's custom metrics,
emitted by the platform adapter's metrics observer, bound in
`durable.config.ts` by the template, and tagged by the
registries' words alone (a workflow's name, a fact's name, a
listener's name, the outcome, the effect), never an id:

| Metric                    | Value                                           | Tags                            |
| ------------------------- | ----------------------------------------------- | ------------------------------- |
| `durable.run.started`     | count per key in one invocation (1 outside one) | `workflow`, `outcome`           |
| `durable.run.finished`    | count per key in one invocation (1 outside one) | `workflow`, `outcome`           |
| `durable.run.duration_ms` | ms                                              | `workflow`, `outcome`           |
| `durable.step.landed`     | count per key in one invocation (1 outside one) | `workflow`, `outcome`, `effect` |
| `durable.fact.emitted`    | count per key in one invocation (1 outside one) | `event`                         |
| `durable.fact.delivered`  | count per key in one invocation (1 outside one) | `listener`, `outcome`           |
| `durable.metrics.dropped` | how many an invocation's flush cut, by `kind`   | `kind` (`points`, `keys`)       |

Inside an invocation (a tick, a door) the counts are kept per key and
emitted once at its end, so read a counter with `-a sum`, never
`-a count` or `-a avg`. The platform admits a hundred calls an
invocation: the duration points are cut first so every key fits, then
the keys, and a cut is said by `durable.metrics.dropped`, so keep the
names times their tags' cardinality (the workflows times the outcomes
times the effects) under a hundred.

The same counters are the console's ([console](https://durablesdk.com/docs/operate/console.md))
and the MCP's, read off the app's own operator API, so you need no seat
on the platform to read them.

## The kill switches

Three switches are the platform's operator's, never yours, each a
refusal with its own code:

| Switch        | What closes                                                    | The answer                             |
| ------------- | -------------------------------------------------------------- | -------------------------------------- |
| `maintenance` | every path of durablesdk.com but the health probe and the tick | 503 `plane.maintenance`, `Retry-After` |
| `deploys`     | `POST /apps`, `POST /apps/:slug/deployments`                   | 503 `plane.deploys_paused`             |
| `signups`     | the sign-up screen                                             | 503 `plane.signups_paused`             |

A switch closes the plane's doors, never your app's: a deployed app
keeps running and ticking under every switch. A switch the operator
flips lands within a minute: the plane re-reads the store every thirty
seconds, and a fresh instance reads it on its first request.

## The log stream

`durable-sdk logs --follow` reads a `text/event-stream` the plane holds
open for up to five minutes (an `open` event naming the deployment, one
`data:` event per line, a heartbeat comment every fifteen seconds,
`event: end` at the window) and asks again; the stream's route is the
one place request cancellation is on, so a client that left stops the
read at once ([logs](https://durablesdk.com/docs/hosting/logs.md)).

## The deployment's id

The HTML durablesdk.com serves carries its deployment's id on the
`<html>` element (`data-dpl-id`), so a tab open across a release keeps
fetching its own page's assets, never the new build's. It is the one
provider-shaped token the site shows, kept rather than masked: it names
nothing of yours.

## What the engine never assumes

- A cron on a preview deployment.
- State in a process: an instance serves many invocations and scales to
  zero; a memo is a hint, the database the record.
- A second region: one per app, next to its database.
- A body over 4.5 MB.
- An error page of its own for a platform fault: a timeout or a crash
  renders the platform's page, and a reader of it may see the
  platform's name there and in the response headers, the one place a
  provider shows ([security](https://durablesdk.com/docs/operate/security.md)).

---

Prompt for an agent:

```text
Read https://durablesdk.com/docs/hosting/platform.md, then know what the platform promises a hosted app and what it does not; run durable-sdk doctor --host before and after; a refused line is a refusal id: durable-sdk explain <id>
```
