Durable Workflow Brings Fault-Tolerant Long-Running Jobs to Laravel
The open-source Laravel 12/13 package persists activity outputs in your own database, replaying workflows after worker restarts without redoing finished steps.
Multi-step background pipelines in PHP often break down the moment a queue worker crashes, deployments restart containers, or an external API times out halfway through a job chain. As covered by Laravel News, the free, open-source Durable Workflow package—created by Richard McDaniel—solves this directly inside Laravel by recording step outputs in your own database and replaying workflow state safely across worker restarts.
Running on Your Existing Laravel Stack
Unlike external workflow engines that require provisioning a separate cluster or subscribing to a managed orchestration platform, Durable Workflow runs inside your Laravel application and builds on infrastructure most PHP teams already operate:
- Database: Persists workflow execution history and recorded step results via database migrations loaded automatically by the package.
- Asynchronous queues: Executes background work using Laravel's
database, Redis, or Amazon SQS drivers (the synchronoussyncdriver is not supported), driven byphp artisan queue:workor Laravel Horizon with Redis. - Lock-capable cache: Coordinates concurrent execution across workers safely using cache locks.
Version 2.28.1 requires Laravel 12.72+ or 13.41+ and PHP 8.2+ (PHP 8.3+ for Laravel 13). Installation takes just two commands: composer require durable-workflow/workflow:"^2.0" followed by php artisan migrate. While the project offers an optional paid Cloud service, the open-source package requires no subscription—you only pay for the infrastructure you already run.
Separating Coordination From Side Effects
Durable Workflow splits background logic into two distinct primitives scaffolded via Artisan commands (php artisan make:workflow ReportWorkflow --v2 and php artisan make:activity GenerateReport --v2), placing v2 classes under app/Workflows by default:
- Workflows (
Workflow\V2\Workflow): Pure orchestration classes that define execution order using theactivity()helper—for example, coordinatingGenerateReport,UploadReport, andNotifyReportReadyin sequence and returning the final report URL. - Activities (
Workflow\V2\Activity): Concrete units of work implementinghandle(), responsible for calling application services such as a report generator, writing to file storage, or talking to external APIs.
Starting a workflow from application code is non-blocking: WorkflowStub::make(ReportWorkflow::class)->start($reportId) returns immediately while background queue workers drive the pipeline to completion.
Replay Mechanics, Idempotency, and Retries
When a worker restarts or resumes a suspended process, Durable Workflow replays the workflow's PHP code using previously recorded activity outputs. If generating and uploading a report already succeeded and were stored in the database, replay reuses those recorded results rather than re-running those two activities.
That replay architecture introduces important engineering rules developers must observe in production:
- Deterministic workflows: Database reads and external calls belong strictly inside activities so that replaying workflow code with the same recorded inputs always makes identical control-flow decisions—a critical constraint whenever you modify workflows that still have active runs in flight.
- Idempotent activity design: An activity can still execute more than once if a worker completes an operation but stops before its result is persisted. Designing activities to be safe to repeat—such as uploading a report to a stable object-storage key—protects against duplicate side effects.
- Opt-in retries: In v2, activities default to a single attempt. Developers configure
$triesandbackoff()explicitly when retry behavior is desired; an unhandled final failure can terminate the run, and deploying a code fix does not automatically reopen a failed run.
Signals, Durable Timers, and Practical Scope
Beyond crash recovery, Durable Workflow supports signals for injecting external input into a running workflow and durable timers for scheduled waits. An approval pipeline, for instance, can pause until a declared approval signal arrives—optionally with a timeout—before scheduling the next activity. For visibility into active and completed runs, Laravel News previously highlighted the companion monitoring UI Laravel Waterline.
For a single, self-contained background task, a regular Laravel queued job remains simpler and lighter. Durable Workflow earns its place when a business process spans multiple dependent steps, must survive container restarts without redoing expensive work, or needs to wait for human or external system input while staying cleanly inside the Laravel stack.
// comments (0)