Skip to content

Keep Pulsar safe in long-lived workers

Pulsar workflow constructors hold dependencies while execute receives runtime data. That convention avoids retaining request, actor, tenant, payload state in objects reused by Octane/queue workers; scoped bindings reset with Laravel lifecycle but do not provide security.

Octane singleton request

Laravel Octane boots the application once and reuses it. Constructors therefore hold only stable dependencies. A workflow must not retain a Request, actor, tenant, correlation value, payload, live Model, mutable configuration, or captured container in an instance property. Controller and route method Request injection remains a Laravel delivery boundary.

Object or stateBinding or useReset and limit
Pure stateless Adapter/value serviceRegular, or deliberate singleton with no mutable/request/config/container capture.Shared only while stateless; application tests choose the singleton.
Actor, tenant, or request contextScoped Contract/implementation or explicit execute()/handler argument.Laravel flushes Octane request and queue-job scope; callers still reconstruct, authorize, and tenant-scope.
UseCase, Action, Operation, QueryConstructor dependencies; runtime data in execute().Do not retain caller context as a property.
Job, Command, queued ListenerDurable IDs, DTOs, and Value Objects.Reconstruct, authorize, scope, and keep the same idempotency key.
Static cache or mutable globalNo actor/tenant accumulation.Only application-owned bounded cache/invalidation; package tests prove no memory safety or isolation.

Pass runtime values at the method boundary

Context: runtime boundary — stable dependencies enter the constructor; request-specific data enters the workflow call.

php
final class ChargeInvoice
{
    public function __construct(private PaymentGateway $gateway) {}

    public function execute(InvoiceId $invoiceId, ActorId $actorId): void {}
}

Scoped lifetime is not authorization, tenant isolation, idempotency, or exactly-once delivery. This documentation neither creates a Context API nor configures Octane, workers, middleware, caches, or tenant infrastructure.

Continue with Contracts and Adapters for bindings, Tenancy for independent isolation, and Anti-patterns for the prohibited shapes.