Distributed mode
The collapsed CLI (urutau run) puts the reader, the worker, and the sink
writer in one process. That is enough for a laptop, but it means one
process owns every table's throughput, and a crash stops everything.
Distributed mode splits the same engine in two:
urutau-coordinator— connects to the source, runs the DBLog snapshot, partitions each table's key range, routes rows to workers over Arrow Flight, commits staged Iceberg cycles, and supervises worker health.urutau-worker— connects to the coordinator, receives an assignment (table, key range, source DSN), and owns the writes to the sink for that partition.
This is the engine Kubernetes automates; if you are on a cluster, read Deploy on Kubernetes instead — the coordinator and workers are the same, just scheduled for you.
How workers are assigned
The coordinator decides the worker count and names; a worker never chooses
its own work. For a table with workers: {number: N}, the coordinator
splits the primary-key range into N contiguous ranges and derives the
group names <pipeline>-<target>-<index>. It waits for exactly those
--names to connect (up to --wait-worker), then hands each its range.
A worker started with an unexpected --name, or one that never connects,
is a startup failure, not a silent degradation: the coordinator waits
--wait-worker and then fails.
Running it by hand
Use the same spec you would give urutau run, with workers: {number: N}
on the tables you want to parallelize.
# Terminal 1 — the coordinator
./bin/urutau-coordinator run -f pipeline.yaml --listen :50051
# Terminal 2..N+1 — one worker per derived name
./bin/urutau-worker run \
--coordinator localhost:50051 \
--name orders-0 \
--catalog-uri http://localhost:8181/api/catalog \
--client-id root --client-secret s3cr3t
The worker names must be exactly the derived ones the coordinator expects.
For a table raw.orders in pipeline orders with number: 3, they are
orders-raw.orders-0, orders-raw.orders-1, orders-raw.orders-2.
The catalog settings (--catalog-uri, --client-id, …) can also come
from URUTAU_SINK_URI, URUTAU_SINK_CLIENT_ID, and friends — see the
CLI reference.
Secure the control plane
The Flight assignment carries the source DSN, credentials included. Run
the control plane under mTLS: give the coordinator
--tls-cert/--tls-key/--tls-ca and every worker the matching client
flags. With no TLS flags the coordinator refuses to boot — it will not
send the DSN in the clear by omission. To accept plaintext explicitly (e.g. a
trusted network), pass --allow-insecure-control-plane, which downgrades the
failure to a startup warning:
WARN coordinator: control plane is PLAINTEXT — the Assignment carries the source DSN; set TLS cert/key/CA (running because --allow-insecure-control-plane was set)
A minimal CA plus a server certificate for the coordinator and a client certificate for each worker:
# CA
openssl req -x509 -newkey rsa:4096 -days 365 -nodes \
-keyout ca.key -out ca.crt -subj "/CN=urutau-ca"
# Coordinator server cert — the SAN must match how workers dial it
openssl req -newkey rsa:4096 -nodes -keyout server.key -out server.csr \
-subj "/CN=urutau-coordinator"
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
-days 365 -out server.crt \
-extfile <(printf "subjectAltName=DNS:urutau-coordinator,DNS:localhost,IP:127.0.0.1")
# Worker client cert
openssl req -newkey rsa:4096 -nodes -keyout client.key -out client.csr \
-subj "/CN=urutau-worker"
openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
-days 365 -out client.crt
urutau-coordinator run -f pipeline.yaml \
--tls-cert server.crt --tls-key server.key --tls-ca ca.crt
urutau-worker run --coordinator urutau-coordinator:50051 \
--tls-cert client.crt --tls-key client.key --tls-ca ca.crt
Source credentials and files on workers
The worker owns the snapshot chunk SELECT, so the coordinator sends it a
source DSN — credentials included. Two consequences for a structured
source.postgres block:
- TLS material is sent as paths, not contents. The DSN carries
sslrootcert/sslcert/sslkey(fromssl.ca/ssl.cert/ssl.key), so every worker must mount those files at the same paths as the coordinator. Otherwise the assignment validates but the snapshot connection fails. Mount them from the same Secret/volume on both. - SSH tunnels are not supported in distributed mode. A DSN cannot carry
the tunnel, and the worker would connect directly to the database. Set
source.snapshotUrito a directly reachable read-only URI (or use the collapsed runner). The coordinator rejects the combination otherwise.
Supervision and resets
A worker that dies or stops acking is recovered, and the job keeps running.
A lost worker (Pod killed, OOM-killed, stream cut) is awaited: its Pod
comes back under the same name, reconnects under a new epoch, and the
coordinator redelivers what it owed — its sent-but-unacked batches, then its
queue. Its open staged cycles stay open until its redelivered stages
complete them. A worker silent for --ack-timeout (30s) while it owes work
is reset and recovered the same way. A reply from the lost session
carries the old epoch and is ignored.
During a snapshot, a lost worker's chunk windows die with it. Once it is
back, its partition redoes the chunks whose Closes marker it had not
committed, under fresh window ids, so a lost window's marker redelivered to
it closes nothing it has open. A restarted coordinator resumes each table's
snapshot from the progress its windows committed (cdc.snapshot.pending)
when the partition ranges are unchanged, and starts it over otherwise.
The job ends only for what does not heal by itself: an error the worker
reports, the same worker crashing --max-consecutive-crashes (3) times
in a row without delivering what it owed (a lost network or a replaced Pod
is not a crash), a worker owing work that delivers none of it for
--worker-delivery-timeout (5m), or a stalled worker with unacked batches
on an append table. See Reliability.
Resets are safe because the position lives in the sink, not in the worker: a resumed partition reads its last committed position back from the sink and continues. See State & position.
Concurrent writers
Parallelizing a table means several writers committing to it. Both built-in sinks support this, with different mechanisms:
- Iceberg: workers stage data files without committing; the coordinator commits one cycle's staged files as a single unit — one committer, one position write, no race.
- ClickHouse: workers commit independently, but the durable position is kept per partition and read back as the minimum safe value.
A sink that does not support concurrent writers rejects
workers: {number: N > 1} at boot with an error naming the table.
Operator
has the details.
Runtime scaling
A running coordinator can re-slice a table across a different number of
workers — adding or removing owners and swapping the routing snapshot
atomically, with no coordinator restart. The coordinator's ScaleTable does
the re-slice; under Kubernetes, KEDA drives it from the per-table backlog
metric (see Autoscaling with KEDA).
The sequence is prepare → commit, and every wait is bounded: a step that cannot complete fails the scale and leaves the old layout in place, so a scale is a retryable no-op rather than an incident — never an unbounded pause, never data loss.
- Prepare — register any new owner (so its Hello is accepted the moment its pod starts), then pause the table's input at the coordinator's pump. The flip requires the table to owe nothing (no in-flight batch, no open staged cycle), and a continuously loaded table never reaches that on its own; pausing the input lets the queue drain, which is what makes the barrier converge under load. The paused table's new batches are buffered, not routed and not counted by the drain.
- Commit — swap the routing snapshot atomically, then resume the input. A reader that loaded the old snapshot keeps routing a whole batch by it, so a batch is never split across two layouts. The batches buffered during the pause are flushed, in order, under the new layout, so a batch still never spans the flip.
- Retire (scale-in only) — each removed owner drains, then is detached.
A prepare step that times out — the table never drains, a commit never lands — resumes the input and returns with the old layout intact. The scaler retries, and worker recovery stays the supervisor's job: a worker that stalls owing work is reset and redelivered what it owed.
Pausing one table does not stall the others. The pump buffers the paused table's batches instead of parking on them, and keeps routing every other table's batches through the shared reader channel. The drain is bounded either way, so the held backlog is too.
The commit mode travels per batch (BatchMeta.staged), decided by the
coordinator at send time, not frozen in the worker's assignment. That is what
makes a table that becomes partitioned under a running worker safe: the
surviving owner, which attached when the table was unpartitioned, stages the
batches the coordinator now marks staged instead of committing them directly —
a direct commit would leave its staged cycle open and block every cycle
behind it in the table's send order.
A table's workers.max caps how far it may scale up; it never blocks a
scale-down. A table that sets it ignores the coordinator's default (32).
Autoscaling with KEDA
In Kubernetes, a table's workers run as one StatefulSet named
<pipeline>-<target> (DNS-sanitized), with replicas = workers.number at
boot. A StatefulSet pod's hostname is <statefulset>-<ordinal> — exactly the
derived worker group name — so a replica is its partition, with no identity
plumbing.
That single replica count is what KEDA scales. Start the operator with
--keda-prometheus-address <url> and it renders one ScaledObject per table
that sets workers.max:
minReplicaCount=workers.number,maxReplicaCount=workers.max;- a Prometheus trigger on
urutau_coordinator_pending_batches{table="<target>"}(the table's outstanding batches — queued, in-flight, and staged), with--keda-threshold(default 30) as the per-replica backlog target.
Why the backlog, not the lag. urutau_coordinator_lag_seconds is the time
since the table's last commit. Measured under a 50k-row burst it stayed ~0.1s
while the table owed ~50k rows — commits kept flowing, so the gauge never moved
— and it grew while the table sat idle. It is a "commits have stalled"
detector, not a load signal. urutau_coordinator_pending_batches is the direct
backlog, and is what the ScaledObject uses. (The lag gauge is still set, and
reads zero for a caught-up table.)
The coordinator never writes the replica count — it follows it. A reconcile
loop reads each worker StatefulSet's spec.replicas and calls ScaleTable when
the routing owner count diverges, so KEDA (or a manual kubectl scale) is the
only writer. A failed scale is retried after a cooldown, so it cannot hold the
table's input paused on every tick.
Known limit. A re-slice flips only once the table owes nothing (the barrier
above). Under a large backlog the drain cannot converge inside
ScaleDrainTimeout, so a scale-out can fail: KEDA raises replicas, the new
pods connect, but the coordinator keeps the old routing and the new owners idle
until the backlog drains. The mechanism is sound for a moderate backlog (the
drain converges) and for scale-in; making a scale-out effective while
backlogged needs a cheaper barrier.
Omit workers.max and the count is fixed — no ScaledObject, no autoscaling.
Next steps
- Automate the lifecycle: Deploy on Kubernetes.
- Live signals: Monitoring.
- Audit log, checkpoints, supervision: Reliability.
- All flags: CLI reference.