Skip to main content
Reference vendor/dbos 2 min read

advanced-versioning


title: Use Versioning for Blue-Green Deployments impact: LOW impactDescription: Safely deploy new code with version tagging tags: versioning, blue-green, deployment, recovery

Use Versioning for Blue-Green Deployments

DBOS versions workflows to prevent unsafe recovery. Use blue-green deployments to safely upgrade.

Incorrect (deploying breaking changes without versioning):

# Deploying new code directly kills in-progress workflows
# because their checkpoints don't match the new code

# Old code
@DBOS.workflow()
def workflow():
    step_a()
    step_b()

# New code replaces old immediately - breaks recovery!
@DBOS.workflow()
def workflow():
    step_a()
    step_c()  # Changed step - old workflows can't recover

Correct (using versioning with blue-green deployment):

# Set explicit version in config
config: DBOSConfig = {
    "name": "my-app",
    "application_version": "2.0.0",  # New version
}
DBOS(config=config)

Deploy new version alongside old version. Direct new traffic to v2.0.0, drain old workflows on v1.0.0.

When upgrading the DBOS library from 2.x to 3.0, also change application_version: 2.x processes cannot process workflows created by 3.0 (see advanced-upgrading-v3).

Directing Enqueued Workflows to Latest Version

Use DBOS.get_latest_application_version to route enqueued work to the latest version:

from dbos import DBOS, SetEnqueueOptions

# After DBOS.launch()
DBOS.register_queue("my_queue")

latest_version = DBOS.get_latest_application_version()
with SetEnqueueOptions(app_version=latest_version["version_name"]):
    DBOS.enqueue_workflow("my_queue", my_workflow, arg1, arg2)

Scheduled workflows are automatically enqueued to their owning application’s latest version. Workflows enqueued without an app_version (e.g. from DBOSClient) are only dequeued by executors running the latest version.

Versions are tracked per application: list_application_versions and get_latest_application_version return only this application’s versions (plus unowned ones), and each VersionInfo has an application_name. set_latest_application_version acts as this application (override with application_name=); promoting a version registered by a different application raises an error.

Checking and Retiring Old Versions

active = DBOS.list_workflows(
    app_version="1.0.0",
    status=["ENQUEUED", "DELAYED", "PENDING"],
)
if not active:
    print("Safe to retire version 1.0.0")

To skip the drain, patch every breaking change and enable auto-upgrade (3.4+, DBOS Transact Enterprise): DBOS then moves workflows left on older versions to the latest version (see advanced-patching).

Reading the Current Version

# Read the version this process is running as
print(DBOS.application_version)

Version Management APIs

# List all registered versions (newest first)
versions = DBOS.list_application_versions()

# Get the latest version
latest = DBOS.get_latest_application_version()

# Roll back: promote a previous version to latest
DBOS.set_latest_application_version("1.0.0")

Each VersionInfo is a dict with:

class VersionInfo(TypedDict):
    version_id: str           # Unique ID
    version_name: str         # Unique name (matches the application_version config field)
    version_timestamp: int    # Epoch ms - determines which version is "latest"
    created_at: int           # Epoch ms when first registered
    application_name: Optional[str]  # Owning application

Forking Workflows to a New Version

new_handle = DBOS.fork_workflow(
    workflow_id="old-workflow-id",
    start_step=5,
    application_version="2.0.0"
)

Reference: Versioning