Skip to main content

Hosting on a Platform

Many teams already have a platform that runs Python web apps, such as Databricks Apps or a container service, with authentication handled for them. A Catchment is an ASGI web app, so it can be deployed there like any other. This guide covers the setup, and how to keep the Catchment's state across redeploys, which such platforms don't always preserve.

The bundle​

A deployable Catchment is two files:

# app.py
from duckstring.catchment.asgi import app
# requirements.txt
duckstring

Ponds that declare their own Python dependencies get an environment built for them under the state directory. Ponds that don't run in the app's environment, so add any packages their Ripples import to requirements.txt. Deploy the bundle as an ASGI (FastAPI) app, using the platform's usual method.

Configure the Catchment with environment variables in the platform's settings:

VariablePurpose
DUCKSTRING_STATE_ROOTWhere state is kept. Defaults to ./.duckstring, inside the bundle directory.
DUCKSTRING_DATA_ROOTWhere published tables are stored. Use object storage on a platform; see below.
DUCKSTRING_STATE_BACKUP_URIWhere to copy state continuously, for platforms whose disk doesn't survive a redeploy.
DUCKSTRING_API_KEYOnly if the platform doesn't authenticate requests itself.

See Environment Variables for the rest.

Run exactly one process of the app. The Catchment keeps its scheduler and database in one process, and a second copy would compete with it. If the platform can stop an app that has had no requests for a while, keep one process running at all times, since the Catchment schedules work between requests.

The web UI works from whatever path the platform serves the app at, including one below the platform's own address, such as /content/{id}/.

Authentication​

Let the platform control access, and leave DUCKSTRING_API_KEY unset. The web UI uses the platform's login session. For the CLI, register the Catchment with whatever header the platform expects, such as an API key the platform issues:

duckstring catchment connect --name prod \
--path https://apps.example.com/content/1a2b3c4d/ \
--header "Authorization: Bearer $PLATFORM_TOKEN" --yes

If the platform's tokens expire, use --header-command with a command that prints a fresh one; see catchment connect.

Everyone the platform lets through gets full access to the Catchment, so restrict who can reach the app in the platform's access settings.

Ducks talk to the Catchment inside the app's own machine, on its local address, so they don't go through the platform's authentication.

Keeping state​

A Catchment's state directory holds its database, deployed Ponds, run history and configuration. The default, ./.duckstring, sits in the app's directory, which survives restarts but is usually replaced when you redeploy the app itself, for example to upgrade Duckstring. There are two ways to keep it.

Carry it in the bundle. Before redeploying, download the state into the bundle directory. The download's default location is exactly where the app looks:

cd catchment-bundle
duckstring catchment download -c prod # writes ./.duckstring
# deploy the bundle as usual

Download while no runs are in progress. Secrets aren't included, so set them again after redeploying. An App's state is included only if the App declares how to write it, with [app] download.

Back it up continuously. Set DUCKSTRING_STATE_BACKUP_URI to an object-store location. The Catchment copies its database there every minute (DUCKSTRING_CHECKPOINT_INTERVAL), and its full state when it shuts down cleanly. A Catchment starting with an empty state directory restores from it automatically. This suits platforms with no persistent disk, such as scale-to-zero containers.

Apps' Records and Media need care on a platform. The Catchment's own PostgreSQL needs the server installed in the app's environment, and between full-state copies its data lives only on the app's disk. Point Records at a PostgreSQL database you run or the platform provides, with catchment records --use, and Media at object storage with catchment media --use, before any App keeps data.

Keeping data​

Published tables are stored under the state directory by default, which makes them part of every download. On a platform, point DUCKSTRING_DATA_ROOT at object storage instead:

DUCKSTRING_DATA_ROOT=s3://acme-lake/duckstring?region=eu-west-2

Tables then persist independently of the app, downloads stay small, and cloud compute becomes available on that cloud (see Cloud Compute on AWS, Azure or Google Cloud). Credentials come from the platform's cloud setup or from ${env:NAME} references in the URI. Google Cloud Storage and Azure work the same way; see Data root URIs.

A data root must belong to one Catchment. A Catchment that finds another live Catchment using its data root refuses to start. If you're sure the other one is gone, for example an old deployment that wasn't shut down cleanly, set DUCKSTRING_FORCE_TAKEOVER=1 once to claim it.

BI tools and SQL clients​

The platform serves the Catchment at one HTTP address, and the web UI, the CLI, the HTTP API, Apps and duckstring query all work through it. The Postgres and Arrow Flight endpoints don't, because they aren't HTTP and each needs a port of its own.

To give BI tools the data, deliver the tables they need with a Spout to a database they already connect to, such as Postgres, and connect them there. The database is updated shortly after each run publishes. For BI tools to query the Catchment directly, run it where you can open the ports, as in Running on a Server.

Databricks Apps​

On Databricks, a Catchment runs as a custom App: a short start script runs it on the App's port, Databricks' sign-in guards it, and its data root and state backup go on a Unity Catalog Volume, which survives the App's compute restarting. Running on Databricks covers the setup and the access to grant the App's service principal.