A rate limit counted separately on each instance of your API lets through the limit multiplied by the instance count, which rises as you scale out. Most layers count locally: ASP.NET Core per instance, Azure Front Door per edge location, API Management per regional gateway. Use those for coarse protection, key signed-in limits on the account rather than the IP address, keep shared counters in a store such as Redis, and enforce exact business limits in the database.
Why does a rate limit stop working when you add instances?
A rate limit stops working because each instance counts only the requests it receives. If every instance allows 100 requests a minute and you run three, a client whose requests are spread across them can make up to 300.
Microsoft’s ASP.NET Core rate limiting documentation says this directly: the middleware keeps its counters in memory in each app instance, and the effective limit is the configured limit multiplied by the number of instances. Its own example is a limit of 100 a minute becoming up to 300 across three instances.
Autoscaling makes it worse. If your API scales out under load, the effective limit rises with every instance added, which tends to happen during the busy periods when the limit matters most. A limit that looked right in testing against one instance can be several times looser in production.
This is one of the gaps we look for when we review an API, alongside rules that the app enforces but the API does not. Our guide to why a pen test can pass while bots still get in covers why it rarely shows up in a penetration test.
Where does each layer count requests?
Each layer in a typical Azure API stack can enforce a rate limit, and each counts in a different place. None of the gateway and edge options shares a single exact counter across everything, which is fine for protection against floods and spikes but not for limits that must be exact.

- Azure Front Door WAF. Rate limit rules count requests per group over one or five minutes, grouped by socket IP address by default. Microsoft says counts are not shared between edge locations or aggregated globally, so a limit can be reached separately at each one. It also notes that low thresholds, below about 200 requests a minute, can let some requests through above the limit.
- Azure Application Gateway WAF v2. Counters are kept for each association, so a policy attached to three gateways keeps three sets, and Microsoft says thresholds are not always enforced exactly as defined.
- Azure API Management. The rate-limit and rate-limit-by-key policies track calls independently at each gateway, and in a multi-region deployment each regional gateway has a separate counter. Quota policies use a single counter for the whole instance. Microsoft adds that rate limiting is never completely accurate, because of the distributed nature of the throttling architecture.
- Your API code. In-process limiters, such as the ASP.NET Core middleware, count per instance unless you give them a shared store.
- A shared store. Counters held in Redis, or in your database, are shared by every instance that uses them, because there is only one copy.
The practical conclusion is to use edge and gateway limits to absorb floods and keep load predictable, and to put any limit that protects a business rule somewhere with a single counter.
Which key should a limit use?
A limit is only as good as the key it counts against, and for a mobile API the IP address is usually the weakest choice.
- IP address. Mobile networks commonly use carrier-grade NAT, which RFC 6888 describes as sharing a public IPv4 address among several subscribers. An IP limit can therefore throttle many real customers at once, while a script can spread its requests across many addresses. Microsoft’s API Management guidance makes the same point about NAT. IP limits still have a place on unauthenticated endpoints, such as sign-in, and at the edge.
- Account. For signed-in traffic, key on the user identity in the access token. API Management can read it with
context.Request.Headers.GetValueOrDefault("Authorization","").AsJwt()?.Subject, and the ASP.NET Core middleware can partition on the user’s identity. This is the right default for most mobile endpoints. - Attested app or device. App attestation tells you whether a request came from your genuine app, which lets you give unattested requests a tighter limit. It does not always give you a device key. With Apple App Attest, your server stores a public key for each user on each device, which you can count against. A Firebase App Check token’s subject is your app ID rather than a device, and Google’s Play Integrity device recall feature, in beta, is designed so the app can recall a few bits of data without accessing device identifiers. Our guide to App Attest and Play Integrity covers the details.
- Business keys. For scarce stock, count against the item or release as well as the account, such as two purchases per account per product drop. Our guide to customers using AI bots on scarce stock covers why these limits matter more now.
Avoid keying on values the client controls without checking them. Microsoft’s ASP.NET Core documentation warns that partitioning on unbounded user input creates a denial of service risk, because every new key creates and caches a new limiter.
How do you share one limit across every instance?
You share a limit by keeping one counter and making every instance read and update it. There are three common ways to do that, and they suit different kinds of limit.
Enforce it at a single gateway
If you run API Management in one region, its rate-limit-by-key policy gives you one counter per gateway in front of every API instance. That works well for protective limits, as long as you accept Microsoft’s caution that it is never completely accurate, and remember that a second region adds a second counter.
Keep counters in a shared store
For limits that need to hold across instances and regions, keep the counters in a shared cache such as Redis, where every instance increments the same key atomically with an expiry. Libraries exist for the common algorithms (fixed window, sliding window and token bucket), and the ASP.NET Core documentation recommends a shared store, or a gateway, for exactly this case.
Three details matter in practice:
- Decide what happens when the store is unavailable. Failing open keeps the API running without limits, and failing closed protects the business rule but blocks every customer. One middle course is to fall back to a looser per-instance limit until the store is back.
- Watch the extra round trip. Every limited request now makes a call to the store, so keep the store close to the API.
- Check your Redis plans. Microsoft is retiring Azure Cache for Redis, with the Basic, Standard and Premium tiers retiring on 30 September 2028 and Enterprise tiers on 31 March 2027. New work should use Azure Managed Redis.
Enforce exact business limits in the database
Some limits are business rules rather than protection: two tickets per customer, one claim per voucher, one referral reward per account. These need to be exact, so enforce them in the same database transaction that writes the purchase or claim, with the check and the write as one atomic step, rather than with a rate limiter that Microsoft itself describes as approximate.
In our experience, separating these two kinds of limit early saves a lot of rework, because protective limits can tolerate some inaccuracy and sit at the edge and gateway, while business limits need to be exact and sit with the data.
What should the API return when a limit is reached?
The API should return 429 Too Many Requests, which RFC 6585 defines for a client that has sent too many requests in a given time, with a Retry-After header saying how long to wait. The RFC also says a 429 response must not be stored by a cache.
Check what each layer actually sends. API Management’s rate-limit policies return 429 with a Retry-After header, but its quota-by-key policy returns 403 Forbidden, which a mobile app may treat as a permissions error. In ASP.NET Core, set the rejection status code to 429 explicitly and copy the retry-after value into the response in the rejection callback, as Microsoft’s documentation shows.
The IETF is standardising headers that tell clients their remaining allowance in advance. The RateLimit header fields draft defines RateLimit and RateLimit-Policy headers, and at the time of writing it is still an Internet-Draft rather than an RFC.
On the app side, respect Retry-After, back off rather than retrying at once, and show the customer a clear message. Our guide to mobile API best practices covers retry strategy for mobile clients.
How do you check that your limits hold?
You check that limits hold by testing them the way production runs, not against a single instance on a developer’s machine:
- List every limit and where it is enforced. Note the layer, the key, the window and whether the counter is per instance, per gateway, per edge location or shared.
- Test at production scale. Run a load test against an environment with the same instance count and regions as production, and measure how many requests get through compared with the configured limit.
- Test the business limits under contention. Send simultaneous requests for the same scarce item from one account and confirm the database rule holds.
- Log every limit decision. Record the key, the layer and the outcome, so you can see who a limit caught and tune it with evidence.
- Run new limits in a logging mode first. Where the layer supports it, record what a limit would have blocked before you let it block real customers.
How do we approach this?
We look at rate limiting as part of the whole path from the app to the data, because a limit only works if every route to the same action passes through it. Our mobile and API security review traces each exposed endpoint through the code, checks where limits are enforced and what they are keyed on, and uses your telemetry to see how they behave under real load.
We recommend changes sized to the real risk, which might be as small as moving one limit into a shared store, and we can make the changes across the app, the API and your Azure configuration. If you are building a new mobile backend, our mobile app backend services build this in from the start.
Frequently asked questions
Does Azure API Management share rate limit counters across regions?
Should a mobile API rate limit by IP address?
Is the ASP.NET Core rate limiting middleware enough?
What should an API return when a client hits a rate limit?
What is the difference between a rate limit and a quota?
Related guides
Mobile API Best Practices: Building Backends That Scale
How to design, secure, and operate APIs for mobile apps. Protocol choice, authentication flows, offline sync, push notifications, versioning, and Azure architecture patterns.
Mobile App Attestation: App Attest and Play Integrity
How to use Apple App Attest and Google Play Integrity to protect a mobile API, which endpoints to cover, and how to roll it out without locking out users.
Backend for Frontend (BFF): API Patterns for Mobile and Web Clients
When to use the BFF pattern, how it compares to a single API or API gateway, and how to implement it on Azure. Practical architecture for teams serving mobile, web, and internal clients.