ScalixScalix Docs
Sign up

Branching

Isolated database branches for development, testing, and CI/CD

Overview

Database branches create a full, isolated, writable copy of your database in seconds. Each branch is restored from the parent timeline's durable base backup plus archived WAL and served by its own compute worker, so nothing a branch does can affect the parent.

Create a Branch

Via the API:

bash
curl -X POST https://api.scalix.world/api/v1/tenants/$TENANT_ID/timelines/$TIMELINE_ID/branch \
  -H "Authorization: Bearer $SCALIX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'

The request body accepts two optional fields:

FieldDescription
branch_lsnLSN to branch at. Omit (or pass 0) to branch at the latest data.
new_timeline_idExplicit id for the new branch timeline. Omit to have one generated.

Response (201 Created):

json
{
  "timeline_id": "b7e2c9d0-1f34-4a56-9c78-0d12e3f45a67",
  "parent_timeline_id": "00000000-0000-0000-0000-000000000001",
  "branch_lsn": 0,
  "endpoint": {
    "host": "api.scalix.world",
    "port": 5432,
    "database": "db_b7e2c9d0-1f34-4a56-9c78-0d12e3f45a67"
  },
  "status": "ready"
}

The branch is restored from the parent timeline's durable base backup plus archived WAL, replayed to the branch LSN, and served by its own compute worker. Your API key must belong to the tenant in the URL.

Connecting to a branch

Two selectors route a query to the branch's worker instead of the primary:

  • Wire protocol (psql, any Postgres client): connect with an API key as the password and endpoint.database from the response as the database name — db_<branch timeline UUID>:

    text
    postgresql://t_a1b2c3d4e5f6:YOUR_API_KEY@api.scalix.world:5432/db_b7e2c9d0-1f34-4a56-9c78-0d12e3f45a67?sslmode=require
  • HTTP / MCP: pass timeline_id (the branch UUID, with or without the db_ prefix) in the POST /api/v1/sql body — or the timeline_id argument of scalix_db_query. Omitting the selector targets the primary.

Two facts that trip up verification:

  • current_database() is NOT the branch selector. A branch is a physical restore served by its own worker, not a CREATE DATABASE — the session database name is the project's db_… name on the primary and on every branch. Verify you are on the branch by its data (or by the timeline your selector named), never by current_database().
  • Name routing fails closed. A database name that does not resolve inside your project is rejected (wire: SQLSTATE 3D000; HTTP: 400) — it never silently serves the primary.

Branch lifetime

While a branch is actively used, its worker and routing stay attached. After a period of inactivity (currently 15 minutes) the attachment expires: the worker is reclaimed and name-based routing stops resolving, so abandoned branches can't exhaust your compute pool. The branch's durable data is not deleted — it survives until you DELETE the branch. Re-attaching an expired branch automatically on first use is in progress; until it ships, an expired branch must be re-attached by support. Do not "recreate" an expired branch by POSTing the same new_timeline_id again — that rebuilds from the parent at the original branch point and does not bring back the branch's own writes.

Passing a specific branch_lsn gives you a branch at a historical point: this is the same mechanism behind point-in-time recovery.

Delete a Branch

bash
curl -X DELETE https://api.scalix.world/api/v1/tenants/$TENANT_ID/timelines/$BRANCH_TIMELINE_ID \
  -H "Authorization: Bearer $SCALIX_API_KEY"

Deleting releases the branch's compute worker and permanently removes the branch's durable data. Its base backups and archived WAL are purged from storage. The response reports the reclaimed object count:

json
{ "deleted": true, "purged_objects": 7 }

Deletion is idempotent and cannot be undone. The main timeline cannot be deleted through this endpoint (400): it is the database itself.

Branches that are neither queried nor deleted expire out of live routing after an idle period (see Branch lifetime above) — the durable data stays until you delete the branch.

How It Works

Each branch is an independent timeline:

  1. Creating a branch restores the parent's durable base backup and replays archived WAL up to the branch point
  2. The branch gets its own compute worker and its own backup cycle
  3. Writes on the branch never touch the parent. The two timelines are fully isolated from the moment the branch is created
  4. Connections that name the branch — the wire database name db_<branch timeline UUID>, or the HTTP/MCP timeline_id selector — are routed to its worker by the gateway while the branch is attached