Side effects and downstream jobs run only after durable commit

rel-017

Intent

Prevent jobs and external side effects from observing or acting on state that later rolls back.

Applicability

Applies when the diff adds queued work, messages, emails, or remote calls around a database transaction.

What to inspect

Transaction boundaries, side-effect timing, after-commit hooks, and enqueue or publish calls.

Pass criteria

External side effects and dependent jobs are emitted after the durable commit point or through an outbox or equivalent commit-coupled mechanism.

Fail criteria

The diff dispatches jobs or side effects before the enclosing transaction is durable.

Do not flag

Read-only transaction scopes. Purely local in-memory callbacks.

Confidence guidance

HIGH when enqueue-before-commit is directly visible. MEDIUM when transaction ownership is partly hidden. LOW when durability boundaries are unclear.

Remediation

Move dispatch or publish logic to an after-commit hook, outbox, or use-case boundary that runs after durability is guaranteed.

Pass example

await db.SaveChangesAsync(ct);
await outbox.PublishAsync(evt, ct);

Fail example

await bus.PublishAsync(evt, ct);
await db.SaveChangesAsync(ct);

Sources

  • Get Your Hands Dirty on Clean Architecture book
  • Laravel official docs: security, validation, authentication, authorization, and queue sections documentation