ASP.NET Core Web API Interview Question #139
What is rate limiting in ASP.NET Core Web API?
Error Handling, Logging, Caching, Rate Limiting, CORS & Reliability Senior Advanced
Quick Interview Answer
Rate limiting restricts the number or rate of requests accepted for a client or partition. It can protect service capacity, reduce accidental overload, and enforce usage policies.
Detailed Explanation
Rate limiting restricts the number or rate of requests accepted for a client or partition. It can protect service capacity, reduce accidental overload, and enforce usage policies.
ASP.NET Core provides rate-limiting middleware with algorithms such as fixed window, sliding window, token bucket, and concurrency limiting.
Code Example
builder.Services.AddRateLimiter(options =>
{
options.AddFixedWindowLimiter("public-api", limiter =>
{
limiter.PermitLimit = 100;
limiter.Window = TimeSpan.FromMinutes(1);
});
});
app.UseRateLimiter();