How your service runs
A project with an infra/runtime.json is a service: the platform runs it
in each environment that selects it. Each deploy starts a new revision of
the service, and the old revision serves until the new one is ready.
What makes a project a service
| The project has… | The platform… |
|---|---|
infra/runtime.json |
runs it as a service, with the routes, scaling and resources it declares |
a config schema and conf/env.<env>.yaml |
resolves its config for each environment |
| a migration bundle | runs its migrations before the new revision starts |
infra/requirements.json |
gives it the databases, buckets, event topics, secrets and scheduled jobs it declares |
A project without infra/runtime.json, such as a library, is built and
published, never run. The fields of each file are in
files.
What happens when a service deploys
Each service that changed deploys on its own, in this order:
- Prepare. The platform creates what the service needs and does not have yet: its identity, its database access, its buckets, its event topics and its routes. On later deploys, it updates only what changed.
- Pin the config. The platform resolves the config of this environment and pins it to the new revision.
- Copy the image. The platform copies the exact image digest you published into the registry your service runs from.
- Migrate. The platform runs the migrations of the release set. A revision never serves against a schema it was not built for.
- Start the new revision, and wait until it is ready and runs the expected image.
- Move the traffic. 100 % of requests go to the new revision. Then the platform starts the scheduled jobs and the event subscriptions.
If a step fails, the deploy of that service stops, and the old revision keeps
serving. The other services of the environment continue. The deploy ends
failed, and putnami cloud deploy status <cm_id> names the service and the
reason.
| It fails at… | What still runs | What stays done |
|---|---|---|
| a migration | the old revision | the migrations that ran before the failure; the platform retries a transient error up to 5 times |
| the start of the new revision | the old revision | the applied migrations |
Migrations already applied are not rolled back. Write each migration so the old revision still works against the new schema.
Scale to zero
Idle services scale to zero. The first request after an idle period starts an instance: it waits for that start, which is a cold start. There is no setting for a minimum number of instances.
You set the ceiling in infra/runtime.json:
{ "scaling": { "max": 2, "concurrency": 500 } }maxis the largest number of instances.concurrencyis the number of requests one instance takes before the platform starts another one.
A task that must continue after its HTTP response ends belongs in a job or a worker, not in a service.
Config and secrets
Config is data that the platform resolves, never baked into the image.
| You change… | It reaches the service… |
|---|---|
| a config value | at the next deploy: the platform pins config to each revision |
| a secret | when a new instance starts: secrets are never pinned, so a rotation needs no deploy; instances already running keep the old value |
| your code | at the next merge |
See config and secrets.
Routes and domains
A service answers on the hosts its ingress.domains declares. There is no
public default address. An internal service sets ingress.public to false.
The platform serves a host only when a certificate covers it and your
workspace holds the host. Hosts under putnami.cloud and putnami.dev are
covered. Certificates and DNS for your own domain are not self-service yet.
Bindings
A service that declares a database or a bucket gets a binding: the platform connects the service to the store at deploy. Your code connects to what it declared, and never holds a database password.
Guarantees
These hold in every environment:
- Each revision comes from one commit. A signal, a deploy and a revision name the commit they came from.
- A deploy is a function of versioned state. The release set and the environment definition decide it, never a manual step.
- Signals by default. Each service emits logs, metrics and traces in the same shape everywhere. See signals.
- Fail closed. A service accepts only the credentials it can verify.