symfony/rate-limiter
Symfony Rate Limiter provides token bucket rate limiting for your app. Create limiters with RateLimiterFactory and a storage backend (e.g., in-memory), then reserve tokens with blocking waits or consume instantly to allow/skip work based on availability.
API Security & Abuse Prevention:
/api/payments = 10 requests/minute) to prevent scraping or abuse of sensitive operations.SaaS Monetization & Tiered Access:
config() or environment variables.consume(1) for control group, consume(5) for treatment group) to test monetization strategies.Compliance & Auditing:
Cost Optimization & Scalability:
User Experience & Transparency:
Retry-After headers (RFC 6585) for API clients, improving developer experience.429 Too Many Requests) with Retry-After timestamps for self-service recovery.Microservices & Distributed Systems:
Roadmap Acceleration:
Adopt when:
Retry-After headers for API clients or RFC 6585 compliance.CompoundRateLimiterFactory.sleep() delays).throttle middleware and seeking a unified solution across APIs, queues, and CLI commands.config/rate_limits.php or environment variables.Look elsewhere:
express-rate-limit (Node.js), ulule/limiter (Go), or django-ratelimit (Python).InMemoryStorage (single-instance only).For Executives:
*"Symfony’s Rate Limiter is a turnkey solution to secure our APIs, prevent abuse, and enable scalable monetization—without custom development. It’s already integrated into Laravel’s core (throttle middleware), so adoption is seamless. Here’s the impact:
For Engineering Teams: *"This package replaces spaghetti rate-limiting code with a battle-tested, Symfony-backed solution. Key advantages:
CompoundRateLimiterFactory.Retry-After headers for API clients, improving UX and reducing support tickets.config/rate_limits.php or env vars—adjust limits without redeploying.composer require symfony/rate-limiter).config/rate_limits.php (e.g., ['login' => ['limit' => 5, 'interval' => '5 minutes']]).For Security Teams: *"This addresses OWASP Top 10 risks (A03:2021 Injection, A07:2021 Broken Authentication) with:
/login, /reset-password, and /2fa endpoints./api/payments, /admin/users) to prevent scraping or DoS.throttle middleware for APIs."*How can I help you explore Laravel packages today?