Laravel Advanced & Architecture
5-8 Years (Senior)
Medium
Production Scenario
How do you monitor and handle Slow Query alerts in real-time in Laravel production?
Real-World Scenario / Incident Description
You need an automated Slack/Sentry alert whenever any database query takes longer than 500ms in production.
287 views
•
Updated 1 month ago
Using DB::whenQueryingForLongerThan
In AppServiceProvider::boot():
DB::whenQueryingForLongerThan(500, function (Connection $connection) {
Log::warning("Database query exceeded 500ms on [{$connection->getName()}]");
// Send alert to Sentry or Slack webhook
});
Related Concepts:
#Monitoring
#Database
#Performance
#DB Listeners
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 →