A Kestrel workflow can start with a failed Kubernetes workload, run an AI root-cause analysis, propose a fix and wait for someone to approve it in Slack before opening a GitOps pull request. The worker that starts the analysis may be gone by the time approval arrives. Kestrel uses Postgres to record what finished and what the workflow is waiting for, so another worker can pick up where the first left off.
The team considered a dedicated orchestrator such as Temporal or AWS Step Functions. Postgres was already its system of record, though, and a separate orchestrator would add a stateful service to operate and secure. It would also need access controls and auditing for workflow payloads that can contain source code, logs and infrastructure topology. Instead, each Kestrel application server runs an embedded workflow library that talks directly to Postgres.
Claiming work without holding a lock for hours
A trigger, such as a PagerDuty alert or GitHub webhook, inserts a row into workflow_executions. Workers poll for queued rows. In a short transaction, a worker uses FOR UPDATE SKIP LOCKED to select a row, marks it as running, records its own ID and sets a lease expiry. Other workers skip the locked row rather than waiting for it. The worker commits before starting the workflow, so a slow external call does not hold a database lock.
That transaction replaces a message broker, leader election and an external lock service in Kestrel’s scheduler. Workers can claim a batch to reduce database round trips, but a crash then leaves more unfinished work to recover. Skipping locked rows also means dispatch is not strictly first-in, first-out under contention.

What survives a restart
Before running a step, the workflow library looks for its result in operation_outputs. The table’s primary key, (execution_id, step_id), identifies a step within a particular run. If a result exists, the worker passes it to the next step without repeating the completed work. Otherwise, it runs the step and records the output with ON CONFLICT DO NOTHING, preserving any result already committed for that key.
The distinction is important: the constraint guarantees one stored result per step, not that an external action and its checkpoint happen atomically. A checkpoint lets a replacement worker skip work for which a result was saved; it does not establish what happened outside the database if the first worker died before saving that result.
While a worker is active, it sends heartbeats to extend its lease. Kestrel’s example extends the expiry to 30 seconds from each renewal. A periodic process called a sweeper requeues runs whose leases have expired. A longer lease delays recovery after a crash; a shorter one risks reassigning a run while a slow worker is still active.
Waiting is a separate state. At a sleep or approval step, Kestrel marks the execution as waiting and inserts a workflow_waits row with a wake_at timestamp. A periodic query requeues waits that come due. Whether an approval window lasts two hours or two weeks, the wait itself needs one row, not a live worker thread.
Where the database becomes the limit
Kestrel’s I/O-heavy automation pipelines run for seconds to hours, spend much of that time on external calls and require moderate concurrency. The team reports observing tens of thousands of workflows per second on a single Postgres instance without read replicas or Citus. That is an observation from its deployment, not a throughput guarantee. For dispatch across thousands of workers with sub-millisecond latency requirements, the team says a dedicated engine such as Temporal may be a better fit.
Adding stateless workers increases throughput only as long as Postgres can service the queue. Hundreds of polling workers can exhaust database connections; the team points to PgBouncer transaction pooling and longer, randomized polling intervals for idle workers. Frequent updates and deletes can also leave dead tuples in the queue table. Tuning autovacuum, using partial indexes and partitioning completed runs away from active ones can keep the working set small.
Keeping the records together has a practical payoff for operators: a SQL join across executions, steps and approvals can show which proposed fixes were rejected and at what step. Kestrel indexes status and creation time to support dashboards without a separate analytics system. The trade-off is that workflow availability now depends directly on Postgres and its failover setup. At larger scale, the team notes, a separate Postgres deployment can isolate workflow traffic from application traffic while retaining the same operational model.
