Laravel Advanced & Architecture
5-8 Years (Senior)
Hard
Production Scenario
How do you manage Database Transactions with external 3rd-party webhook triggers safely in Laravel?
Real-World Scenario / Incident Description
A transaction was committed, but an unhandled exception in an external Stripe webhook inside the transaction closure rolled back the database after Stripe had already charged the credit card.
376 views
•
Updated 1 hour ago
The Golden Rule: Never call external network APIs inside a database transaction
Use DB::afterCommit() callbacks:
DB::transaction(function () use ($order, $paymentData) {
$order->update(['status' => 'paid']);
PaymentTransaction::create([...]);
// Dispatch side-effects ONLY after database commit succeeds
DB::afterCommit(function () use ($order) {
SendInvoiceEmailJob::dispatch($order);
NotifyThirdPartyFulfillment::dispatch($order);
});
});
Related Concepts:
#Database Transactions
#Webhooks
#Stripe
#Consistency
More Laravel Advanced & Architecture Interview Questions
How does Laravel Octane handle state persistence across requests, and how do you prevent catastrophic memory leaks and data bleeding in singletons?
Read →
How do you prevent Deadlocks when processing concurrent financial transactions or inventory deductions across multiple queue workers in Laravel?
Read →
How does the Laravel Service Container resolve dependencies using Reflection, and what are the performance trade-offs in large applications?
Read →
How do you execute Zero-Downtime database migrations on tables with 50+ million rows without locking writes in production Laravel?
Read →
How do you architect Multi-Tenant database isolation in Laravel (Single DB vs Multi DB vs Schema Separation)?
Read →