What is Rate Limiting in Laravel?
Why Interviewers Ask This
This question targets practical, hands-on experience with Laravel. Interviewers want to see if you've worked with these concepts in real projects, not just read about them. Strong answers include concrete examples.
Answer
Rate limiting restricts how many times a user or IP can hit an endpoint within a time window. Apply the built-in throttle middleware: Route::middleware("throttle:60,1")->group(...) — 60 requests per minute. In Laravel 8+, define named rate limiters in RouteServiceProvider (or AppServiceProvider): RateLimiter::for("api", fn($request) => $request->user() ? Limit::perMinute(100)->by($request->user()->id) : Limit::perMinute(10)->by($request->ip())). Apply: Route::middleware("throttle:api"). Rate limiters can return custom responses on exceeded limits. The RateLimiter facade also provides attempt(), hit(), and tooManyAttempts() for manual rate limiting logic (e.g., login throttling).
Pro Tip
Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a Laravel codebase.