Weave 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 a token bucket implementation for rate limiting input and output in PHP applications. Configure policies and storage with RateLimiterFactory, then reserve tokens to wait or consume tokens to check acceptance.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • API Security & Abuse Prevention:

    • Replace ad-hoc rate-limiting solutions (e.g., sleep() delays, custom Redis scripts) with a maintainable, battle-tested Token Bucket implementation to mitigate brute-force attacks on /login, /reset-password, and /api/payments.
    • OWASP Top 10 compliance (A03:2021 Injection, A07:2021 Broken Authentication) via standardized rate limits (e.g., 5 attempts/minute for login).
    • Dynamic throttling for admin actions (e.g., DELETE /users/{id}) to prevent accidental data loss during traffic spikes.
    • Patched against burst-size over-permissiveness (v5.4.54, security release): burst capacity and its derived duration are now capped, so very large configured limits can no longer silently translate into oversized token buckets. Decision: treat ≥5.4.54 as the minimum supported version and re-validate that effective throttling matches the limits we advertise to customers and auditors.
  • SaaS Monetization & Tiered Access:

    • Paywall-enforced limits (e.g., free tier: 100 requests/hour, pro tier: 10K requests/hour) with zero backend refactoring by leveraging Laravel’s config() or environment variables.
    • Feature flag integration: Use RateLimiterFactory to gradually roll out APIs/features (e.g., limit to 1% of users via consume(1)) without custom logic.
    • A/B testing: Apply segmented rate limits (e.g., consume(1) for control group, consume(5) for treatment group) to test monetization strategies.
    • Billing-integrity check: the burst cap means enterprise-tier quotas now behave predictably under load — pricing pages and overage terms can be stated without a hidden "burst multiplier" caveat.
  • Compliance & Auditing:

    • Generate SOC 2 (CC7.1), PCI DSS (5.5), and GDPR (Article 32)-ready logs by integrating with Laravel’s Monolog and SIEM tools (Splunk, Datadog).
    • Track rate-limiting events for audit trails and anomaly detection (e.g., sudden spikes in /api/payments).
    • Vulnerability management evidence: this release gives us a concrete, dated artifact — a security patch shipped and applied within SLA — useful for SOC 2 CC7.1 change-management and dependency-patching controls.
  • Cost Optimization & Scalability:

    • Prevent resource exhaustion (database connections, external API calls) during traffic spikes, reducing AWS RDS costs and third-party API fees.
    • Serverless-friendly: Works seamlessly with Laravel on AWS Lambda, Bref, or Kubernetes, avoiding distributed lock contention.
    • Distributed rate limiting: Supports Redis/Memcached-backed storage for consistent limits across Laravel instances or microservices.
  • User Experience & Transparency:

    • Automatically inject HTTP Retry-After headers (RFC 6585) for API clients, improving developer experience and reducing support tickets.
    • Provide clear error responses (e.g., 429 Too Many Requests with Retry-After timestamps) for self-service recovery.
    • Expect a small, bounded behavior shift post-upgrade: clients that previously exploited large bursts may now receive 429 sooner. Worth a release note to top API consumers rather than a silent change.
  • Microservices & Distributed Systems:

    • Compound rate limiters: Enforce per-IP and per-user limits for multi-tenant SaaS using CompoundRateLimiterFactory.
    • Unified rate limiting: Standardize limits across APIs, queues, and CLI commands (e.g., Artisan tasks) without duplicating logic.
  • 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.
  • Operational/Release Decisions:

    • Patch now, low ceremony: v5.4.54 is a patch-level change on the 5.4 line (5.4.47 → 5.4.54) with no new APIs or deprecations — a routine dependency bump plus a re-run of throttle-related load tests, not a migration project.
    • Adopt a security-release intake policy: subscribe to Symfony security advisories and treat [SECURITY] releases as same-sprint upgrades; this is the difference between "we use a rate limiter" and "we can prove our rate limiter is current."

When to Consider This Package

  • Adopt when:

    • You need standardized, maintainable rate limiting in Laravel/Symfony with minimal code (e.g., <50 lines of configuration).
    • Your application requires distributed rate limiting (multi-AZ, Kubernetes, serverless) and you want to avoid custom Redis scripts or database locks.
    • You need 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, etc.).
    • You require SOC 2, PCI DSS, or GDPR compliance for rate-limiting events and audit trails.
    • You will pin a floor of ≥5.4.54 and can commit to applying future [SECURITY] releases on a defined cadence — the upstream project ships security fixes promptly, but it does not backport indefinitely, so a stale lockfile is the real risk.
  • Look elsewhere when:

    • You need advanced algorithms (e.g., Leaky Bucket, Fixed Window) beyond Token Bucket (though Symfony supports these via SlidingWindow and FixedWindow policies).
    • Your use case requires real-time analytics or machine learning-based rate limiting (e.g., detecting DDoS attacks).
    • You’re building a high-frequency trading (HFT) system where microsecond precision is critical (Token Bucket introduces slight delays).
    • You need rate limiting for WebSockets (though Symfony’s package can be extended with custom storage).
    • Your team lacks PHP/Laravel expertise and prefers a low-code/no-code solution (e.g., Cloudflare Rate Limiting, AWS WAF).
    • You require rate limiting for non-HTTP contexts (e.g., database queries, internal microservices) without HTTP headers.
    • You cannot operate a dependency-patching process — an unmaintained fork or frozen lockfile forfeits the main security benefit of adopting this package in the first place.

How to Pitch It (Stakeholders)

For Executives: *"Symfony’s Rate Limiter is a turnkey solution to secure our APIs, prevent abuse, and enable SaaS monetization—without custom development. It replaces fragile ad-hoc rate limiting (e.g., sleep() delays) with a maintainable, scalable Token Bucket implementation that:

  • Blocks brute-force attacks on login/payment flows (OWASP Top 10 compliance).
  • Enforces paywall tiers (free/pro) with zero backend changes.
  • Reduces AWS costs by preventing resource exhaustion during traffic spikes.
  • Integrates seamlessly with Laravel’s caching (Redis, database) for distributed systems.
  • Automates Retry-After headers for APIs, improving developer experience.
  • Ships security fixes fast — the latest patch (v5.4.54) closes a burst-size loophole that could have let a client exceed its intended allowance. Upgrading is a one-line version bump with no code changes; not upgrading is a known, documented exposure.

Implementation is trivial (50 lines of config), the upgrade is a patch-level bump, and it’s backed by Symfony’s security team—used in production by enterprises like Shopify and Symfony itself."

For Engineering: *"This package gives us:

  • Standardized rate limiting across APIs, queues, and CLI (no more duplicated logic).
  • Distributed support (Redis/Memcached) for multi-AZ/Kubernetes/serverless.
  • Compound limiters (per-IP and per-user) for multi-tenant SaaS.
  • HTTP compliance (Retry-After headers) for APIs.
  • Zero custom code—just configure policies (e.g., limit: 10, interval: '15 minutes').

Action from v5.4.54: this is a [SECURITY] patch that caps the burst size and the duration derived from it (#65747). No API changes, no deprecations on the 5.4 line — bump the constraint to ^5.4.54, run composer update symfony/rate-limiter, and re-run our login/payment throttle load tests. Audit any limiter config with an unusually large limit value: those are the ones whose effective burst envelope shrinks, so a few clients may see 429 earlier than before. Add us to the Symfony security advisory feed so the next one is same-sprint, not best-effort.

It’s lightweight, battle-tested (used in Symfony’s core), and actively maintained (releases every 2–3 months, security issues patched promptly). Let’s replace our custom Redis scripts with this—it’s more reliable and scalable."

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.
hsluv/hsluv
seampact/codegen
seampact/hooks
seampact/ir
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table
siberfx/flysystem-wasabi
hollyit/token-replace
ippanelcom/laravel-sdk
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support