What are Deferred Service Providers?

Why Interviewers Ask This

This is a differentiating question used for senior and lead roles. Interviewers want to see if you can explain not just what happens, but why — and what the trade-offs are in different approaches.

Answer

Deferred service providers are not loaded on every request — they are loaded only when one of their bindings is actually needed. Implement the DeferrableProvider interface and define a provides() method that lists the container bindings the provider registers. Laravel's bootstrap/cache/services.php file caches this mapping. When something in the container resolves a listed binding, only then is the provider loaded. This improves bootstrap performance for large applications with many service providers. Example: a PDF generation service provider is deferred — it only loads when you actually use the PDF generator, not on every request. Most first-party Laravel packages use deferred providers. Always run php artisan optimize in production to regenerate the cached services manifest.

Common Mistake

Rushing to answer is a common mistake. Take two seconds to structure your response: definition → example → trade-off. This structure makes complex Laravel answers easy to follow.