BACKEND ENGINEERING • OCT 2026

Laravel & PHP Production Architecture: Queues, Caching & Scalable Database Design

Laravel makes it remarkably fast to ship an initial MVP, but as an application grows to handle thousands of daily orders, multi-role permissions, and third-party API webhooks, putting all business logic inside Eloquent controllers quickly leads to slow responses and fragile code. Over the past several years building production web platforms, CRMs, and ecommerce backends, I have refined a practical architecture checklist that keeps Laravel codebases clean and fast.

1. Slim Controllers, FormRequests & Action/Service Classes

A controller method should never exceed 15-20 lines of code. Its sole responsibility is to receive an HTTP request, delegate validation to a dedicated FormRequest class, pass validated data to a focused Service or single-action class, and return a standardized view or JSON resource.

  • Validation Isolation: Move all validation rules and authorization checks into app/Http/Requests/StoreOrderRequest.php.
  • Reusable Domain Logic: When order creation lives inside OrderService::createOrder(), you can call the exact same tested method from a web controller, a REST API endpoint, or an Artisan CLI command.

2. Eliminating N+1 Eloquent Queries & Indexing Foreign Keys

90% of slow Laravel dashboards are caused by unindexed database columns or accidental N+1 query loops inside Blade or React API transformers:

  • Enable Model::preventLazyLoading(!app()->isProduction()) inside AppServiceProvider so N+1 queries are caught immediately during local development.
  • Select only the columns you actually render (e.g., Order::with('customer:id,name,email')->select(['id', 'customer_id', 'total', 'status', 'created_at'])->paginate(25)).
  • Add composite database indexes on columns frequently paired in WHERE and ORDER BY clauses, such as ['status', 'created_at'].

3. Offloading Slow Work to Background Queues

Never make a user wait for an SMTP email, PDF invoice generation, or third-party webhook call during an HTTP request. Dispatch queued jobs (`ShouldQueue`) so your server returns an HTTP response in under 100ms while background workers process heavy tasks asynchronously with automatic retry backoff.

Looking for a PHP / Laravel & Full Stack Engineer?
Explore my Selected Production Work or Get in Touch to discuss your web application architecture.
← Back to All Articles Open Free Online Tools →