Atomic Team Creation vs. Asynchronous Invitation Dispatch in Laravel Jetstream
0 reputation · 03 Jun 2022, 09:59 UTC
When creating a new team through Laravel Jetstream’s TeamsRepository, the operation wraps user creation and team membership assignment in a single database transaction. However, the invitation email is dispatched outside that transaction, so a failure in the mail driver can leave a team record without a corresponding user or invitation entry.
The goal is to decide whether to keep the invitation dispatch inside the transaction to guarantee atomicity, accepting that a mail failure would roll back the entire team creation, or to keep it outside and rely on compensating mechanisms to clean up orphaned records.
Should invitation sending be included in the same database transaction? What are the user‑experience consequences of rolling back team creation on a mail failure? How can orphaned team records be prevented without sacrificing the atomicity guarantees of user and team membership?