ASP.NET Core's built-in rate limiter can be driven by a signed license instead of a hard-coded number: partition the limiter per customer, size each bucket from a requests-per-minute entitlement, and let a plan change rotate the budget without a restart.
Key points
- `PartitionedRateLimiter.Create<HttpContext, string>` builds one limiter per request from a partition key you compute.
- `GetLimit("requests-per-minute", fallback: 60)` fails closed to the free-tier floor; `"unlimited"` resolves to `long.MaxValue`.
- Putting the limit in the partition key rotates the bucket on renewal without evicting cached limiters.
- `QueueLimit = 0` rejects over-limit calls with 429 instead of queuing them and inflating tail latency.
- `OnRejected` reads `MetadataName.RetryAfter` to emit a `Retry-After` header plus a problem-details body.
- Buckets are per process: behind a load balancer the effective cap becomes R × instance count.
Why it matters
The team this hits hardest is the one running a multi-tenant API with paid tiers: today the marketing number and the enforced number usually live in two places, and the drift surfaces as a support ticket. Moving the cap into the signed license is the interesting part, and it also makes the limit testable, since the fallback path is a single value you can assert on. Check two things before adopting it: the entitlement call here is Keyright-specific, so the pattern has to be adapted to your own licensing backend, and per-process buckets mean a scaled-out deployment silently multiplies the promised rate by the instance count. If a gateway or API Management already sits in front, decide which layer owns the number. A vendor-written post, but the partition-key trick is worth reading.
Real-world use
- A multi-tenant API whose pricing page promises 60, 600 or unlimited requests per minute per plan
- A self-hosted single-node deployment where per-process buckets match the real capacity
- A render endpoint kept on a named policy while `/api/health` stays outside the limiter
- A customer upgrading mid-contract where the new rate must apply without a restart
This summary was generated by the agent from the original post on DEV Community: #aspnetcore. The full text and all rights belong to its author and publisher. Go to original