Choosing Between Storage Types
Attaching a Disk
Declare aDurableDisk with a name, a size, and the path where it should appear inside the container, then pass it to your app with the disks parameter.
disks parameter is accepted by Pod, function, endpoint, task_queue, and Sandbox.
If a disk with that name does not exist in your workspace yet, Beam creates it the first time you run or deploy the app. You can also create disks ahead of time from the CLI.
Running a Database on a Disk
Disks are a natural fit forPod, which can run any container image as a long-lived service. This example runs Redis with its append-only file stored on a durable disk:
/data directory the previous one wrote to.
Parameters
string
required
The name of the disk. Names are unique within your workspace, so two apps that declare the same name share the same disk.
string
required
The declared size of the disk, for example
"10Gi" or "500Mi". The size is recorded on the disk and shown in the CLI; it is not changed by redeclaring the disk with a different value.string
required
The absolute path where the disk is mounted inside the container. A disk without a mount path is not attached.
string
default:"ext4"
Recorded on the disk for reference.
boolean
default:"False"
Mount the disk read-only. Read-only disks can be attached to any number of containers at once. See Read-Only Disks.
Snapshots
Beam snapshots a disk to object storage each time the container using it stops. Only data that changed since the previous snapshot is uploaded. Snapshots are not taken on a timer: while a container is running, its writes live on the node’s local disk, and changes made since the container last stopped are not yet in a snapshot. When a container starts, Beam reuses the disk’s local copy if the container lands on the node that ran it last, and otherwise restores the latest snapshot onto the new node. For a large disk the restore is the slower path, so long-running services withkeep_warm_seconds=-1 avoid it entirely.
You can list the snapshots of a disk with the CLI:
- Generation is a timestamp assigned when the snapshot is taken. The highest generation is the most recent snapshot and is the one used for restores.
- Logical Size is the total size of the files in the snapshot. Stored Size is the size of the object storage chunks the snapshot references.
- Format describes how the directory was captured.
dir.v1is the general format. Beam’s managed databases usepostgres.wal.v1andredis.aof.v1, which recognize Postgres write-ahead log segments and Redis append-only files: when one of those files has grown since the last snapshot, only the newly appended tail is uploaded.
Read-Only Disks
Only one container can have a writable mount of a given disk at a time. Deploying an app that mounts a writable disk with an autoscaler that allows more than one container is rejected:read_only=True to mount a disk without write access. Read-only mounts are exempt from the single-writer rule, so you can attach the same disk to a horizontally scaled endpoint. A typical pattern is one writer that prepares data, such as a nightly job that builds an index, and many readers that serve it:
Limits and Caveats
- One writer. A writable disk can be mounted by one container at a time. Scale-out requires
read_only=True. - Durability is per container lifetime. Data is copied to object storage when the container stops. Changes made during a run are on the node’s local disk until then.
- Size is fixed at creation. Declaring an existing disk with a different
sizereturns the existing disk unchanged. The size is not enforced as a quota, anddfinside the container reports the capacity of the node rather than the declared size. - Deleting is soft.
beam disk deleteremoves the disk from your workspace but leaves its snapshots in place. Apps that still reference the name will recreate the disk record and, on their next start, restore from the latest snapshot. - Mount path is required. A
DurableDiskwithout amount_pathis ignored. - Leave the marker file alone. Every disk contains a small
.beta9-durable-diskfile at its root that Beam uses to track snapshot state.
Managed Databases
Beam’s managed Postgres and Redis services are built on durable disks.beam db postgres create <name> deploys a Postgres container with a <name>-data disk mounted at /var/lib/postgresql/data, and beam db redis create <name> does the same with a disk at /data. The disks show up in beam disk list alongside any you create yourself.
CLI Management Commands
List Disks
--format json to get the full record, including the disk id and driver.
Create a Disk
--size defaults to 10Gi. --mount-path sets the disk’s default mount path, which is shown in beam disk list; the mount_path you set in code is what determines where the disk is mounted. If a disk with that name already exists, the command returns it unchanged.
List Snapshots
Delete a Disk
-y to skip the confirmation.