Introduction
This is a series of two articles that will help you to learn about rate limiting and how can it be applied in a microservice or .net core API.
This series will cover the following things:
- What is rate limiting?
- Why do we use rate limiting?
- Real-world use-case of rate limiting
- Hands-on Lab – Create a WebAPI project and execute the API using swagger
- Hands-on Lab – Implement Rate limiting using the AspNetCoreRateLimit Nuget Package
- Difference between Rate Limiting and Throttling (To be covered in next Article)
- Hands-on Lab – Implement Rate limiting using a Custom Middleware (To be covered in the next Article)
What is Rate limiting?
- Rate limiting is the process of restricting the number of requests for a resource within a specific time window.
- Rate limiting is the concept of limiting the amount a resource can be accessed. For example, you know that a database your application accesses can handle 1000 requests per minute safely, but are not confident that it can handle more than that. So, you can put a rate limiter in your application that allows 1000 requests every minute and rejects any more requests before they can access the database. The rate limiting of your database allows your application to handle a safe number of requests without potentially causing failures from your database.
- A service provider offering an API for consumers will have limitations on requests made within a specified time window. For instance, each unique user/IP Address/Client key will have a limitation on the number of requests it can make to an API endpoint.
Why do we use Rate limiting?
- Rate limiting helps protect against malicious bot attacks. For example, a hacker can use bots to make repeated calls to an API endpoint. This renders the service unavailable for anyone else. This is known as the Denial of Service (DoS) attack.
- Another purpose of rate limiting is to regulate traffic to the API according to infrastructure availability. Such usage is more relevant to the cloud-based API services that utilize a “pay as you go” IaaS strategy with cloud providers.
Real-world use-case of Rate limiting
Public APIs use rate-limiting for commercial purposes to generate revenue. A common business model is to pay a certain subscription amount for leveraging the API. So, they can only make so many API calls before paying more for an upgraded plan.
Hands-on Lab – Create a WebAPI project and execute the API using swagger
Steps to be followed:
- Open VS 2022 and create a project
- Choose ASP.NET Core API as a template and create a directory











Join the conversation! Your thoughts help the community grow.