Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Saga Laravel Package

brzuchal/saga

Laravel package implementing the Saga pattern for coordinating long-running, distributed workflows. Helps model multi-step processes with compensating actions, track saga state, and handle failures/retries so complex business transactions stay consistent across services.

View on GitHub
Deep Wiki
Context7

At a glance

Frequently asked questions about Saga
How does this package compare to Laravel’s built-in queues for handling multi-step workflows?
This package explicitly implements the Saga pattern, which is designed for distributed systems where traditional transactions (ACID) aren’t possible. While Laravel queues handle individual jobs, this package orchestrates entire workflows with compensating actions for rollback scenarios. Use it when you need eventual consistency across services, not just sequential job execution.
Can I use this for a simple Laravel monolith without microservices?
Yes, but evaluate if it’s overkill. The Saga pattern shines in distributed systems, but it can also manage complex workflows within a monolith if you need compensating actions for failures. For simpler cases, Laravel’s database transactions or queues alone might suffice. Test with a pilot workflow first.
What happens if a step in my saga fails? How are compensating actions triggered?
When a step fails, the package automatically invokes the compensating actions you define in reverse order. For example, if `ChargeCustomer` fails after `ReserveInventory`, it will call your `refundAndReleaseInventory` method. Compensating actions are executed asynchronously via Laravel queues, ensuring eventual consistency.
Does this package support Laravel’s event system for saga lifecycle hooks?
Yes, it integrates with Laravel Events for key saga lifecycle moments like `SagaStarted`, `StepExecuted`, and `SagaFailed`. You can listen to these events for logging, notifications, or custom logic. This is useful for observability and extending saga behavior without modifying the core package.
What storage options are available for saga state, and which should I choose?
The package supports both database (Eloquent) and Redis for storing saga state. Choose database if you need persistence with complex queries or transactions, and Redis if you prioritize speed and scalability. Redis is ideal for high-throughput systems, while database storage offers more flexibility for querying saga history.
How do I handle idempotency if a saga step fails and retries?
Idempotency is your responsibility. Design each step to be repeatable without side effects (e.g., using unique IDs or checking state before acting). The package doesn’t enforce idempotency, so ensure your compensating actions and steps account for retries. For example, avoid double-charging a customer by checking payment status first.
Will this package work with Laravel 9 or 10? Are there any breaking changes to watch for?
The package is tested with Laravel 8+ and should work with Laravel 9/10, but always check the `laravel/framework` compatibility constraint in the package’s `composer.json`. Breaking changes are unlikely unless Laravel introduces major queue or event system modifications. Monitor the package’s release notes for updates.
Can I integrate this with non-Laravel services (e.g., external APIs or microservices)?
Yes, the package is designed for distributed workflows. You can invoke external services as saga steps, but ensure they support eventual consistency. Compensating actions must also be callable remotely (e.g., via HTTP callbacks or message queues). Use Laravel’s queue drivers or external systems like Kafka/RabbitMQ for event publishing.
How do I test sagas in my Laravel application? Are there mocking strategies for unit tests?
Test sagas by mocking their steps, compensating actions, and event listeners. Use Laravel’s testing tools to simulate failures and verify compensations. For integration tests, queue workers and saga state storage (DB/Redis) must be available. Focus on testing edge cases like partial failures and retry logic.
What are the performance implications of storing saga state in Redis vs. the database?
Redis is faster for high-throughput systems due to in-memory storage, but lacks persistence and query flexibility. Database storage is slower but offers ACID guarantees and richer querying (e.g., filtering sagas by status). Benchmark your use case: Redis for scalability, database for reliability and debugging. Consider hybrid approaches for critical workflows.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity