DocsRunning your app
Volumes and SQLite
A volume is a disk that belongs to an app and keeps its data through sleep, deploys and server failures. Use one for uploads, a SQLite database, or anything else your app writes to files and must not lose.
Adding a volume
snapwake deploy . --volume data:/data:1024--volume NAME:/PATH:MB mounts a volume named NAME at /PATH, MB megabytes in size. Repeat the flag for more volumes. The volume is created on the first deploy that names it, empty, formatted as ext4, and mounted before your app starts.
| Rule | |
|---|---|
| Volumes per app | at most 4 |
| Size | 64 MB to 1 TB, within your plan's limit (Usage and limits) |
| Growing | deploy again with a larger size; the volume grows the next time the app starts |
| Shrinking | not possible |
| Path | absolute, not /, no .., commas or colons, at most 200 characters; each volume has its own path |
| Name | lowercase letters, digits and dashes; each volume has its own name |
A later deploy that doesn't mention a volume keeps it. A deploy that names an existing volume with a new size or path changes that volume and leaves the others alone.
Volumes can't be declared in snapwake.toml yet; use the flag.
SQLite
snapwake deploy . --sqlite /data/app.dbThis gives the app a 1 GB volume named db for the database's folder (unless it already has a volume there) and two variables:
SQLITE_PATH=/data/app.db
DATABASE_URL=sqlite:////data/app.dbSQLAlchemy and Django read that form of DATABASE_URL as it is. The database file must be in a folder of its own (/data/app.db, not /app.db).
For durability, open the database in WAL mode with full sync:
PRAGMA journal_mode = WAL;
PRAGMA synchronous = FULL;With synchronous = FULL, a transaction that returned is on both copies of the volume (see below) before your app answers. With NORMAL, the last transactions can be lost if a server fails, as on any disk.
How an app with a volume behaves
One VM at a time. Only one VM may write to a volume, so an app with volumes runs at most one VM. snapwake scale --max 2 is refused for such an app.
It sleeps with its state. When it goes to sleep, Snapwake pauses the VM, saves its memory and devices, and stops it. The next wake continues exactly where it stopped: same process, same memory, same files. Waking takes longer than for apps without volumes, about half a second on our development machine, because the whole saved state is loaded rather than a shared deploy snapshot.
Sometimes it starts fresh. If there is no saved state, the app boots from scratch with its volume: after a crash of the VM, after a server failure, and after every deploy. A fresh start runs your start command again; the filesystem outside your volumes starts from the image, and only the volumes keep what was written. Make sure your app opens its data on start and doesn't rely on anything else surviving.
Deploys pause it briefly. The old VM stops before the new version boots with the volume, so requests wait for the new version to start.
Two copies
Every volume has a live copy on the app's standby server. A write that your app flushes (fsync, a SQLite commit with synchronous = FULL) returns only after it is on disk on both servers. On our development setup this adds about 6 ms per flush.
If the standby server stops answering for 3 seconds, the volume continues with one copy, so your app doesn't stall. Snapwake's control service records that first; if it can't be reached either, flushes wait until one of the two answers. When the standby comes back, it catches up on the blocks that changed. While a volume runs on one copy, Snapwake does not move the app to another server.
When the home server fails
Apps with volumes do not switch to the standby as fast as apps without them, on purpose: a server that is merely unreachable could still be writing. Snapwake waits until the control service considers the home server gone (about 10 seconds), checks that the standby holds a current copy, fences the old server off so it can never write to the volume again, and then starts the app on the standby. In our failover tests the pause was about 14 seconds and no flushed write was lost.
Backups
Volumes are backed up to object storage, encrypted with your organization's key:
- a full copy at least every hour, taken while the app runs or right after it goes to sleep;
- a log of changed blocks, sent about every 10 seconds;
- the last 7 full copies are kept.
Together they let a volume be restored to any moment in that window, to the second. During the beta restores are done by us: write to support@snapwake.dev with the app, the volume and the time.
What volumes cost
$0.15 per GiB-month, for both copies together. A volume is counted by the space its data actually takes on disk, not by its declared size. See Usage, plans and limits.
Deleting
Deleting the app removes its volumes from service. They are never attached to another app, even one that later takes the same name.