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
Use managed databases for Postgres, Redis, MySQL, or MongoDB with generated credentials and an attached durable disk: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"
The filesystem requested when creating the disk. Its effect depends on the storage driver.
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
When a container starts, Beam reuses its disk on the same node or restores the latest snapshot on a new node. 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 follows snapshot publication. Changes since the last successfully published snapshot can be lost if the worker is lost. Inspect snapshot status and lifecycle errors.
- Size is fixed at creation. Declaring an existing disk with a different
sizereturns the existing disk unchanged. - 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, Redis, MySQL, and MongoDB 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.