ASP.NET Core Web API Interview Question #73

What is rate limiting and why is it useful for APIs?

Authentication, Authorization, JWT & API Security Mid-Level Intermediate

Quick Interview Answer

Rate limiting controls how many requests a client or partition may make within defined limits. It can protect service capacity, reduce accidental overload, limit some forms of abuse, and enforce product usage policies.

Detailed Explanation

Rate limiting controls how many requests a client or partition may make within defined limits. It can protect service capacity, reduce accidental overload, limit some forms of abuse, and enforce product usage policies.

Rate limiting is not a replacement for authentication, authorization, or infrastructure-level denial-of-service protection. Limits should be designed around endpoint cost and legitimate client behavior.

Code Example

builder.Services.AddRateLimiter(options =>
{
    options.AddFixedWindowLimiter("api", limiter =>
    {
        limiter.PermitLimit = 100;
        limiter.Window = TimeSpan.FromMinutes(1);
    });
});

app.UseRateLimiter();