Skip to content
Written with Claude
IMPORTANT

As you may notice, this page and pretty much the entire website were obviously created with the help of AI. I wonder how you could tell? Was it a big "Written With Claude" badge on every page? I moved it to the top now (with the help of AI of course) to make it even more obvious. There are a few blogposts that were written by me manually, the old-fashioned way, I hope there will be more in the future, and those have a similar "Human Written" badge. This project (not the website), on the other hand, is a very, very different story. It took me more than two years of painstaking and unpaid work in my own free time. A story that, hopefully, I will tell someday. But meanwhile, what would you like me to do? To create a complex documentation website with a bunch of highly technical articles with the help of AI and fake it, to give you an illusion that I also did that manually? Like the half of itnernet is doing at this point? How does that makes any sense? Is that even fair to you? Or maybe to create this website manually, the old-fashioned way, just for you? While working a paid job for a salary, most of you wouldn't even get up in the morning. Would you like me to sing you a song while we're at it? For your personal entertainment? Seriously, get a grip. Do you find this information less valuable because of the way this website was created? I give my best to fix it to keep the information as accurate as possible, and I think it is very accurate at this point. If you find some mistakes, inaccurancies or problems, there is a comment section at the bottom of every page, which I also made with the help of the AI. And I woould very much appreciate if you leave your feedback there. Look, I'm just a guy who likes SQL, that's all. If you don't approve of how this website was constructed and the use of AI tools, I suggest closing this page and never wever coming back. And good riddance. And I would ban your access if I could know how. Thank you for your attention to this matter.

Rate Limiter

Rate limiting configuration to control the number of requests from clients. Apply policies to endpoints using the rate_limiter_policy annotation.

Overview

json
{
  "RateLimiterOptions": {
    "Enabled": false,
    "StatusCode": 429,
    "StatusMessage": "Too many requests. Please try again later.",
    "DefaultPolicy": null,
    "Policies": []
  }
}

Settings Reference

SettingTypeDefaultDescription
EnabledboolfalseEnable rate limiting.
StatusCodeint429HTTP status code returned when rate limit is exceeded.
StatusMessagestring"Too many requests. Please try again later."Response message when rate limit is exceeded.
DefaultPolicystringnullName of the default policy to apply to all endpoints.
Policiesarray[]List of rate limiting policies. Assign a policy to an endpoint using the rate_limiter_policy annotation.

Policy Types

Four policy types are available:

  • FixedWindow - Fixed time window rate limiting
  • SlidingWindow - Sliding time window rate limiting
  • TokenBucket - Token bucket algorithm
  • Concurrency - Concurrent request limiting

Fixed Window Policy

Limits requests within fixed time intervals.

json
{
  "Type": "FixedWindow",
  "Enabled": true,
  "Name": "fixed",
  "PermitLimit": 100,
  "WindowSeconds": 60,
  "QueueLimit": 10,
  "AutoReplenishment": true
}
SettingTypeDefaultDescription
Typestring-Must be "FixedWindow".
EnabledboolfalseEnable this policy.
Namestring-Policy name. Use this name with the rate_limiter_policy annotation to apply this policy to an endpoint.
PermitLimitint100Maximum requests allowed per window.
WindowSecondsint60Window duration in seconds.
QueueLimitint10Maximum queued requests when limit is reached.
AutoReplenishmentbooltrueAutomatically replenish permits.

See Fixed Window Limiter documentation.

Sliding Window Policy

Limits requests using a sliding time window with segments.

json
{
  "Type": "SlidingWindow",
  "Enabled": true,
  "Name": "sliding",
  "PermitLimit": 100,
  "WindowSeconds": 60,
  "SegmentsPerWindow": 6,
  "QueueLimit": 10,
  "AutoReplenishment": true
}
SettingTypeDefaultDescription
Typestring-Must be "SlidingWindow".
EnabledboolfalseEnable this policy.
Namestring-Policy name. Use this name with the rate_limiter_policy annotation to apply this policy to an endpoint.
PermitLimitint100Maximum requests allowed per window.
WindowSecondsint60Window duration in seconds.
SegmentsPerWindowint6Number of segments dividing the window.
QueueLimitint10Maximum queued requests when limit is reached.
AutoReplenishmentbooltrueAutomatically replenish permits.

See Sliding Window Limiter documentation.

Token Bucket Policy

Limits requests using the token bucket algorithm.

json
{
  "Type": "TokenBucket",
  "Enabled": true,
  "Name": "bucket",
  "TokenLimit": 100,
  "TokensPerPeriod": 10,
  "ReplenishmentPeriodSeconds": 10,
  "QueueLimit": 10,
  "AutoReplenishment": true
}
SettingTypeDefaultDescription
Typestring-Must be "TokenBucket".
EnabledboolfalseEnable this policy.
Namestring-Policy name. Use this name with the rate_limiter_policy annotation to apply this policy to an endpoint.
TokenLimitint100Maximum tokens in the bucket.
TokensPerPeriodint10Number of tokens to add per replenishment period.
ReplenishmentPeriodSecondsint10How often tokens are added to the bucket.
QueueLimitint10Maximum queued requests when limit is reached.
AutoReplenishmentbooltrueAutomatically replenish tokens.

See Token Bucket Limiter documentation.

Concurrency Policy

Limits the number of concurrent requests.

json
{
  "Type": "Concurrency",
  "Enabled": true,
  "Name": "concurrency",
  "PermitLimit": 10,
  "QueueLimit": 5,
  "OldestFirst": true
}
SettingTypeDefaultDescription
Typestring-Must be "Concurrency".
EnabledboolfalseEnable this policy.
Namestring-Policy name. Use this name with the rate_limiter_policy annotation to apply this policy to an endpoint.
PermitLimitint10Maximum concurrent requests.
QueueLimitint5Maximum queued requests when limit is reached.
OldestFirstbooltrueProcess queued requests oldest first.

See Concurrency Limiter documentation.

Complete Example

Configuration with multiple policies:

json
{
  "RateLimiterOptions": {
    "Enabled": true,
    "StatusCode": 429,
    "StatusMessage": "Too many requests. Please try again later.",
    "DefaultPolicy": "bucket",
    "Policies": [
      {
        "Type": "FixedWindow",
        "Enabled": true,
        "Name": "fixed",
        "PermitLimit": 100,
        "WindowSeconds": 60,
        "QueueLimit": 10,
        "AutoReplenishment": true
      },
      {
        "Type": "SlidingWindow",
        "Enabled": true,
        "Name": "sliding",
        "PermitLimit": 100,
        "WindowSeconds": 60,
        "SegmentsPerWindow": 6,
        "QueueLimit": 10,
        "AutoReplenishment": true
      },
      {
        "Type": "TokenBucket",
        "Enabled": true,
        "Name": "bucket",
        "TokenLimit": 100,
        "TokensPerPeriod": 10,
        "ReplenishmentPeriodSeconds": 10,
        "QueueLimit": 10,
        "AutoReplenishment": true
      },
      {
        "Type": "Concurrency",
        "Enabled": true,
        "Name": "concurrency",
        "PermitLimit": 10,
        "QueueLimit": 5,
        "OldestFirst": true
      }
    ]
  }
}

Next Steps

  • Server & SSL - Configure HTTPS and Kestrel web server
  • CORS - Configure Cross-Origin Resource Sharing

Comments

Released under the MIT License.