Autoscaling services

A service runs your HTTP app on as many replicas as its traffic needs: none while nobody is using it, more as requests arrive. You pay for replicas only while they run, by the second.

svl service deploy web ghcr.io/me/app:latest --http 8080
Deployed web (revision 1) → https://web-acme.svl.blah.au
Scales 0–3 replicas at 20 requests in flight each; up to A$0.1485/hr at max.

The service gets an HTTPS address like a pod with --http does, and your own domains work the same way. Replicas are ordinary pods named web-xxxx: svl ls lists them with their service.

How it scales

serverless.au counts the requests in flight to each service, every second, at the HTTPS edge.

  • Concurrency (--concurrency, default 20) is how many requests in flight one replica should handle. With 75 in flight and a concurrency of 20, the service runs 4 replicas.
  • Scaling up happens within seconds of a burst.
  • Scaling down follows the last minute's average, one replica at a time. A replica leaving stops taking new requests first, and gets up to 30 seconds to finish the ones it has.
  • Limits: --min (default 0) replicas always run, and the service never goes above --max (default 3). Your account can run at most 20 replicas across all its services; ask support to raise it.
svl service scale web --min 1 --max 10 --concurrency 50

Scale to zero and cold starts

With --min 0, a service with no requests for --idle (default 15 minutes) stops its last replica. The next request starts one.

That first request waits while the replica starts: it isn't turned away. Once the replica passes its health check, the request (and any that arrived meanwhile) goes through. Once a server has your image, a replica usually starts and serves in about a second, plus however long your app takes to boot. The first start on a server after a deploy also pulls the image. If no replica is ready within --cold-timeout (default 60 seconds), waiting requests get a 503 with Retry-After: 5, and we email you.

To never wait, keep one replica running: svl service scale web --min 1.

Spreading replicas

  • --spread prefer (default): replicas go on different servers when there's room.
  • --spread host: never two replicas on the same server. If no server has room, a new one is started for it (this takes a few minutes).
  • --spread none: replicas may share a server.

CPU burst

Every pod, replicas included, may use spare CPU above its shape when the server has it: svl shapes shows how far each shape bursts. Your shape's vCPU is what you're guaranteed and billed for; burst is extra, and never billed.

Deploying a new version

Run svl service deploy again with a new image, command, environment or shape, and it rolls out a new revision:

  1. A replica of the new revision starts.
  2. When it passes its health check, it takes traffic and an old replica leaves.
  3. Repeat until no old replicas are left.

svl service deploy follows along until it's done; -d returns straight away. Deploying the same template again only changes the scaling settings.

If the new revision keeps crashing or doesn't pass its health check within 3 minutes, the rollout stops and the previous revision keeps serving. We email you. Deploy a fix, or go back for good:

svl service rollback web

A service with a volume must have --max 1 (a volume attaches to one pod), and rolls out by replacing its replica, so it's briefly unavailable.

Watching a service

svl service ls
svl service show web      # settings, replicas and where they run, load now, recent events
svl service logs web -f   # every replica's logs, each line marked with the replica

Health checks

Replicas take traffic only once healthy, using the same checks as HTTPS routes: GET /health by default (anything below 500 is healthy), or --health-path /healthz to require a 2xx. A starting replica is checked every quarter-second, so it serves the moment it's up.

Billing

Each replica is billed at its shape's price while it runs, including the seconds it spends finishing requests on its way out. A service at zero replicas costs nothing, and the time a request waits for a cold start isn't billed.

If your account runs out of credit, the service is suspended: its replicas stop and its address shows an "out of credit" page. Add credit and it starts again on the next request.

Removing a service

svl service rm web

Its replicas stop once their requests finish, and its address and domains are removed.

Today's limits

  • Services are for HTTP apps. Other protocols and background workers run as pods.
  • Scaling follows requests in flight, not CPU.
  • A service runs in one region.