Durable Workflow for Laravel: Running Long-Running Business Processes Without the Headaches
Long-running business processes — order fulfilment, subscription onboarding, loan approval pipelines, multi-step data imports — are a staple of serious Laravel applications. The traditional approach of chaining jobs and stuffing state into the database works until it doesn't: a deployment mid-process loses in-memory state, a worker crash leaves a job half-done, and debugging a saga that spanned three days and five services becomes archaeology.
The durable-workflow/workflow package (v2, released October 2026) brings a different model to Laravel: durable execution. You write workflows as ordinary PHP classes that can suspend, resume, and survive anything the infrastructure throws at them. The package handles persistence, replay, and orchestration so you don't have to.
What "durable" means here
A durable workflow is a piece of code that:
- Persists its execution history automatically — every activity call, timer, signal, and child workflow is recorded
- Survives worker restarts, deployments, and crashes — when the worker comes back, the workflow rebuilds its state by replaying history deterministically
- Runs on Laravel's existing infrastructure — queues, cache, and database; no separate Temporal or Cadence cluster required (though self-hosted and cloud modes exist if you outgrow embedded mode)
The mental model shifts from "fire-and-forget jobs with manual state tracking" to "a single function that looks synchronous but can pause for days."
Installation and requirements
composer require durable-workflow/workflow:^2.0
php artisan migrate
php artisan queue:work # or Horizon
Requirements: PHP 8.1+, Laravel 9+ (Laravel 12/13 recommended for production). The package uses Fibers under the hood, so PHP 8.1 is the floor.
A minimal workflow
use Workflow\V2\Activity;
use Workflow\V2\Workflow;
use Workflow\V2\WorkflowStub;
use function Workflow\V2\activity;
final class SendWelcomeEmail extends Activity {
public function handle(string $email): void {
Mail::to($email)->send(new WelcomeMail);
}
}
final class OnboardUser extends Workflow {
public function handle(string $email): void {
activity(SendWelcomeEmail::class, $email);
// Workflow can pause here for days — state is safe
activity(AssignDefaultRole::class, $email);
activity(CreateStarterProject::class, $email);
}
}
// Starting it
$stub = WorkflowStub::make(OnboardUser::class);
$stub->start('alice@example.com');
activity() suspends the workflow, queues the activity, and resumes when the activity completes. If the worker restarts between the first and second activity, the workflow replays from the beginning — but the first activity is not re-executed because its result is already in the history.
Activities: durable units of work
Activities are the building blocks. They run on the queue (any driver: Redis, SQS, database) and support:
- Retries with backoff — configure
RetryOptionsper activity or globally - Timeouts —
startToCloseTimeout,heartbeatTimeout,scheduleToCloseTimeout - Heartbeats — long activities can report progress; the runtime knows they're alive
- Idempotency keys — the same activity invocation ID won't run twice
use Workflow\V2\ActivityOptions;
use function Workflow\V2\activity;
activity(
ProcessPayment::class,
$orderId,
new ActivityOptions(
retryOptions: new RetryOptions(
maxAttempts: 5,
initialInterval: 10,
backoffCoefficient: 2.0,
),
startToCloseTimeout: 60,
),
);
Signals: external events that resume workflows
Real processes wait for humans, webhooks, or other systems. Signals let a workflow pause until an external event arrives:
use Workflow\V2\Workflow;
use function Workflow\V2\awaitSignal;
final class OrderFulfilment extends Workflow {
public function handle(string $orderId): void {
activity(ReserveInventory::class, $orderId);
// Wait for payment webhook — could be seconds or weeks
$payment = awaitSignal('payment-received', timeout: 60 * 60 * 24 * 7);
if (! $payment->success) {
activity(ReleaseInventory::class, $orderId);
return;
}
activity(ShipOrder::class, $orderId);
}
}
// From a controller or webhook handler
$stub = WorkflowStub::make(OrderFulfilment::class, $orderId);
$stub->signal('payment-received', ['success' => true, 'txn_id' => 'txn_123']);
The workflow suspends at awaitSignal() consuming zero resources while waiting. The signal payload is validated and typed.
Queries: read workflow state without replay side effects
Need to show progress in a UI? Queries are read-only, replay-safe, and don't advance history:
use Workflow\V2\Workflow;
use function Workflow\V2\query;
final class OrderFulfilment extends Workflow {
private string $status = 'pending';
#[QueryMethod]
public function getStatus(): string {
return $this->status;
}
public function handle(string $orderId): void {
$this->status = 'reserving';
activity(ReserveInventory::class, $orderId);
$this->status = 'awaiting_payment';
$payment = awaitSignal('payment-received');
$this->status = 'shipping';
activity(ShipOrder::class, $orderId);
$this->status = 'completed';
}
}
// From anywhere
$stub = WorkflowStub::make(OrderFulfilment::class, $orderId);
echo $stub->query(OrderFulfilment::class, 'getStatus'); // "awaiting_payment"
Child workflows: composition without coupling
Complex processes decompose into sub-processes. Child workflows are first-class:
use Workflow\V2\Workflow;
use function Workflow\V2\child;
final class ParentWorkflow extends Workflow {
public function handle(string $orderId): void {
$fulfilment = child(OrderFulfilment::class, $orderId);
$billing = child(BillingWorkflow::class, $orderId);
// Run in parallel
$fulfilment->start();
$billing->start();
$fulfilment->await();
$billing->await();
}
}
Each child has its own history and can be queried, signalled, or cancelled independently.
Sagas: compensation when things go wrong
When a multi-step process fails halfway, you need to undo what succeeded. The package includes saga support with compensation activities:
use Workflow\V2\Workflow;
use function Workflow\V2\saga;
final class TransferFunds extends Workflow {
public function handle(TransferInput $input): void {
saga()
->step(
execute: fn () => activity(DebitSource::class, $input),
compensate: fn () => activity(CreditSource::class, $input),
)
->step(
execute: fn () => activity(CreditDestination::class, $input),
compensate: fn () => activity(DebitDestination::class, $input),
)
->execute();
}
}
If the second step fails, the first step's compensation runs automatically. You can also define saga timeouts and custom rollback logic.
Parallel execution and timers
use Workflow\V2\Workflow;
use function Workflow\V2\parallel;
use function Workflow\V2\timer;
final class ParallelDemo extends Workflow {
public function handle(): void {
// Fire activities in parallel, wait for all
parallel([
activity(StepA::class),
activity(StepB::class),
activity(StepC::class),
]);
// Sleep without blocking a worker
timer(60 * 60 * 24); // resume in 24 hours
}
}
timer() suspends the workflow; no queue worker is occupied during the wait.
Scheduling recurring workflows
use Workflow\V2\Support\ScheduleManager;
ScheduleManager::create(
scheduleId: 'daily-report',
workflowClass: GenerateDailyReport::class,
cronExpression: '0 6 * * *',
arguments: ['2026-10-31'],
);
Add php artisan workflow:v2:schedule-tick to Laravel's scheduler (* * * * * cron) and the package handles deduplication and overlapping runs.
Deployment modes
| Mode | When to use |
|---|---|
| Embedded Laravel (default) | Workflows and activities live in your Laravel app; simplest ops |
| Self-hosted server | Workers run independently, multi-language support, scale workflows separately from HTTP |
| Durable Workflow Cloud | Fully managed PHP/Python/Rust runtime; zero infrastructure |
Start embedded. Migrate when you need language polyglot, independent scaling, or want to offload operational burden.
When to reach for this
- Multi-step processes with human delays — approvals, onboarding, KYC
- Saga-pattern transactions across services — payments, inventory, shipping
- Long-running data pipelines — ETL, report generation, ML training orchestration
- Agentic AI workflows — the package includes a sample AI agent with saga compensation
When to stick with queues + jobs
- Fire-and-forget tasks (email, notifications, webhooks)
- Simple linear chains with no external waits
- Teams unfamiliar with event-sourced thinking — there's a learning curve
Gotchas to know
- Determinism is mandatory — workflow code must produce the same history on replay. No random, no
now(), no external I/O inside the workflow function (use activities for that). - Workflow code changes break replay — if you change the sequence of activity calls, in-flight workflows can't replay. Version your workflow classes or use the patching API.
- Activity idempotency is your responsibility — the runtime guarantees at-least-once delivery; design activities to be safely re-runnable.
- Large histories impact replay time — workflows with thousands of events take longer to rebuild. Continue-as-new can reset history for very long processes.
TL;DR
durable-workflow/workflow brings production-grade durable execution to Laravel without leaving the ecosystem. You write workflows that look synchronous, and the package handles the hard parts: persistence, replay, signals, queries, sagas, and scheduling. If you're building processes that span hours, days, or weeks — especially ones that wait on humans or external systems — it's worth a serious look.