A Kestrel workflow can investigate a Kubernetes failure, propose a fix, wait for someone to approve it in Slack and then open a GitOps pull request. If Kubernetes evicts the worker during the wait, its replacement needs to know that the investigation is complete but approval is still pending. Kestrel keeps that distinction in Postgres rather than in the worker’s memory.
The Kestrel team chose its existing database over a dedicated workflow orchestrator such as Temporal or AWS Step Functions. Each application server runs an embedded workflow library that talks directly to Postgres. The team can therefore use its existing access controls and auditing rather than sending workflow payloads, which can include source code, logs and infrastructure details, to another service.
Claiming work without holding a lock for hours
A trigger, such as a PagerDuty alert or a GitHub webhook, inserts a row into workflow_executions. Workers poll the table. In a short transaction, a worker uses FOR UPDATE SKIP LOCKED to lock an available row, marks it as running, records its worker ID and sets a lease expiration. Other workers skip the locked row rather than waiting for it. The transaction commits before the worker starts the task, so a slow external call does not tie up a database lock.
That transaction takes the place of a separate scheduler, message broker or lock service. Workers can claim several rows at once to reduce database round trips, though more tasks then have to be recovered if a worker fails. Skipping locked rows also means that workers need not claim tasks in strict arrival order.

What a replacement worker can recover
Before running a step, the workflow library looks in operation_outputs for a result with the same execution ID and step ID. If it finds one, it passes the saved output to the next step. Otherwise, it runs the step and inserts the result. A composite primary key on (execution_id, step_id) and an ON CONFLICT ... DO NOTHING insert ensure that a later attempt cannot overwrite the first committed result.
The distinction is between one stored result and one external action. A committed checkpoint lets a replacement worker skip a completed step. The unique key does not by itself establish whether an external action occurred if the worker failed before recording its result.
While working, the owner sends heartbeats to extend its lease; Kestrel’s example uses a 30-second lease. A periodic cleanup query returns runs with expired leases to the queue, where another worker can claim them and read their checkpoints. Short leases speed recovery after a crash, but a slow worker that misses a heartbeat can still be running when its replacement starts. Longer leases reduce that overlap at the cost of slower recovery.
For a sleep or an approval gate, the library marks the run as waiting and writes a row to workflow_waits with a wake_at timestamp. A periodic query requeues waits that are due. A two-week approval window needs the same single wait record as a two-hour window; neither requires a worker to stay alive.
Where the database becomes the limit
Kestrel’s automation pipelines are I/O-bound, run for seconds to hours 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 observation is specific to its workload. 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 workers increases throughput only while Postgres can keep up. Hundreds of pollers can exhaust database connections, so the team points to PgBouncer transaction pooling and recommends that idle workers poll less often, with jitter to spread out requests. Frequent updates and deletes can also bloat the queue table. Tuning autovacuum, using partial indexes and partitioning completed runs away from the active queue help keep the working set small.
The operational payoff is that the same records used for recovery can answer questions about a run. Operators can join executions, step outputs and approvals to see which proposed fixes were rejected and at what step. Indexes on status and creation time support dashboards without a separate analytics system. The trade-off is equally direct: workers can replace one another, but workflow availability still depends on the database and its failover setup.
