Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Rate Limiter Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • API Security & Abuse Prevention:

    • Implement OWASP Top 10 compliant rate limiting for authentication flows (login, 2FA, password reset) to mitigate brute-force attacks (A03:2021 Injection, A07:2021 Broken Authentication).
    • Enforce per-endpoint limits (e.g., /api/payments = 10 requests/minute) to prevent scraping or abuse of sensitive operations.
    • Dynamic throttling for admin dashboards or high-risk actions (e.g., user deletions) to reduce accidental damage.
  • SaaS Monetization & Tiered Access:

    • Paywall-enforced limits (e.g., free tier: 100 requests/hour, pro tier: 10K requests/hour) with zero backend refactoring.
    • Feature flag integration: Use rate limiting to gradually roll out APIs/features (e.g., limit to 1% of users initially) via Laravel’s config() or environment variables.
    • A/B testing: Apply segmented rate limits (e.g., consume(1) for control group, consume(5) for treatment group) to test monetization strategies.
  • Compliance & Auditing:

    • Generate SOC 2 (CC7.1), PCI DSS (5.5), and GDPR (Article 32)-ready logs for rate-limiting events.
    • Integrates with Laravel’s Monolog for centralized monitoring and SIEM tools (Splunk, Datadog, ELK).
  • Cost Optimization & Scalability:

    • Prevent resource exhaustion (database connections, external API calls) during traffic spikes, reducing AWS RDS costs and third-party API fees.
    • Critical for serverless architectures (AWS Lambda, Bref) where cold starts and concurrency limits are a concern.
    • Distributed rate limiting across Laravel instances, Kubernetes pods, or serverless functions without distributed lock contention.
  • User Experience & Transparency:

    • Automatically inject HTTP Retry-After headers (RFC 6585) for API clients, improving developer experience.
    • Provide clear error responses (e.g., 429 Too Many Requests) with Retry-After timestamps for self-service recovery.
  • Microservices & Distributed Systems:

    • Supports Redis/Memcached-backed storage for consistent rate limiting across distributed environments.
    • Compound rate limiters (e.g., per-IP and per-user) for multi-tenant SaaS applications.
  • Roadmap Acceleration:

    • Chaos engineering: Simulate traffic spikes during load testing by dynamically adjusting limits via Laravel Horizon or Telescope.
    • Progressive delivery: Use rate limiting to canary release APIs/features to a subset of users before full rollout.

When to Consider This Package

  • Adopt when:

    • Your Laravel/Symfony application needs standardized, maintainable rate limiting with minimal code (e.g., <50 lines).
    • You require distributed rate limiting (multi-AZ, Kubernetes, serverless) and want to avoid custom Redis scripts or database locks.
    • Implementing HTTP-compliant rate limiting with Retry-After headers for API clients or RFC 6585 compliance.
    • Enforcing compound limits (e.g., per-IP and per-user) for multi-tenant SaaS using CompoundRateLimiterFactory.
    • Prioritizing security for auth/payment flows without custom development (e.g., replace ad-hoc sleep() delays).
    • Using Laravel’s throttle middleware and seeking a unified solution across APIs, queues, and CLI commands.
    • Planning global scaling with a solution that integrates into Laravel’s caching (Redis, database, file storage).
    • Requiring dynamic rate-limiting policies adjustable via config/rate_limits.php or environment variables.
    • Your team lacks bandwidth to maintain custom rate-limiting logic or wants to reduce technical debt.
  • Look elsewhere:

    • Non-PHP stacks: Use express-rate-limit (Node.js), ulule/limiter (Go), or django-ratelimit (Python).
    • Ultra-low-latency needs: If Redis/database storage adds latency, use InMemoryStorage (single-instance only).
    • Non-Laravel/Symfony: Teams using Drupal/WordPress may prefer NGINX rate limiting or Cloudflare WAF.
    • Legacy PHP (<8.1): Symfony 8+ requires PHP 8.1+ (check Symfony’s requirements).
    • Edge rate limiting: For CDN-level throttling, use Cloudflare Rate Limiting, AWS WAF, or Fastly.
    • High-frequency analytics: Dedicated tools (Kong, NGINX, AWS WAF) offer richer telemetry for dashboards.
    • Cost-sensitive micro-projects: If Redis/Memcached is overkill, use simple in-memory solutions (though they lack persistence).

How to Pitch It (Stakeholders)

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:

  • Block credential stuffing on login endpoints with a 5-attempt/5-minute limit, reducing fraud risk by ~30% (based on industry benchmarks).
  • Enforce tiered access for our SaaS (e.g., free tier: 100 requests/hour, enterprise: 100K requests/hour) with zero backend changes, unlocking new revenue streams.
  • Cut cloud costs by preventing database overload during traffic spikes (e.g., save ~20% on AWS RDS).
  • Comply with PCI DSS and GDPR with built-in auditing and logging, reducing audit overhead. The MIT license avoids licensing risks, and Symfony’s active maintenance ensures long-term reliability. This is a low-cost, high-impact fix for security, scalability, and revenue protection."*

For Engineering Teams: *"This package replaces spaghetti rate-limiting code with a battle-tested, Symfony-backed solution. Key advantages:

  • Token Bucket algorithm (industry standard) for smooth, predictable throttling.
  • Plug-and-play integration with Laravel’s middleware, queues, and CLI—no refactoring needed.
  • Redis/Memcached support for distributed environments (Kubernetes, serverless, multi-AZ).
  • Compound limiters for complex rules (e.g., per-user and per-IP) using CompoundRateLimiterFactory.
  • HTTP Retry-After headers for API clients, improving UX and reducing support tickets.
  • Dynamic configuration via config/rate_limits.php or env vars—adjust limits without redeploying.
  • Zero dependencies beyond Laravel/Symfony’s core (no bloat, easy to maintain).
  • Battle-hardened: Used in production by Symfony, Laravel, and thousands of apps. To implement:
  1. Install via Composer (composer require symfony/rate-limiter).
  2. Configure limits in config/rate_limits.php (e.g., ['login' => ['limit' => 5, 'interval' => '5 minutes']]).
  3. Apply to middleware, queues, or CLI commands.
  4. Done. No custom logic, no edge cases to debug. Trade-offs: In-memory storage lacks persistence (use Redis for production). For edge cases, we can extend with custom storage backends."*

For Security Teams: *"This addresses OWASP Top 10 risks (A03:2021 Injection, A07:2021 Broken Authentication) with:

  • Brute-force protection: Enforce limits on /login, /reset-password, and /2fa endpoints.
  • PCI DSS compliance: Log all rate-limiting events for audits (integrates with Monolog/SIEM).
  • Abuse prevention: Throttle sensitive endpoints (e.g., /api/payments, /admin/users) to prevent scraping or DoS.
  • No false positives: Token Bucket algorithm avoids abrupt blocking (unlike fixed windows). Recommendation: Deploy as a non-negotiable layer for all auth and payment flows. Pair with Laravel’s throttle middleware for APIs."*
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium