DocsStart here
How Snapwake works
The short version
Each app runs in its own small virtual machine (a Firecracker microVM). When you deploy, Snapwake builds your app, starts it, sends it a few warm-up requests and then takes a snapshot: a saved copy of the running VM, memory included. When the app has had no traffic for a while it goes to sleep: the VM is stopped and nothing is running. The next request restores the VM from the snapshot. On our test hardware that takes 12 to 25 ms for Node.js and Python apps, so the first visitor sees a slightly slower response, not a cold start.
Because a sleeping app has no VM, it uses no memory and no CPU, and you are not billed for it.
Terms
Organization. Apps, secrets and usage belong to an organization. During the beta every account gets one organization, named after your GitHub login.
App. One service with one name, for example shop. The name gives the app its address: https://shop.snapwake.app. App names use lowercase letters, digits and dashes, start and end with a letter or digit, and are at most 40 characters long. Names are global, so pick something specific.
Process. What runs inside the app's VMs. An app has exactly one process, of one of these kinds:
| Kind | What it is | What wakes it |
|---|---|---|
web |
an HTTP server listening on a port | an HTTP request to the app's URL or to <app>.internal |
worker |
a background process with no HTTP | a job in its Redis queue, or nothing (an always-on worker) |
If your project has a web server and a worker, deploy them as two apps from the same source, for example shop and shop-worker. See Background workers.
Version. Every deploy creates a new version with an id like v1764158400123. A version is built once, and Snapwake keeps the previous one so a rollback is instant. See Versions and rollbacks.
VM (instance). A running copy of the app. By default an app runs at most one VM and none while it sleeps. You can let it run more under load, or keep some awake at all times. See Scaling and health checks.
Home server and standby server. Each app is placed on a home server, which builds it and serves it. A second server in the same region keeps a standby copy of the current version. If the home server stops answering, requests go to the standby, which wakes the app from its copy. For apps without volumes this usually takes well under a second and requests that had not reached the app yet are not lost.
What sleep keeps and what it doesn't
This is the one thing that behaves differently from a server that runs all the time, so it is worth reading carefully.
Apps without volumes wake from the snapshot taken at deploy time, every time. That snapshot holds the app after it started and answered its warm-up requests: loaded code, JIT-compiled functions, caches it filled while starting, open files. Whatever the app changed after that is gone when it goes to sleep:
- data it kept in memory (sessions, in-process caches, counters);
- files it wrote to its own filesystem (the filesystem is a writable layer in memory on top of the image);
- open connections to databases and other services (they are closed before sleep and on wake the app reconnects, the way it would after a network blip).
Keep anything that must survive in a database, in Redis, in object storage, or on a volume.
Apps with a volume sleep with their state. On sleep Snapwake saves the whole VM, memory and disk together, and the next wake continues from there. Waking such an app takes longer (about half a second on our development machine), and an app with a volume runs one VM at a time.
What Snapwake fixes on every wake
A restored VM wakes up believing it is still the moment the snapshot was taken. Before your app sees the request that woke it, Snapwake:
- sets the clock to the current time;
- gives the kernel fresh randomness, so two wakes of the same snapshot never produce the same random bytes;
- reseeds the random number generators inside Node.js (
Math.random, OpenSSL,crypto.randomUUID) and Python (random, OpenSSL); - gives the VM a new network address and closes connections that belonged to the old one;
- delivers your current secrets to
/run/flare/secrets.env; - runs your wake hooks, if you registered any (see Runtime helpers).
Details, and what other runtimes need from you, are in Sleep and wake.
Where your code runs and who can reach it
- Each VM has its own kernel. VMs of different organizations never share a VM process, and the platform keeps different organizations off the two hardware threads of one CPU core at the same time.
- Your build runs in a throwaway VM, never on the server itself.
- Snapshots, secrets and stored versions are encrypted with a key that belongs to your organization.
- Requests from the internet reach your app only through Cloudflare and our edge proxy. VMs have no public address, cannot reach each other directly, and cannot reach the servers they run on.
What doesn't run on Snapwake
GPU workloads, Windows containers, privileged containers and Docker-in-Docker. Inbound traffic is HTTP only for now: a database image will deploy and wake, but clients outside Snapwake can't connect to it over TCP yet.