Saga Lara Flow: Durable Workflows for Laravel | Mohamed Said        [  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MH.png)   Mohamed Said Laravel Backend Engineer  ](https://www.msaied.com) [ Home ](https://www.msaied.com) [ Projects ](https://www.msaied.com/projects) [ Articles  ](https://www.msaied.com/articles) [ Certificates ](https://www.msaied.com/certificates) [ Contact ](https://www.msaied.com#contact-section) 

       [  ](https://github.com/EG-Mohamed)       

 [ Home ](https://www.msaied.com) [ Projects ](https://www.msaied.com/projects) [ Articles ](https://www.msaied.com/articles) [ Certificates ](https://www.msaied.com/certificates) [ Contact ](https://www.msaied.com#contact-section) 

  [ home ](https://www.msaied.com)    [ articles ](https://www.msaied.com/articles)    Saga Lara Flow: Durable Workflows and Compensating Transactions on Laravel Queues        On this page       1. [  What Is Saga Lara Flow? ](#what-is-saga-lara-flow)
2. [  Core Features at a Glance ](#core-features-at-a-glance)
3. [  Defining Workflows and Actions ](#defining-workflows-and-actions)
4. [  Compensating Failed Transactions ](#compensating-failed-transactions)
5. [  Signals: Waiting on External Input ](#signals-waiting-on-external-input)
6. [  Concurrency and Child Workflows ](#concurrency-and-child-workflows)
7. [  Installation ](#installation)
8. [  Key Takeaways ](#key-takeaways)

  ![Saga Lara Flow: Durable Workflows and Compensating Transactions on Laravel Queues](https://cdn.msaied.com/520/d77bd3c0cecb6fb89c16f85648e7e369.png)

 [  Laravel ](https://www.msaied.com/articles?category=laravel) [  Composer Pacakge ](https://www.msaied.com/articles?category=composer-pacakge)  #Laravel   #Workflows   #Saga Pattern   #Queues   #Compensating Transactions   #PHP Package  

 Saga Lara Flow: Durable Workflows and Compensating Transactions on Laravel Queues 
===================================================================================

     7 Aug 2026      4 min read    ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said  

       Table of contents

1. [  01   What Is Saga Lara Flow?  ](#what-is-saga-lara-flow)
2. [  02   Core Features at a Glance  ](#core-features-at-a-glance)
3. [  03   Defining Workflows and Actions  ](#defining-workflows-and-actions)
4. [  04   Compensating Failed Transactions  ](#compensating-failed-transactions)
5. [  05   Signals: Waiting on External Input  ](#signals-waiting-on-external-input)
6. [  06   Concurrency and Child Workflows  ](#concurrency-and-child-workflows)
7. [  07   Installation  ](#installation)
8. [  08   Key Takeaways  ](#key-takeaways)

 What Is Saga Lara Flow?
-----------------------

[Saga Lara Flow](https://github.com/discovery-ukraine/saga-lara-flow) is a Laravel package by Andriy Karpishyn that lets you model long-running business processes — charge a card, reserve stock, book a shipment — as a single `handle()` method on top of Laravel queues. No job chaining, no hand-rolled state machines.

The engine records every completed step to the database. When a worker picks up a workflow, it re-executes `handle()` from the top, but `$this->action()` intercepts each call: already-completed steps return their stored result instantly, and execution resumes only at the first unfinished step. If any step throws, registered compensations fire in reverse order.

Core Features at a Glance
-------------------------

- **Workflows as plain methods** — sequential `$this->action()` calls with no job chaining
- **Compensating transactions** — register an undo action per step with `compensateWith()`
- **Signals** — suspend a run until external input arrives, with optional timeout
- **Parallel blocks** — dispatch independent actions concurrently and collect results
- **Child workflows** — nest workflows with a configurable close policy
- **Side effect recording** — wrap non-deterministic values so replays stay deterministic
- **Tag-based querying** — find runs by workflow class, tag, and status
- **Artisan commands** — list, inspect, signal, cancel, prune, and monitor runs

Defining Workflows and Actions
------------------------------

A workflow extends `Workflow` and calls action classes through `$this->action()`. Actions are resolved from the container, so dependencies are injected automatically:

```php
use DiscoveryUkraine\SagaLaraFlow\Workflow;

class ProvisionAccountWorkflow extends Workflow
{
    public function handle(string $email): array
    {
        $tenantId = $this->action(CreateTenant::class, $email)->run();
        $this->action(SendWelcomeEmail::class, $email)->run();
        return ['tenant' => $tenantId];
    }
}

```

Runs are started via the `SagaFlow` facade. `runSync()` drives every step in-process, making it ideal for tests:

```php
$run = SagaFlow::create(ProvisionAccountWorkflow::class)
    ->withArguments('jane@example.com')
    ->runSync();

$this->assertTrue($run->isCompleted());

```

Non-deterministic values like UUIDs must be wrapped in `sideEffect()` so replays always see the original result:

```php
$reference = $this->sideEffect('reference', fn () => (string) Str::uuid());

```

Compensating Failed Transactions
--------------------------------

Each step can register an undo action. If a later step fails, compensations fire in reverse order:

```php
public function handle(string $orderId): void
{
    $this->action(ChargeCard::class, $orderId)
        ->compensateWith(RefundCard::class, $orderId)
        ->run();

    $this->action(ReserveStock::class, $orderId)
        ->compensateWith(ReleaseStock::class, $orderId)
        ->run();

    // If this throws, ReleaseStock runs first, then RefundCard.
    $this->action(ShipOrder::class, $orderId)->run();
}

```

For grouped rollbacks, `$this->saga()` supports `onCompensationFailure()` and `compensateInParallel()` to control whether a failed undo aborts the rollback and whether undos run concurrently.

Signals: Waiting on External Input
----------------------------------

`$this->signal()` suspends a run until external code delivers the named signal. `timeoutAfter()` adds a deadline:

```php
try {
    $decision = $this->signal('approval')
        ->timeoutAfter(now()->addDay())
        ->wait();
} catch (AwaitSignalTimeoutException $e) {
    $this->action(AutoReject::class)->run();
}

```

Deliver the signal from anywhere in your application:

```php
SagaFlow::loadFlow($runId)->signal('approval', ['approved' => true]);

```

Tag-based querying lets you locate the right run without storing its ID:

```php
SagaFlow::query()
    ->whereWorkflow(ProvisionCompanyWorkflow::class)
    ->whereTag('company', $companyId)
    ->signalable()
    ->handles()
    ->first()
    ?->signal('owner-synced');

```

Concurrency and Child Workflows
-------------------------------

Independent actions run in parallel with `$this->parallel()`:

```php
[$pricing, $inventory, $reviews] = $this->parallel()
    ->action(FetchPricing::class, $sku)
    ->action(FetchInventory::class, $sku)
    ->action(FetchReviews::class, $sku)
    ->run();

```

Child workflows are invoked with `$this->child()`, and a `ChildClosePolicy` controls what happens when the parent finishes.

Installation
------------

The package requires **PHP 8.5** and **Laravel 13**:

```bash
composer require discovery-ukraine/saga-lara-flow
php artisan migrate
php artisan vendor:publish --tag="saga-lara-flow-config"

```

Register the expiration monitor with the Laravel scheduler:

```php
Schedule::command('saga-flow:monitor')->everyMinute();

```

Key Takeaways
-------------

- Write multi-step distributed processes as a single readable `handle()` method
- Automatic replay skips already-completed steps without re-running side effects
- Compensating transactions roll back completed steps in reverse order on failure
- Signals pause execution until a human or external system responds
- Parallel blocks, optional steps, child workflows, and versioning cover advanced use cases
- `runSync()` makes the whole workflow testable without a real queue

Full documentation is available at [sagalaraflow.dev](https://sagalaraflow.dev). Read the original announcement at [Laravel News](https://laravel-news.com/saga-lara-flow).

 Found this useful?

          [  ](https://twitter.com/intent/tweet?url=https%3A%2F%2Fwww.msaied.com%2Farticles%2Fsaga-lara-flow-durable-workflows-and-compensating-transactions-on-laravel-queues&text=Saga+Lara+Flow%3A+Durable+Workflows+and+Compensating+Transactions+on+Laravel+Queues) [  ](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fwww.msaied.com%2Farticles%2Fsaga-lara-flow-durable-workflows-and-compensating-transactions-on-laravel-queues) 

 Frequently Asked Questions 
----------------------------

  3 questions  

     Q01  How does Saga Lara Flow avoid re-running completed steps when a workflow is replayed?        The package records each completed step and its result to the database. On replay, `$this-&gt;action()` intercepts every call and returns the stored result for already-completed steps without executing the action class again. Execution only resumes at the first step that has not yet finished. 

      Q02  What happens if a step in the middle of a workflow fails?        When a step throws an exception, the engine triggers the compensation actions registered for all previously completed steps, running them in reverse order. You can register an undo action class or a closure per step using `compensateWith()`, and group compensations with `$this-&gt;saga()` for parallel or fault-tolerant rollback behavior. 

      Q03  Can a workflow pause and wait for an external event like a human approval?        Yes. `$this-&gt;signal()` suspends the workflow run and releases the worker. When external code calls `SagaFlow::loadFlow($runId)-&gt;signal('approval', $data)`, the run resumes from where it left off. You can also chain `timeoutAfter()` to set a deadline and catch `AwaitSignalTimeoutException` if it expires. 

  Continue reading

 More Articles 
---------------

 [ View all    ](https://www.msaied.com/articles) 

 [ ![Filament v4.12 & v5.7: Major Performance Improvements and Security Patches](https://cdn.msaied.com/518/48e5a4da1b38d6cf27a0117baa547e1b.png) Filament Laravel Performance 

### Filament v4.12 &amp; v5.7: Major Performance Improvements and Security Patches

Filament v4.12.6 and v5.7.6 ship massive rendering speed gains—up to 92% faster form fields—alongside security...

  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said 

 6 Aug 2026     1 min read  

  Read    

 ](https://www.msaied.com/articles/filament-v412-v57-major-performance-improvements-and-security-patches) [ ![Managed Queues: Autoscaling Queue Workers on Laravel Cloud](https://cdn.msaied.com/519/854099015015dbc72dd8743202b69efc.png) Laravel Cloud Queue Workers Autoscaling 

### Managed Queues: Autoscaling Queue Workers on Laravel Cloud

Laravel Cloud's managed queues feature autoscales workers based on queue pressure, surfaces failed jobs in a r...

  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said 

 6 Aug 2026     3 min read  

  Read    

 ](https://www.msaied.com/articles/managed-queues-autoscaling-queue-workers-on-laravel-cloud) [ ![Job Batching, Chaining, and Rate-Limited Middleware in Laravel Queues](https://cdn.msaied.com/515/f0ef4270f8cb79ceff107c7a7c63f1ed.png) laravel queues jobs 

### Job Batching, Chaining, and Rate-Limited Middleware in Laravel Queues

Go beyond basic dispatching: learn how to compose Laravel job batches, build resilient chains, and throttle th...

  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said 

 6 Aug 2026     3 min read  

  Read    

 ](https://www.msaied.com/articles/job-batching-chaining-and-rate-limited-middleware-in-laravel-queues-4) 

   [  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MH.png)   Mohamed Said Laravel Backend Engineer  ](https://www.msaied.com)Senior Backend Engineer specializing in Laravel, scalable SaaS platforms, APIs, and cloud infrastructure. I build secure, high-performance web applications that help businesses grow.

Explore

- [Home](https://www.msaied.com)
- [Projects](https://www.msaied.com/projects)
- [Articles](https://www.msaied.com/articles)
- [Certificates](https://www.msaied.com/certificates)
- [Contact](https://www.msaied.com#contact-section)

Connect

- [   hello@msaied.com ](mailto:hello@msaied.com)
- [   +20 109 461 9204 ](tel:+201094619204)

© 2026 Mohamed Said. All rights reserved.

 [  ](https://github.com/EG-Mohamed) [  ](https://www.linkedin.com/in/msaiedm/) [  ](https://wa.me/201094619204) [  ](mailto:hello@msaied.com) [  ](https://drive.google.com/file/u/0/d/1MF20IPRJyzfy32mhEutjL5EpSls0w2Q8/view)
