From a544a5a2ecfb37f53606c24d4cab229745a8236e Mon Sep 17 00:00:00 2001 From: Roberto Polli Date: Thu, 17 Nov 2022 18:48:09 +0100 Subject: [PATCH 01/28] Fix: #64. Combine header. --- draft-ietf-httpapi-ratelimit-headers.md | 313 ++++++++++++------------ 1 file changed, 155 insertions(+), 158 deletions(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index 4ea87b2..850b520 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -51,7 +51,7 @@ informative: --- abstract -This document defines the RateLimit-Limit, RateLimit-Remaining, RateLimit-Reset and RateLimit-Policy HTTP header fields for servers to advertise their current service rate limits, thereby allowing clients to avoid being throttled. +This document defines the RateLimit and RateLimit-Policy HTTP header fields for servers to advertise their current service rate limits, thereby allowing clients to avoid being throttled. --- middle @@ -61,14 +61,15 @@ Rate limiting HTTP clients has become a widespread practice, especially for HTTP Currently, there is no standard way for servers to communicate quotas so that clients can throttle its requests to prevent errors. This document defines a set of standard HTTP header fields to enable rate limiting: -- RateLimit-Limit: the server's quota for requests by the client in the time window, -- RateLimit-Remaining: the remaining quota in the current window, -- RateLimit-Reset: the time remaining in the current window, specified in seconds, and +- RateLimit: to convey + the server's quota for requests by the client in the time window, + the remaining quota in the current window, + and the time remaining in the current window, specified in seconds, and - RateLimit-Policy: the quota policy. These fields allow the establishment of complex rate limiting policies, including using multiple and variable time windows and dynamic quotas, and implementing concurrency limits. -The behavior of the RateLimit-Reset header field is compatible with the delay-seconds notation of Retry-After. +The behavior of the RateLimit header field is compatible with the delay-seconds notation of Retry-After. ## Goals {#goals} @@ -192,122 +193,144 @@ For example, two quota policies containing further details via extension paramet ~~~ - - # RateLimit header field Definitions The following RateLimit response header fields are defined. -## RateLimit-Limit {#ratelimit-limit-field} +## RateLimit {#ratelimit-field} + +A server uses the "RateLimit" response header field to communicate its quota policies. + +The field is a Dictionary. The allowed keys are defined in the "Hypertext Transfer Protocol (HTTP) RateLimit Keywords and Parameters Registry", as described in {{iana-ratelimit-parameters}}. -The "RateLimit-Limit" response header field indicates the [service limit](#service-limit) associated with the client in the current [time window](#time-window). If the client exceeds that limit, it MAY not be served. +The following Keys are defined in this specification: + + limit: + : The REQUIRED "limit" key value conveys + the expiring limit ({{ratelimit-limit-keyword}}). + remaining: + : The OPTIONAL "remaining" key value conveys + the remaining quota units ({{ratelimit-remaining-keyword}}). + reset: + : The REQUIRED "reset" key value conveys + the time window reset time ({{ratelimit-reset-keyword}}). -The field is an Item and its value is a non-negative Integer referred to as the "expiring-limit". This specification does not define Parameters for this field. If they appear, they MUST be ignored. -The expiring-limit MUST be set to the service limit that is closest to reaching its limit, and the associated time window MUST either be: +This field cannot appear in a trailer section. + +## Limit Keyword {#ratelimit-limit-keyword} + +The "limit" keyword indicates the [service limit](#service-limit) associated with the client in the current [time window](#time-window). If the client exceeds that limit, it MAY not be served. -- inferred by the value of RateLimit-Reset header field at the moment of the reset, or +It is an Item and its value is a non-negative Integer referred to as the "expiring limit". +This specification does not define Parameters for it. +If they appear, they MUST be ignored. + +The expiring limit MUST be set to the service limit that is closest to reaching its limit, and the associated time window MUST either be: + +- inferred by the value of the [reset keyword](#ratelimit-reset-keyword) at the moment of the reset, or - communicated out-of-band (e.g. in the documentation). Example: ~~~ example - RateLimit-Limit: 100 + limit=100 ~~~ The RateLimit-Policy header field (see {{ratelimit-policy-field}}), might contain information on the associated time window. -This field cannot appear in a trailer section. -## RateLimit-Policy {#ratelimit-policy-field} +## Remaining Keyword {#ratelimit-remaining-keyword} -The "RateLimit-Policy" response header field indicates the quota policies currently associated with the client. Its value is informative. +The "remaining" keyword indicates the remaining quota units associated with the expiring-limit. -The field is a non-empty List of Items. Each item is a [quota policy](#quota-policy). +It is an Item and its value is a non-negative Integer expressed in [quota units](#service-limit). +This specification does not define Parameters for it. +If they appear, they MUST be ignored. -This field can convey the time window associated with the expiring-limit, as shown in this example: +Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. -~~~ example - RateLimit-Policy: 100;w=10 - RateLimit-Limit: 100 -~~~ +When the value of the remaining keyword is low, it indicates that the server may soon throttle the client (see {{providing-ratelimit-fields}}). -These examples show multiple policies being returned: +For example: ~~~ example - RateLimit-Policy: 10;w=1, 50;w=60, 1000;w=3600, 5000;w=86400 - RateLimit-Policy: 10;w=1;burst=1000, 1000;w=3600 + remaining=50 ~~~ -This field cannot appear in a trailer section. -## RateLimit-Remaining {#ratelimit-remaining-field} +## Reset Keyword {#ratelimit-reset-keyword} -The "RateLimit-Remaining" response header field indicates the remaining quota units associated with the expiring-limit. +The "reset" keyword indicates the number of seconds until the quota associated with the expiring-limit resets. -The field is an Item and its value is a non-negative Integer expressed in [quota units](#service-limit). -This specification does not define Parameters for this field. -If they appear, they MUST be ignored. +It is a non-negative Integer compatible with the delay-seconds rule, because: -Clients MUST NOT assume that a positive RateLimit-Remaining header field value is a guarantee that further requests will be served. +- it does not rely on clock synchronization and is resilient to clock adjustment + and clock skew between client and server (see {{Section 5.6.7 of HTTP}}); +- it mitigates the risk related to thundering herd when too many clients are serviced with the same timestamp. -When the value of RateLimit-Remaining is low, it indicates that the server may soon throttle the client (see {{providing-ratelimit-fields}}). +This specification does not define Parameters for it. +If they appear, they MUST be ignored. For example: ~~~ example - RateLimit-Remaining: 50 + reset=50 ~~~ -This field cannot appear in a trailer section. +The client MUST NOT assume that all its service limit will be reset at the moment indicated by the reset keyword. The server MAY arbitrarily alter the reset keyword value between subsequent requests; for example, in case of resource saturation or to implement sliding window policies. -## RateLimit-Reset {#ratelimit-reset-field} -The "RateLimit-Reset" response header field indicates the number of seconds until the quota associated with the expiring-limit resets. +## RateLimit-Policy {#ratelimit-policy-field} -The field is a non-negative Integer compatible with the delay-seconds rule, because: +The "RateLimit-Policy" response header field indicates the quota policies currently associated with the client. Its value is informative. -- it does not rely on clock synchronization and is resilient to clock adjustment - and clock skew between client and server (see {{Section 5.6.7 of HTTP}}); -- it mitigates the risk related to thundering herd when too many clients are serviced with the same timestamp. +The field is a non-empty List of Items. Each item is a [quota policy](#quota-policy). +Two quota policies MUST NOT be associated with the same quota units value. -This specification does not define Parameters for this field. -If they appear, they MUST be ignored. +This field can convey the time window associated with the expiring-limit, as shown in this example: -For example: +~~~ example + RateLimit-Policy: 100;w=10 + RateLimit: limit=100, remaining=50, reset=5 +~~~ + +These examples show multiple policies being returned: ~~~ example - RateLimit-Reset: 50 + RateLimit-Policy: 10;w=1, 50;w=60, 1000;w=3600, 5000;w=86400 + RateLimit-Policy: 10;w=1;burst=1000, 1000;w=3600 ~~~ -The client MUST NOT assume that all its service limit will be reset at the moment indicated by the RateLimit-Reset header field. The server MAY arbitrarily alter the RateLimit-Reset header field value between subsequent requests; for example, in case of resource saturation or to implement sliding window policies. +An example of invalid header field value with two policies associated with the same quota units: + +~~~ example + RateLimit-Policy: 10;w=1, 10;w=60 +~~~ This field cannot appear in a trailer section. -# Server Behavior {#providing-ratelimit-fields} -A server uses the RateLimit header fields to communicate its quota policies. Sending the RateLimit-Limit and RateLimit-Reset header fields is REQUIRED; sending RateLimit-Remaining header field is RECOMMENDED. +# Server Behavior {#providing-ratelimit-fields} A server MAY return RateLimit header fields independently of the response status code. This includes on throttled responses. This document does not mandate any correlation between the RateLimit header field values and the returned status code. -Servers should be careful when returning RateLimit header fields in redirection responses (i.e., responses with 3xx status codes) because a low RateLimit-Remaining header field value could prevent the client from issuing requests. For example, given the RateLimit header fields below, a client could decide to wait 10 seconds before following the "Location" header field (see {{Section 10.2.2 of HTTP}}), because the RateLimit-Remaining header field value is 0. +Servers should be careful when returning RateLimit header fields in redirection responses (i.e., responses with 3xx status codes) because a low remaining keyword value could prevent the client from issuing requests. For example, given the RateLimit header fields below, a client could decide to wait 10 seconds before following the "Location" header field (see {{Section 10.2.2 of HTTP}}), because the remaining keyword value is 0. ~~~ http-message HTTP/1.1 301 Moved Permanently Location: /foo/123 -RateLimit-Remaining: 0 -RateLimit-Limit: 10 -RateLimit-Reset: 10 +RateLimit: limit=10, remaining=0, reset=10 ~~~ -If a response contains both the Retry-After and the RateLimit-Reset header fields, the RateLimit-Reset header field value SHOULD reference the same point in time as the Retry-After field value. +If a response contains both the Retry-After and the RateLimit header fields, the reset keyword value SHOULD reference the same point in time as the Retry-After field value. -When using a policy involving more than one time window, the server MUST reply with the RateLimit header fields related to the time window with the lower RateLimit-Remaining header field values. +When using a policy involving more than one time window, the server MUST reply with the RateLimit header fields related to the time window with the lower remaining keyword values. -A service using RateLimit header fields MUST NOT convey values exposing an unwanted volume of requests and SHOULD implement mechanisms to cap the ratio between RateLimit-Remaining and RateLimit-Reset header field values (see {{sec-resource-exhaustion}}); this is especially important when a quota policy uses a large time window. +A service using RateLimit header fields MUST NOT convey values exposing an unwanted volume of requests and SHOULD implement mechanisms to cap the ratio between the remaining and the reset keyword values (see {{sec-resource-exhaustion}}); this is especially important when a quota policy uses a large time window. Under certain conditions, a server MAY artificially lower RateLimit header field values between subsequent requests, e.g. to respond to Denial of Service attacks or in case of resource saturation. @@ -325,9 +348,7 @@ The RateLimit header fields can be used by clients to determine whether the asso For example, a successful response with the following fields: ~~~ example - RateLimit-Limit: 10 - RateLimit-Remaining: 1 - RateLimit-Reset: 7 + RateLimit: limit=10, remaining=1, reset=7 ~~~ does not guarantee that the next request will be successful. Servers' behavior may be subject to other conditions like the one shown in the example from {{service-limit}}. @@ -340,15 +361,15 @@ A client receiving RateLimit header fields MUST NOT assume that future responses Malformed RateLimit header fields MUST be ignored. -A client SHOULD NOT exceed the quota units conveyed by the RateLimit-Remaining header field before the time window expressed in RateLimit-Reset header field. +A client SHOULD NOT exceed the quota units conveyed by the remaining keyword before the time window expressed in the reset keyword. -A client MAY still probe the server if the RateLimit-Reset header field is considered too high. +A client MAY still probe the server if the reset keyword is considered too high. -The value of the RateLimit-Reset header field is generated at response time: a client aware of a significant network latency MAY behave accordingly and use other information (e.g. the "Date" response header field, or otherwise gathered metrics) to better estimate the RateLimit-Reset header field moment intended by the server. +The value of the reset keyword is generated at response time: a client aware of a significant network latency MAY behave accordingly and use other information (e.g. the "Date" response header field, or otherwise gathered metrics) to better estimate the reset keyword moment intended by the server. The details provided in the RateLimit-Policy header field are informative and MAY be ignored. -If a response contains both the RateLimit-Reset and Retry-After fields, the Retry-After field MUST take precedence and the RateLimit-Reset header field MAY be ignored. +If a response contains both the RateLimit and Retry-After fields, the Retry-After field MUST take precedence and the reset keyword MAY be ignored. This specification does not mandate a specific throttling behavior and implementers can adopt their preferred policies, including: @@ -407,32 +428,32 @@ to the user agent. RateLimit header fields convey hints from the server to the clients in order to help them avoid being throttled out. -Clients MUST NOT consider the [quota units](#service-limit) returned in RateLimit-Remaining header field as a service level agreement. +Clients MUST NOT consider the [quota units](#service-limit) returned in remaining keyword as a service level agreement. In case of resource saturation, the server MAY artificially lower the returned values or not serve the request regardless of the advertised quotas. -## Reliability of RateLimit-Reset {#sec-reset-reliability} +## Reliability of the reset keyword {#sec-reset-reliability} -Consider that service limit might not be restored after the moment referenced by RateLimit-Reset header field, -and the RateLimit-Reset header field value may not be fixed nor constant. +Consider that service limit might not be restored after the moment referenced by the [reset keyword](#ratelimit-reset-keyword), +and the reset keyword value may not be fixed nor constant. -Subsequent requests might return a higher RateLimit-Reset header field value +Subsequent requests might return a higher reset keyword value to limit concurrency or implement dynamic or adaptive throttling policies. ## Resource exhaustion {#sec-resource-exhaustion} -When returning RateLimit-Reset header field you must be aware that +When returning reset keyword you must be aware that many throttled clients may come back at the very moment specified. This is true for Retry-After too. For example, if the quota resets every day at `18:00:00` -and your server returns the RateLimit-Reset header field accordingly +and your server returns the reset keyword accordingly ~~~ example Date: Tue, 15 Nov 1994 08:00:00 GMT - RateLimit-Reset: 36000 + RateLimit: limit=1, remaining=1, reset=36000 ~~~ there's a high probability that all clients will show up at `18:00:00`. @@ -447,38 +468,36 @@ The following example describes a service with an unconsumed quota policy of 10000 quota units per 1000 seconds. ~~~ example -RateLimit-Limit: 10000 +RateLimit: limit=10000, remaining=10000, reset=10 RateLimit-Policy: 10000;w=1000 -RateLimit-Remaining: 10000 -RateLimit-Reset: 10 ~~~ -A client implementing a simple ratio between RateLimit-Remaining header field and -RateLimit-Reset header field could infer an average throughput of 1000 quota units per second, -while the RateLimit-Limit header field conveys a quota-policy +A client implementing a simple ratio between remaining keyword and +reset keyword could infer an average throughput of 1000 quota units per second, +while the limit keyword conveys a quota-policy with an average of 10 quota units per second. If the service cannot handle such load, it should return -either a lower RateLimit-Remaining header field value -or an higher RateLimit-Reset header field value. +either a lower remaining keyword value +or an higher reset keyword value. Moreover, complementing large time window quota policies with a short time window one mitigates those risks. ### Denial of Service {#sec-dos} RateLimit header fields may contain unexpected values by chance or on purpose. -For example, an excessively high RateLimit-Remaining header field value may be: +For example, an excessively high remaining keyword value may be: - used by a malicious intermediary to trigger a Denial of Service attack or consume client resources boosting its requests; - passed by a misconfigured server; -or a high RateLimit-Reset header field value could inhibit clients to contact the server (e.g. similarly to receiving "Retry-after: 1000000"). +or a high reset keyword value could inhibit clients to contact the server (e.g. similarly to receiving "Retry-after: 1000000"). To mitigate this risk, clients can set thresholds that they consider reasonable in terms of quota units, time window, concurrent requests or throughput, and define a consistent behavior when the RateLimit exceed those thresholds. For example this means capping the maximum number of request per second, -or implementing retries when the RateLimit-Reset exceeds ten minutes. +or implementing retries when the reset keyword exceeds ten minutes. The considerations above are not limited to RateLimit header fields, but apply to all fields affecting how clients behave @@ -510,17 +529,15 @@ Please add the following entries to the |---------------------|-----------|---------------| | Field Name | Status | Specification | |---------------------|-----------|---------------| -| RateLimit-Limit | permanent | {{ratelimit-limit-field}} of {{&SELF}} | -| RateLimit-Remaining | permanent | {{ratelimit-remaining-field}} of {{&SELF}} | -| RateLimit-Reset | permanent | {{ratelimit-reset-field}} of {{&SELF}} | +| RateLimit | permanent | {{ratelimit-field}} of {{&SELF}} | | RateLimit-Policy | permanent | {{ratelimit-policy-field}} of {{&SELF}} | |---------------------|-----------|---------------| -## RateLimit Parameters Registration {#iana-ratelimit-parameters} +## RateLimit Keywords and Parameters Registration {#iana-ratelimit-parameters} IANA is requested to create a new registry to be called -"Hypertext Transfer Protocol (HTTP) RateLimit Parameters Registry", +"Hypertext Transfer Protocol (HTTP) RateLimit Keywords and Parameters Registry", to be located at . Registration is done on the advice of a Designated Expert, @@ -529,8 +546,11 @@ All entries are Specification Required ({{IANA, Section 4.6}}). Registration requests consist of the following information: -- Parameter name: - The parameter name, conforming to {{STRUCTURED-FIELDS}}. +- Token name: + The keyword or parameter name, conforming to {{STRUCTURED-FIELDS}}. + +- Token type: + Whether the token is a Dictionary Keyword or a Parameter Name. - Field name: The RateLimit header field for which the parameter is registered. If a parameter is intended to be used @@ -549,11 +569,14 @@ Registration requests consist of the following information: The initial contents of this registry should be: -|---|---|---|---| -| Field Name | Parameter name | Description | Specification | Comments (optional) | -|---|---|---|---| -| RateLimit-Policy | w | Time window | {{quota-policy}} of {{&SELF}} | | -|---|---|---|---| +|---|---|---|---|---|---| +| Field Name | Token name | Token type | Description | Specification | Comments (optional) | +|---|---|---|---|---|---| +| RateLimit | limit | Dictionary Key |Expiring limit | {{ratelimit-limit-keyword}} of {{&SELF}} | | +| RateLimit | remaining | Dictionary Key |Remaining quota units | {{ratelimit-remaining-keyword}} of {{&SELF}} | | +| RateLimit | reset | Dictionary Key |Quota reset interval | {{ratelimit-reset-keyword}} of {{&SELF}} | | +| RateLimit-Policy | w | Parameter name |Time window | {{quota-policy}} of {{&SELF}} | | +|---|---|---|---|---|---| --- back @@ -623,9 +646,7 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -RateLimit-Limit: 100 -Ratelimit-Remaining: 0 -Ratelimit-Reset: 50 +RateLimit: limit=100, remaining=0, reset=50 {"hello": "world"} ~~~ @@ -634,7 +655,7 @@ Since the field values are not necessarily correlated with the response status code, a subsequent request is not required to fail. The example below shows that the server decided to serve the request -even if RateLimit-Remaining header field value is 0. +even if remaining keyword value is 0. Another server, or the same server under other load conditions, could have decided to throttle the request instead. Request: @@ -650,9 +671,7 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -RateLimit-Limit: 100 -Ratelimit-Remaining: 0 -Ratelimit-Reset: 48 +RateLimit: limit=100, remaining=0, reset=48 {"still": "successful"} ~~~ @@ -692,9 +711,7 @@ HTTP/1.1 200 Ok Content-Type: application/json acme-RateLimit-DayLimit: 5000 acme-RateLimit-HourLimit: 1000 -RateLimit-Limit: 5000 -RateLimit-Remaining: 100 -RateLimit-Reset: 36000 +RateLimit: limit=5000, remaining=100, reset=36000 {"hello": "world"} ~~~ @@ -707,7 +724,7 @@ in case of saturation, thus increasing availability. The server adopted a basic policy of 100 quota units per minute, and in case of resource exhaustion adapts the returned values -reducing both RateLimit-Limit and RateLimit-Remaining header field values. +reducing both limit and remaining keyword values. After 2 seconds the client consumed 40 quota units @@ -724,15 +741,13 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -RateLimit-Limit: 100 -RateLimit-Remaining: 60 -RateLimit-Reset: 58 +RateLimit: limit=100, remaining=60, reset=58 {"elapsed": 2, "issued": 40} ~~~ At the subsequent request - due to resource exhaustion - -the server advertises only `RateLimit-Remaining: 20`. +the server advertises only `remaining=20`. Request: @@ -747,9 +762,7 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -RateLimit-Limit: 100 -RateLimit-Remaining: 20 -RateLimit-Reset: 56 +RateLimit: limit=100, remaining=20, reset=56 {"elapsed": 4, "issued": 41} ~~~ @@ -759,7 +772,7 @@ RateLimit-Reset: 56 A client exhausted its quota and the server throttles it sending Retry-After. -In this example, the values of Retry-After and RateLimit-Reset header field reference the same moment, +In this example, the values of Retry-After and RateLimit header field reference the same moment, but this is not a requirement. The 429 (Too Many Request) HTTP status code is just used as an example. @@ -779,9 +792,7 @@ HTTP/1.1 429 Too Many Requests Content-Type: application/json Date: Mon, 05 Aug 2019 09:27:00 GMT Retry-After: Mon, 05 Aug 2019 09:27:05 GMT -RateLimit-Reset: 5 -RateLimit-Limit: 100 -Ratelimit-Remaining: 0 +RateLimit: limit=100, remaining=0, reset=5 { "title": "Too Many Requests", @@ -810,27 +821,25 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -RateLimit-Limit: 100 +RateLimit: limit=100, remaining=99, reset=50 RateLimit-Policy: 100;w=60 -Ratelimit-Remaining: 99 -Ratelimit-Reset: 50 - {"hello": "world"} ~~~ + ### Dynamic limits with parameterized windows -The policy conveyed by the RateLimit-Limit header field states that +The policy conveyed by the RateLimit header field states that the server accepts 100 quota units per minute. To avoid resource exhaustion, the server artificially lowers the actual limits returned in the throttling headers. -The RateLimit-Remaining header field then advertises +The remaining keyword then advertises only 9 quota units for the next 50 seconds to slow down the client. Note that the server could have lowered even the other -values in the RateLimit-Limit header field: this specification +values in the RateLimit header field: this specification does not mandate any relation between the field values contained in subsequent responses. @@ -847,10 +856,8 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -RateLimit-Limit: 10 +RateLimit: limit=10, remaining=9, reset=50 RateLimit-Policy: 100;w=60 -Ratelimit-Remaining: 9 -Ratelimit-Reset: 50 { "status": 200, @@ -862,7 +869,7 @@ Ratelimit-Reset: 50 Continuing the previous example, let's say the client waits 10 seconds and performs a new request which, due to resource exhaustion, the server rejects -and pushes back, advertising `RateLimit-Remaining: 0` for the next 20 seconds. +and pushes back, advertising `remaining=0` for the next 20 seconds. The server advertises a smaller window with a lower limit to slow down the client for the rest of its original window after the 20 seconds elapse. @@ -880,10 +887,8 @@ Response: ~~~ http-message HTTP/1.1 429 Too Many Requests Content-Type: application/json -RateLimit-Limit: 0 +RateLimit: limit=0, remaining=0, reset=20 RateLimit-Policy: 15;w=20 -Ratelimit-Remaining: 0 -Ratelimit-Reset: 20 { "status": 429, @@ -915,10 +920,8 @@ Response: HTTP/1.1 429 Too Many Requests Content-Type: application/json Retry-After: 20 -RateLimit-Limit: 15 +RateLimit: limit=15, remaining=15, reset=40 RateLimit-Policy: 100;w=60 -Ratelimit-Remaining: 15 -Ratelimit-Reset: 40 { "status": 429, @@ -934,12 +937,12 @@ query again the server even if it is likely to have the request rejected. ### Missing Remaining information -The server does not expose RateLimit-Remaining header field values +The server does not expose remaining keyword values (for example, because the underlying counters are not available). Instead, it resets the limit counter every second. It communicates to the client the limit of 10 quota units per second -always returning the couple RateLimit-Limit and RateLimit-Reset header field. +always returning the limit and reset keywords. Request: @@ -954,8 +957,7 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -RateLimit-Limit: 10 -Ratelimit-Reset: 1 +RateLimit: limit=10, reset=1 {"first": "request"} ~~~ @@ -973,8 +975,7 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -RateLimit-Limit: 10 -Ratelimit-Reset: 1 +RateLimit: limit=10, reset=1 {"second": "request"} ~~~ @@ -1011,10 +1012,8 @@ Response: ~~~ http-message HTTP/1.1 200 OK Content-Type: application/json -RateLimit-Limit: 5000 +RateLimit: limit=5000, remaining=100, reset=36000 RateLimit-Policy: 1000;w=3600, 5000;w=86400 -RateLimit-Remaining: 100 -RateLimit-Reset: 36000 {"hello": "world"} ~~~ @@ -1081,7 +1080,7 @@ RateLimit-Reset: 36000 While this might be of some value, my experience suggests that overly-complex quota implementations results in lower effectiveness of this policy. This spec allows the client to easily focusing on - RateLimit-Remaining and RateLimit-Reset. + the remaining and reset keywords. 7. Shouldn't I limit concurrency instead of request rate? @@ -1101,26 +1100,24 @@ RateLimit-Reset: 36000 Saturation conditions can be either dynamic or static: all this is out of the scope for the current document. -8. Do a positive value of RateLimit-Remaining header field imply any service guarantee for my +8. Do a positive value of remaining keyword imply any service guarantee for my future requests to be served? - No. FAQ integrated in {{ratelimit-remaining-field}}. + No. FAQ integrated in {{ratelimit-remaining-keyword}}. 9. Is the quota-policy definition {{quota-policy}} too complex? You can always return the simplest form of the 3 fields ~~~ example -RateLimit-Limit: 100 -RateLimit-Remaining: 50 -RateLimit-Reset: 60 +RateLimit: limit=100, remaining=50, reset=60 ~~~ The key runtime value is the first element of the list: `expiring-limit`, the others quota-policy are informative. So for the following field: ~~~ example -RateLimit-Limit: 100 +RateLimit: limit=100, remaining=50, reset=44 RateLimit-Policy: 100;w=60;burst=1000;comment="sliding window", 5000;w=3600;burst=0;comment="fixed window" ~~~ @@ -1169,8 +1166,8 @@ RateLimit-Policy: 100;w=60;burst=1000;comment="sliding window", 5000;w=3600;burs where clients and servers are tightly coupled. Conveying policies with this detail on a large scale would be very complex and implementations would be likely not interoperable. We thus decided to leave `w` as - an informational parameter and only rely on RateLimit-Limit, - RateLimit-Remaining header field and RateLimit-Reset header field for defining the throttling + an informational parameter and only rely on the limit, remaining and reset keywords + for defining the throttling behavior. 15. Can I use RateLimit fields in trailers? @@ -1212,26 +1209,26 @@ Here are some interoperability issues: * X-RateLimit-Remaining and X-Rate-Limit-Remaining * X-RateLimit-Reset and X-Rate-Limit-Reset -The semantic of RateLimit-Remaining depends on the windowing algorithm. +The semantic of RateLimit depends on the windowing algorithm. A sliding window policy for example may result in having a -RateLimit-Remaining header field +remaining keyword value related to the ratio between the current and the maximum throughput. e.g. ~~~ example -RateLimit-Limit: 12 +RateLimit: limit=12, \ + remaining=6, \ ; using 50% of throughput, that is 6 units/s + reset=1 RateLimit-Policy: 12;w=1 -RateLimit-Remaining: 6 ; using 50% of throughput, that is 6 units/s -RateLimit-Reset: 1 ~~~ If this is the case, the optimal solution is to achieve ~~~ example -RateLimit-Limit: 12 +RateLimit: limit=12, \ + remaining=1 \ ; using 100% of throughput, that is 12 units/s + reset=1 RateLimit-Policy: 12;w=1 -RateLimit-Remaining: 1 ; using 100% of throughput, that is 12 units/s -RateLimit-Reset: 1 ~~~ At this point you should stop increasing your request rate. From 0b47e951901933b408516ca4b6091a9b5a4e82af Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Tue, 18 Jul 2023 21:57:30 -0400 Subject: [PATCH 02/28] Updated with policy parameter --- draft-ietf-httpapi-ratelimit-headers.md | 168 ++++++++++++------------ 1 file changed, 83 insertions(+), 85 deletions(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index 850b520..9bc2512 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -141,18 +141,21 @@ A quota policy is maintained by a server to limit the activity (counted in quota Quota policies can be advertised by servers (see {{ratelimit-policy-field}}), but they are not required to be, and more than one quota policy can affect a given request from a client to a server. -A quota policy is expressed in Structured Fields {{STRUCTURED-FIELDS}} as an Integer that indicates the service limit with associated parameters. +A quota policy is expressed in Structured Fields {{STRUCTURED-FIELDS}} as a String that identifies the policy and its associated parameters. The following Parameters are defined in this specification: + l: + : The REQUIRED "l" parameter uses a non-negative integer value to limit the activity (counted in quota units) of a given client ({{service-limit}}). + w: - : The REQUIRED "w" parameter value conveys + : The OPTIONAL "w" parameter value conveys a time window ({{time-window}}). -For example, a quota policy of 100 quota units per minute is expressed as: +For example, a quota policy named "default" of 100 quota units per minute is expressed as: ~~~ example - 100;w=60 + default;l=100;w=60 ~~~ Other parameters are allowed and can be regarded as comments. Parameters for use by more than one implementation or service ought to be registered within the "Hypertext Transfer Protocol (HTTP) RateLimit Parameters Registry", as described in {{iana-ratelimit-parameters}}. @@ -162,7 +165,7 @@ Implementation- or service-specific parameters SHOULD be prefixed parameters wit ## Service Limit {#service-limit} -The service limit is a non-negative Integer indicating the maximum amount of activity that the server is willing to accept from what it identifies as the client (e.g., based upon originating IP or user authentication) during a [time window](#time-window). +The service limit is a non-negative Integer indicating the maximum amount of activity that the server is willing to accept from what it identifies as the client (e.g., based upon originating IP or user authentication) that MAY be constrained by a [time window](#time-window). The activity being limited is usually the HTTP requests made by the client; for example "you can make 100 requests per minute". However, a server might only rate limit some requests (based upon URI, method, user identity, etc.), and it might weigh requests differently. Therefore, quota policies are defined in terms of "quota units". Servers SHOULD document how they count quota units. @@ -179,7 +182,7 @@ Often, the service limit advertised will match the server's actual limit. Howeve ## Time Window {#time-window} -Quota policies limit the number of acceptable requests within a given time interval, known as a time window. +Quota policies often limit the number of acceptable requests within a given time interval, known as a time window. The time window is a non-negative Integer value expressing that interval in seconds, similar to the "delay-seconds" rule defined in {{Section 10.2.3 of HTTP}}. Subsecond precision is not supported. @@ -188,8 +191,8 @@ By default, a quota policy does not constrain the distribution of quota units wi For example, two quota policies containing further details via extension parameters: ~~~ example - 100;w=60;comment="fixed window" - 12;w=1;burst=1000;policy="leaky bucket" + tier1;l=100;w=60;comment="fixed window" + protect;l=12;w=1;burst=1000 ~~~ @@ -199,49 +202,27 @@ The following RateLimit response header fields are defined. ## RateLimit {#ratelimit-field} -A server uses the "RateLimit" response header field to communicate its quota policies. +A server uses the "RateLimit" response header field to communicate the client quota consumption state. The field is a Dictionary. The allowed keys are defined in the "Hypertext Transfer Protocol (HTTP) RateLimit Keywords and Parameters Registry", as described in {{iana-ratelimit-parameters}}. The following Keys are defined in this specification: - limit: - : The REQUIRED "limit" key value conveys - the expiring limit ({{ratelimit-limit-keyword}}). + policy: + : The OPTIONAL "policy" key identifies + the quota policy associated to this rate limit field ({{ratelimit-policy-keyword}}). remaining: : The OPTIONAL "remaining" key value conveys - the remaining quota units ({{ratelimit-remaining-keyword}}). + the remaining quota units for the identified policy ({{ratelimit-remaining-keyword}}). reset: : The REQUIRED "reset" key value conveys - the time window reset time ({{ratelimit-reset-keyword}}). + the time window reset time for the identified policy ({{ratelimit-reset-keyword}}). This specification does not define Parameters for this field. If they appear, they MUST be ignored. This field cannot appear in a trailer section. -## Limit Keyword {#ratelimit-limit-keyword} - -The "limit" keyword indicates the [service limit](#service-limit) associated with the client in the current [time window](#time-window). If the client exceeds that limit, it MAY not be served. - -It is an Item and its value is a non-negative Integer referred to as the "expiring limit". -This specification does not define Parameters for it. -If they appear, they MUST be ignored. - -The expiring limit MUST be set to the service limit that is closest to reaching its limit, and the associated time window MUST either be: - -- inferred by the value of the [reset keyword](#ratelimit-reset-keyword) at the moment of the reset, or -- communicated out-of-band (e.g. in the documentation). - -Example: - -~~~ example - limit=100 -~~~ - -The RateLimit-Policy header field (see {{ratelimit-policy-field}}), might contain information on the associated time window. - - ## Remaining Keyword {#ratelimit-remaining-keyword} The "remaining" keyword indicates the remaining quota units associated with the expiring-limit. @@ -282,32 +263,47 @@ For example: The client MUST NOT assume that all its service limit will be reset at the moment indicated by the reset keyword. The server MAY arbitrarily alter the reset keyword value between subsequent requests; for example, in case of resource saturation or to implement sliding window policies. +## policy Keyword {#ratelimit-p-keyword} + +The "policy" keyword provides the identifer of the [quota policy](#quota-policy)) that corresponds to this [ratelimit](#ratelimit-field) field. + +It is a string value. An origin server MUST not return a response that contains multiple rate limit fields with the same policy value. + +This specification does not define Parameters for it. +If they appear, they MUST be ignored. + +For example: + +~~~ example + policy=protection +~~~ + ## RateLimit-Policy {#ratelimit-policy-field} -The "RateLimit-Policy" response header field indicates the quota policies currently associated with the client. Its value is informative. +The "RateLimit-Policy" response header field contains properties of the quota policy of the target resource that are expected to remain consistent over a the lifetime of a connection. It is this characteristic that differentiates itself from the [RateLimit](#ratelimit-field) that contains values that may change on every request. Its value is informative. The field is a non-empty List of Items. Each item is a [quota policy](#quota-policy). -Two quota policies MUST NOT be associated with the same quota units value. +Two quota policies MUST NOT be associated with the same quota units value unless they are differentiated with a unique p parameter value. This field can convey the time window associated with the expiring-limit, as shown in this example: ~~~ example - RateLimit-Policy: 100;w=10 - RateLimit: limit=100, remaining=50, reset=5 + RateLimit-Policy: default;l=100;w=10 + RateLimit: policy=default, limit=100, remaining=50, reset=5 ~~~ These examples show multiple policies being returned: ~~~ example - RateLimit-Policy: 10;w=1, 50;w=60, 1000;w=3600, 5000;w=86400 - RateLimit-Policy: 10;w=1;burst=1000, 1000;w=3600 + RateLimit-Policy: persec;l=10;w=1, permin;l=50;w=60, perhr;l=1000;w=3600, perday;l=5000;w=86400 + RateLimit-Policy: persec;l=10;w=1;burst=1000, perhr;l=1000;w=3600 ~~~ -An example of invalid header field value with two policies associated with the same quota units: +An example of invalid header field value with two policies associated with the same quota units without a unique "p" parameter value to differentiate them: ~~~ example - RateLimit-Policy: 10;w=1, 10;w=60 + RateLimit-Policy: spike;l=10;w=1, rate;l=10;w=60 ~~~ This field cannot appear in a trailer section. @@ -322,13 +318,13 @@ Servers should be careful when returning RateLimit header fields in redirection ~~~ http-message HTTP/1.1 301 Moved Permanently Location: /foo/123 -RateLimit: limit=10, remaining=0, reset=10 +RateLimit: remaining=0, reset=10 ~~~ If a response contains both the Retry-After and the RateLimit header fields, the reset keyword value SHOULD reference the same point in time as the Retry-After field value. -When using a policy involving more than one time window, the server MUST reply with the RateLimit header fields related to the time window with the lower remaining keyword values. +When using a policy involving more than one time window, the server MUST reply with the RateLimit header field related to the time window with the lower remaining keyword values. A service using RateLimit header fields MUST NOT convey values exposing an unwanted volume of requests and SHOULD implement mechanisms to cap the ratio between the remaining and the reset keyword values (see {{sec-resource-exhaustion}}); this is especially important when a quota policy uses a large time window. @@ -348,7 +344,7 @@ The RateLimit header fields can be used by clients to determine whether the asso For example, a successful response with the following fields: ~~~ example - RateLimit: limit=10, remaining=1, reset=7 + RateLimit: remaining=1, reset=7 ~~~ does not guarantee that the next request will be successful. Servers' behavior may be subject to other conditions like the one shown in the example from {{service-limit}}. @@ -453,14 +449,15 @@ and your server returns the reset keyword accordingly ~~~ example Date: Tue, 15 Nov 1994 08:00:00 GMT - RateLimit: limit=1, remaining=1, reset=36000 + RateLimit: remaining=1, reset=36000 ~~~ there's a high probability that all clients will show up at `18:00:00`. This could be mitigated by adding some jitter to the field-value. -Resource exhaustion issues can be associated with quota policies using a large time window, because a user agent by chance or on purpose +Resource exhaustion issues can be associated with quota policies using a +large time window, because a user agent by chance or on purpose might consume most of its quota units in a significantly shorter interval. This behavior can be even triggered by the provided RateLimit header fields. @@ -468,8 +465,8 @@ The following example describes a service with an unconsumed quota policy of 10000 quota units per 1000 seconds. ~~~ example -RateLimit: limit=10000, remaining=10000, reset=10 -RateLimit-Policy: 10000;w=1000 +RateLimit-Policy: somepolicy;l=10000;w=1000 +RateLimit: policy=somepolicy;remaining=10000, reset=10 ~~~ A client implementing a simple ratio between remaining keyword and @@ -631,7 +628,7 @@ may reply with different throttling headers. ### Throttling information in responses The client exhausted its service-limit for the next 50 seconds. -The time-window is communicated out-of-band or inferred by the field values. +The limit and time-window is communicated out-of-band. Request: @@ -646,7 +643,7 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -RateLimit: limit=100, remaining=0, reset=50 +RateLimit: remaining=0, reset=50 {"hello": "world"} ~~~ @@ -671,7 +668,7 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -RateLimit: limit=100, remaining=0, reset=48 +RateLimit: remaining=0, reset=48 {"still": "successful"} ~~~ @@ -711,7 +708,7 @@ HTTP/1.1 200 Ok Content-Type: application/json acme-RateLimit-DayLimit: 5000 acme-RateLimit-HourLimit: 1000 -RateLimit: limit=5000, remaining=100, reset=36000 +RateLimit: remaining=100, reset=36000 {"hello": "world"} ~~~ @@ -741,7 +738,8 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -RateLimit: limit=100, remaining=60, reset=58 +RateLimit-Policy: basic;l=100;w=60 +RateLimit: policy=basic; remaining=60, reset=58 {"elapsed": 2, "issued": 40} ~~~ @@ -762,7 +760,8 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -RateLimit: limit=100, remaining=20, reset=56 +RateLimit-Policy: basic;l=100;w=60 +RateLimit: policy=basic, remaining=20, reset=56 {"elapsed": 4, "issued": 41} ~~~ @@ -792,7 +791,7 @@ HTTP/1.1 429 Too Many Requests Content-Type: application/json Date: Mon, 05 Aug 2019 09:27:00 GMT Retry-After: Mon, 05 Aug 2019 09:27:05 GMT -RateLimit: limit=100, remaining=0, reset=5 +RateLimit: remaining=0, reset=5 { "title": "Too Many Requests", @@ -821,8 +820,8 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -RateLimit: limit=100, remaining=99, reset=50 -RateLimit-Policy: 100;w=60 +RateLimit: policy=fixedwindow, remaining=99, reset=50 +RateLimit-Policy: fixedwindow;l=100;w=60 {"hello": "world"} ~~~ @@ -856,8 +855,9 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -RateLimit: limit=10, remaining=9, reset=50 -RateLimit-Policy: 100;w=60 +RateLimit-Policy: dynamic;l=100;w=60 +RateLimit: remaining=9, reset=50 + { "status": 200, @@ -887,8 +887,8 @@ Response: ~~~ http-message HTTP/1.1 429 Too Many Requests Content-Type: application/json -RateLimit: limit=0, remaining=0, reset=20 -RateLimit-Policy: 15;w=20 +RateLimit-Policy: dynamic;l=15;w=20 +RateLimit: remaining=0, reset=20 { "status": 429, @@ -920,8 +920,8 @@ Response: HTTP/1.1 429 Too Many Requests Content-Type: application/json Retry-After: 20 -RateLimit: limit=15, remaining=15, reset=40 -RateLimit-Policy: 100;w=60 +RateLimit-Policy: dynamic;l=100;w=60 +RateLimit: remaining=15, reset=40 { "status": 429, @@ -957,7 +957,8 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -RateLimit: limit=10, reset=1 +RateLimit-Policy: quota;l=100 +RateLimit: policy=quota; reset=1 {"first": "request"} ~~~ @@ -975,7 +976,8 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -RateLimit: limit=10, reset=1 +RateLimit-Policy: quota;l=10 +RateLimit: reset=1 {"second": "request"} ~~~ @@ -1012,8 +1014,8 @@ Response: ~~~ http-message HTTP/1.1 200 OK Content-Type: application/json -RateLimit: limit=5000, remaining=100, reset=36000 -RateLimit-Policy: 1000;w=3600, 5000;w=86400 +RateLimit-Policy: hour;l=1000;w=3600, day;l=5000;w=86400 +RateLimit: policy=day, remaining=100, reset=36000 {"hello": "world"} ~~~ @@ -1076,11 +1078,7 @@ RateLimit-Policy: 1000;w=3600, 5000;w=86400 on the [httpwg ml](https://lists.w3.org/Archives/Public/ietf-http-wg/2019JulSep/0202.html) - almost all rate-limit headers implementations do not use it. -6. Why not support multiple quota remaining? - - While this might be of some value, my experience suggests that overly-complex quota implementations - results in lower effectiveness of this policy. This spec allows the client to easily focusing on - the remaining and reset keywords. +6. 7. Shouldn't I limit concurrency instead of request rate? @@ -1107,21 +1105,21 @@ RateLimit-Policy: 1000;w=3600, 5000;w=86400 9. Is the quota-policy definition {{quota-policy}} too complex? - You can always return the simplest form of the 3 fields + You can always return the simplest form ~~~ example -RateLimit: limit=100, remaining=50, reset=60 +RateLimit: remaining=50, reset=60 ~~~ - The key runtime value is the first element of the list: `expiring-limit`, the others quota-policy are informative. + The policy key clearly connects the current usage status of a policy to the defined limits. So for the following field: ~~~ example -RateLimit: limit=100, remaining=50, reset=44 -RateLimit-Policy: 100;w=60;burst=1000;comment="sliding window", 5000;w=3600;burst=0;comment="fixed window" +RateLimit-Policy: sliding;l=100;w=60;burst=1000;comment="sliding window", fixed;l=5000;w=3600;burst=0;comment="fixed window" +RateLimit: policy=sliding, remaining=50, reset=44 ~~~ - the key value is the one referencing the lowest limit: `100` + the value "sliding" identifies the policy being reported. 11. Can we use shorter names? Why don't put everything in one field? @@ -1216,19 +1214,19 @@ value related to the ratio between the current and the maximum throughput. e.g. ~~~ example -RateLimit: limit=12, \ +RateLimit: policy=default, \ remaining=6, \ ; using 50% of throughput, that is 6 units/s reset=1 -RateLimit-Policy: 12;w=1 +RateLimit-Policy: default;l=12;w=1 ~~~ If this is the case, the optimal solution is to achieve ~~~ example -RateLimit: limit=12, \ +RateLimit: policy=default, \ remaining=1 \ ; using 100% of throughput, that is 12 units/s reset=1 -RateLimit-Policy: 12;w=1 +RateLimit-Policy: default;l=12;w=1 ~~~ At this point you should stop increasing your request rate. From 08d1ada54011d28ebd61cce9a4c5dc48ac8e7df2 Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Tue, 18 Jul 2023 22:43:21 -0400 Subject: [PATCH 03/28] Removed limit --- draft-ietf-httpapi-ratelimit-headers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index 6838cec..088847a 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -290,7 +290,7 @@ This field can convey the time window associated with the expiring-limit, as sho ~~~ example RateLimit-Policy: default;l=100;w=10 - RateLimit: policy=default, limit=100, remaining=50, reset=5 + RateLimit: policy=default, remaining=50, reset=5 ~~~ These examples show multiple policies being returned: From c3fa4e5c485bd2d181e63ed1a2893bc6f886430a Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Sun, 5 Nov 2023 22:17:16 -0500 Subject: [PATCH 04/28] Updated based on IETF117 feedback --- draft-ietf-httpapi-ratelimit-headers.md | 160 ++++++++---------------- 1 file changed, 50 insertions(+), 110 deletions(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index 088847a..76d1d8e 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -141,9 +141,9 @@ A quota policy is maintained by a server to limit the activity (counted in quota Quota policies can be advertised by servers (see {{ratelimit-policy-field}}), but they are not required to be, and more than one quota policy can affect a given request from a client to a server. -A quota policy is expressed in Structured Fields {{STRUCTURED-FIELDS}} as a String that identifies the policy and its associated parameters. +A quota policy is expressed in Structured Fields {{STRUCTURED-FIELDS}} as a sf-Item that identifies the policy and its associated parameters. -The following Parameters are defined in this specification: +The following parameters are defined in this specification: l: : The REQUIRED "l" parameter uses a non-negative integer value to limit the activity (counted in quota units) of a given client ({{service-limit}}). @@ -162,7 +162,6 @@ Other parameters are allowed and can be regarded as comments. Parameters for use Implementation- or service-specific parameters SHOULD be prefixed parameters with a vendor identifier, e.g. `acme-policy`, `acme-burst`. - ## Service Limit {#service-limit} The service limit is a non-negative Integer indicating the maximum amount of activity that the server is willing to accept from what it identifies as the client (e.g., based upon originating IP or user authentication) that MAY be constrained by a [time window](#time-window). @@ -204,28 +203,30 @@ The following RateLimit response header fields are defined. A server uses the "RateLimit" response header field to communicate the client quota consumption state. -The field is a Dictionary. The allowed keys are defined in the "Hypertext Transfer Protocol (HTTP) RateLimit Keywords and Parameters Registry", as described in {{iana-ratelimit-parameters}}. +The field is expressed as a Structured Fields {{STRUCTURED-FIELDS}} sf-Item that identifies the policy and its associated consumption state as parameters. + +An origin server MUST not return a response that contains multiple rate limit fields with the same policy value. -The following Keys are defined in this specification: +The field is a Dictionary. The allowed keys are defined in the "Hypertext Transfer Protocol (HTTP) RateLimit Keywords and Parameters Registry", as described in {{iana-ratelimit-parameters}}. - policy: - : The OPTIONAL "policy" key identifies - the quota policy associated to this rate limit field ({{ratelimit-policy-keyword}}). - remaining: - : The OPTIONAL "remaining" key value conveys - the remaining quota units for the identified policy ({{ratelimit-remaining-keyword}}). - reset: - : The REQUIRED "reset" key value conveys - the time window reset time for the identified policy ({{ratelimit-reset-keyword}}). +The following parameters are defined in this specification: -This specification does not define Parameters for this field. -If they appear, they MUST be ignored. + r: + : This parameter value conveys the remaining quota units for the identified policy ({{ratelimit-remaining-keyword}}). + + t: + : This OPTIONAL parameter value conveys the time window reset time for the identified policy ({{ratelimit-reset-keyword}}). This field cannot appear in a trailer section. -## Remaining Keyword {#ratelimit-remaining-keyword} +~~~ example + RateLimit: protection;r=50;t=30 +~~~ + + +## Remaining Parameter {#ratelimit-remaining-parameter} -The "remaining" keyword indicates the remaining quota units associated with the expiring-limit. +The "r" parameter indicates the remaining quota units associated with the expiring-limit. It is an Item and its value is a non-negative Integer expressed in [quota units](#service-limit). This specification does not define Parameters for it. @@ -238,13 +239,13 @@ When the value of the remaining keyword is low, it indicates that the server may For example: ~~~ example - remaining=50 + r=50 ~~~ -## Reset Keyword {#ratelimit-reset-keyword} +## Reset Keyword {#ratelimit-reset-parameter} -The "reset" keyword indicates the number of seconds until the quota associated with the expiring-limit resets. +The "t" parameter indicates the number of seconds until the quota associated with the expiring-limit resets. It is a non-negative Integer compatible with the delay-seconds rule, because: @@ -252,32 +253,15 @@ It is a non-negative Integer compatible with the delay-seconds rule, because: and clock skew between client and server (see {{Section 5.6.7 of HTTP}}); - it mitigates the risk related to thundering herd when too many clients are serviced with the same timestamp. -This specification does not define Parameters for it. -If they appear, they MUST be ignored. For example: ~~~ example - reset=50 + t=50 ~~~ The client MUST NOT assume that all its service limit will be reset at the moment indicated by the reset keyword. The server MAY arbitrarily alter the reset keyword value between subsequent requests; for example, in case of resource saturation or to implement sliding window policies. -## policy Keyword {#ratelimit-p-keyword} - -The "policy" keyword provides the identifer of the [quota policy](#quota-policy)) that corresponds to this [ratelimit](#ratelimit-field) field. - -It is a string value. An origin server MUST not return a response that contains multiple rate limit fields with the same policy value. - -This specification does not define Parameters for it. -If they appear, they MUST be ignored. - -For example: - -~~~ example - policy=protection -~~~ - ## RateLimit-Policy {#ratelimit-policy-field} @@ -290,7 +274,7 @@ This field can convey the time window associated with the expiring-limit, as sho ~~~ example RateLimit-Policy: default;l=100;w=10 - RateLimit: policy=default, remaining=50, reset=5 + RateLimit: default;r=50;t=5 ~~~ These examples show multiple policies being returned: @@ -313,13 +297,12 @@ This field cannot appear in a trailer section. A server MAY return RateLimit header fields independently of the response status code. This includes on throttled responses. This document does not mandate any correlation between the RateLimit header field values and the returned status code. -Servers should be careful when returning RateLimit header fields in redirection responses (i.e., responses with 3xx status codes) because a low remaining keyword value could prevent the client from issuing requests. For example, given the RateLimit header fields below, a client could decide to wait 10 seconds before following the "Location" header field (see {{Section 10.2.2 of HTTP}}), because the remaining keyword value is 0. Servers should be careful when returning RateLimit header fields in redirection responses (i.e., responses with 3xx status codes) because a low remaining keyword value could prevent the client from issuing requests. For example, given the RateLimit header fields below, a client could decide to wait 10 seconds before following the "Location" header field (see {{Section 10.2.2 of HTTP}}), because the remaining keyword value is 0. ~~~ http-message HTTP/1.1 301 Moved Permanently Location: /foo/123 -RateLimit: remaining=0, reset=10 +RateLimit: problemPolicy;r=0, t=10 ~~~ @@ -327,7 +310,6 @@ If a response contains both the Retry-After and the RateLimit header fields, the When using a policy involving more than one time window, the server MUST reply with the RateLimit header field related to the time window with the lower remaining keyword values. -A service using RateLimit header fields MUST NOT convey values exposing an unwanted volume of requests and SHOULD implement mechanisms to cap the ratio between the remaining and the reset keyword values (see {{sec-resource-exhaustion}}); this is especially important when a quota policy uses a large time window. A service using RateLimit header fields MUST NOT convey values exposing an unwanted volume of requests and SHOULD implement mechanisms to cap the ratio between the remaining and the reset keyword values (see {{sec-resource-exhaustion}}); this is especially important when a quota policy uses a large time window. Under certain conditions, a server MAY artificially lower RateLimit header field values between subsequent requests, e.g. to respond to Denial of Service attacks or in case of resource saturation. @@ -346,7 +328,7 @@ The RateLimit header fields can be used by clients to determine whether the asso For example, a successful response with the following fields: ~~~ example - RateLimit: remaining=1, reset=7 + RateLimit: default;r=1;t=7 ~~~ does not guarantee that the next request will be successful. Servers' behavior may be subject to other conditions like the one shown in the example from {{service-limit}}. @@ -359,10 +341,8 @@ A client receiving RateLimit header fields MUST NOT assume that future responses Malformed RateLimit header fields MUST be ignored. -A client SHOULD NOT exceed the quota units conveyed by the remaining keyword before the time window expressed in the reset keyword. A client SHOULD NOT exceed the quota units conveyed by the remaining keyword before the time window expressed in the reset keyword. -A client MAY still probe the server if the reset keyword is considered too high. A client MAY still probe the server if the reset keyword is considered too high. The value of the reset keyword is generated at response time: a client aware of a significant network latency MAY behave accordingly and use other information (e.g. the "Date" response header field, or otherwise gathered metrics) to better estimate the reset keyword moment intended by the server. @@ -430,39 +410,32 @@ to the user agent. RateLimit header fields convey hints from the server to the clients in order to help them avoid being throttled out. -Clients MUST NOT consider the [quota units](#service-limit) returned in remaining keyword as a service level agreement. Clients MUST NOT consider the [quota units](#service-limit) returned in remaining keyword as a service level agreement. In case of resource saturation, the server MAY artificially lower the returned values or not serve the request regardless of the advertised quotas. -## Reliability of the reset keyword {#sec-reset-reliability} ## Reliability of the reset keyword {#sec-reset-reliability} -Consider that service limit might not be restored after the moment referenced by the [reset keyword](#ratelimit-reset-keyword), -and the reset keyword value may not be fixed nor constant. Consider that service limit might not be restored after the moment referenced by the [reset keyword](#ratelimit-reset-keyword), and the reset keyword value may not be fixed nor constant. -Subsequent requests might return a higher reset keyword value Subsequent requests might return a higher reset keyword value to limit concurrency or implement dynamic or adaptive throttling policies. ## Resource exhaustion {#sec-resource-exhaustion} -When returning reset keyword you must be aware that When returning reset keyword you must be aware that many throttled clients may come back at the very moment specified. This is true for Retry-After too. For example, if the quota resets every day at `18:00:00` -and your server returns the reset keyword accordingly -and your server returns the reset keyword accordingly +and your server returns the reset parameter accordingly ~~~ example Date: Tue, 15 Nov 1994 08:00:00 GMT - RateLimit: remaining=1, reset=36000 + RateLimit: daily;r=1;t=36000 ~~~ there's a high probability that all clients will show up at `18:00:00`. @@ -479,21 +452,11 @@ with an unconsumed quota policy of 10000 quota units per 1000 seconds. ~~~ example RateLimit-Policy: somepolicy;l=10000;w=1000 -RateLimit: policy=somepolicy;remaining=10000, reset=10 +RateLimit: somepolicy;r=10000;t=10 ~~~ -A client implementing a simple ratio between remaining keyword and -reset keyword could infer an average throughput of 1000 quota units per second, -while the limit keyword conveys a quota-policy -A client implementing a simple ratio between remaining keyword and -reset keyword could infer an average throughput of 1000 quota units per second, -while the limit keyword conveys a quota-policy -with an average of 10 quota units per second. -If the service cannot handle such load, it should return -either a lower remaining keyword value -or an higher reset keyword value. -either a lower remaining keyword value -or an higher reset keyword value. +A client implementing a simple ratio between remaining keyword and reset keyword could infer an average throughput of 1000 quota units per second,while the limit keyword conveys a quota-policy with an average of 10 quota units per second. +If the service cannot handle such load, it should return either a lower remaining keyword value or an higher reset keyword value. Moreover, complementing large time window quota policies with a short time window one mitigates those risks. @@ -501,25 +464,17 @@ Moreover, complementing large time window quota policies with a short time windo RateLimit header fields may contain unexpected values by chance or on purpose. For example, an excessively high remaining keyword value may be: -For example, an excessively high remaining keyword value may be: - used by a malicious intermediary to trigger a Denial of Service attack or consume client resources boosting its requests; - passed by a misconfigured server; -or a high reset keyword value could inhibit clients to contact the server (e.g. similarly to receiving "Retry-after: 1000000"). or a high reset keyword value could inhibit clients to contact the server (e.g. similarly to receiving "Retry-after: 1000000"). -To mitigate this risk, clients can set thresholds that they consider reasonable in terms of -quota units, time window, concurrent requests or throughput, -and define a consistent behavior when the RateLimit exceed those thresholds. -For example this means capping the maximum number of request per second, -or implementing retries when the reset keyword exceeds ten minutes. -or implementing retries when the reset keyword exceeds ten minutes. +To mitigate this risk, clients can set thresholds that they consider reasonable in terms of quota units, time window, concurrent requests or throughput, and define a consistent behavior when the RateLimit exceed those thresholds. +For example this means capping the maximum number of request per second, or implementing retries when the reset keyword exceeds ten minutes. -The considerations above are not limited to RateLimit header fields, -but apply to all fields affecting how clients behave -in subsequent requests (e.g. Retry-After). +The considerations above are not limited to RateLimit header fields, but apply to all fields affecting how clients behave in subsequent requests (e.g. Retry-After). # Privacy Considerations {#privacy} @@ -548,17 +503,14 @@ Please add the following entries to the | Field Name | Status | Specification | |---------------------|-----------|---------------| | RateLimit | permanent | {{ratelimit-field}} of {{&SELF}} | -| RateLimit | permanent | {{ratelimit-field}} of {{&SELF}} | | RateLimit-Policy | permanent | {{ratelimit-policy-field}} of {{&SELF}} | |---------------------|-----------|---------------| -## RateLimit Keywords and Parameters Registration {#iana-ratelimit-parameters} ## RateLimit Keywords and Parameters Registration {#iana-ratelimit-parameters} IANA is requested to create a new registry to be called "Hypertext Transfer Protocol (HTTP) RateLimit Keywords and Parameters Registry", -"Hypertext Transfer Protocol (HTTP) RateLimit Keywords and Parameters Registry", to be located at . Registration is done on the advice of a Designated Expert, @@ -680,7 +632,7 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -RateLimit: remaining=0, reset=50 +RateLimit: default;r=0;t=50 {"hello": "world"} ~~~ @@ -706,7 +658,7 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -RateLimit: remaining=0, reset=48 +RateLimit: default;r=0;t=48 {"still": "successful"} ~~~ @@ -746,7 +698,8 @@ HTTP/1.1 200 Ok Content-Type: application/json acme-RateLimit-DayLimit: 5000 acme-RateLimit-HourLimit: 1000 -RateLimit: remaining=100, reset=36000 +RateLimit: dayLimit;r=100;t=36000 +RateLimit: hourLimit;r=25;t=700 {"hello": "world"} ~~~ @@ -778,7 +731,7 @@ Response: HTTP/1.1 200 Ok Content-Type: application/json RateLimit-Policy: basic;l=100;w=60 -RateLimit: policy=basic; remaining=60, reset=58 +RateLimit: basic;r=60;t=58 {"elapsed": 2, "issued": 40} ~~~ @@ -801,7 +754,7 @@ Response: HTTP/1.1 200 Ok Content-Type: application/json RateLimit-Policy: basic;l=100;w=60 -RateLimit: policy=basic, remaining=20, reset=56 +RateLimit: basic;r=20;t=56 {"elapsed": 4, "issued": 41} ~~~ @@ -811,7 +764,6 @@ RateLimit: policy=basic, remaining=20, reset=56 A client exhausted its quota and the server throttles it sending Retry-After. -In this example, the values of Retry-After and RateLimit header field reference the same moment, In this example, the values of Retry-After and RateLimit header field reference the same moment, but this is not a requirement. @@ -832,7 +784,7 @@ HTTP/1.1 429 Too Many Requests Content-Type: application/json Date: Mon, 05 Aug 2019 09:27:00 GMT Retry-After: Mon, 05 Aug 2019 09:27:05 GMT -RateLimit: remaining=0, reset=5 +RateLimit: default;r=0;t=5 { "title": "Too Many Requests", @@ -861,7 +813,7 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -RateLimit: policy=fixedwindow, remaining=99, reset=50 +RateLimit: fixedwindow;r=99;t=50 RateLimit-Policy: fixedwindow;l=100;w=60 {"hello": "world"} ~~~ @@ -869,20 +821,17 @@ RateLimit-Policy: fixedwindow;l=100;w=60 ### Dynamic limits with parameterized windows -The policy conveyed by the RateLimit header field states that The policy conveyed by the RateLimit header field states that the server accepts 100 quota units per minute. To avoid resource exhaustion, the server artificially lowers the actual limits returned in the throttling headers. -The remaining keyword then advertises The remaining keyword then advertises only 9 quota units for the next 50 seconds to slow down the client. Note that the server could have lowered even the other values in the RateLimit header field: this specification -values in the RateLimit header field: this specification does not mandate any relation between the field values contained in subsequent responses. @@ -900,7 +849,7 @@ Response: HTTP/1.1 200 Ok Content-Type: application/json RateLimit-Policy: dynamic;l=100;w=60 -RateLimit: remaining=9, reset=50 +RateLimit: dynamic;r=9;t=50 { @@ -933,7 +882,7 @@ Response: HTTP/1.1 429 Too Many Requests Content-Type: application/json RateLimit-Policy: dynamic;l=15;w=20 -RateLimit: remaining=0, reset=20 +RateLimit: dynamic;r=0;t=20 { "status": 429, @@ -966,7 +915,7 @@ HTTP/1.1 429 Too Many Requests Content-Type: application/json Retry-After: 20 RateLimit-Policy: dynamic;l=100;w=60 -RateLimit: remaining=15, reset=40 +RateLimit: dynamic;r=15;t=40 { "status": 429, @@ -982,14 +931,12 @@ query again the server even if it is likely to have the request rejected. ### Missing Remaining information -The server does not expose remaining keyword values The server does not expose remaining keyword values (for example, because the underlying counters are not available). Instead, it resets the limit counter every second. It communicates to the client the limit of 10 quota units per second always returning the limit and reset keywords. -always returning the limit and reset keywords. Request: @@ -1005,7 +952,7 @@ Response: HTTP/1.1 200 Ok Content-Type: application/json RateLimit-Policy: quota;l=100 -RateLimit: policy=quota; reset=1 +RateLimit: quota;t=1 {"first": "request"} ~~~ @@ -1024,7 +971,7 @@ Response: HTTP/1.1 200 Ok Content-Type: application/json RateLimit-Policy: quota;l=10 -RateLimit: reset=1 +RateLimit: quota;t=1 {"second": "request"} ~~~ @@ -1062,7 +1009,7 @@ Response: HTTP/1.1 200 OK Content-Type: application/json RateLimit-Policy: hour;l=1000;w=3600, day;l=5000;w=86400 -RateLimit: policy=day, remaining=100, reset=36000 +RateLimit: day;r=100;t=36000 {"hello": "world"} ~~~ @@ -1145,19 +1092,17 @@ RateLimit: policy=day, remaining=100, reset=36000 Saturation conditions can be either dynamic or static: all this is out of the scope for the current document. -8. Do a positive value of remaining keyword imply any service guarantee for my 8. Do a positive value of remaining keyword imply any service guarantee for my future requests to be served? No. FAQ integrated in {{ratelimit-remaining-keyword}}. - No. FAQ integrated in {{ratelimit-remaining-keyword}}. 9. Is the quota-policy definition {{quota-policy}} too complex? You can always return the simplest form ~~~ example -RateLimit: remaining=50, reset=60 +RateLimit:default;r=50;t=60 ~~~ The policy key clearly connects the current usage status of a policy to the defined limits. @@ -1165,7 +1110,7 @@ RateLimit: remaining=50, reset=60 ~~~ example RateLimit-Policy: sliding;l=100;w=60;burst=1000;comment="sliding window", fixed;l=5000;w=3600;burst=0;comment="fixed window" -RateLimit: policy=sliding, remaining=50, reset=44 +RateLimit: sliding;r=50;t=44 ~~~ the value "sliding" identifies the policy being reported. @@ -1215,8 +1160,6 @@ RateLimit: policy=sliding, remaining=50, reset=44 would be likely not interoperable. We thus decided to leave `w` as an informational parameter and only rely on the limit, remaining and reset keywords for defining the throttling - an informational parameter and only rely on the limit, remaining and reset keywords - for defining the throttling behavior. 15. Can I use RateLimit fields in trailers? @@ -1233,9 +1176,6 @@ Commonly used header field names are: - `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset`; -- `X-Rate-Limit-Limit`, - `X-Rate-Limit-Remaining`, - `X-Rate-Limit-Reset`. There are variants too, where the window is specified in the header field name, eg: From 562114b817176ff9989c7fd1cebc372445552a86 Mon Sep 17 00:00:00 2001 From: Roberto Polli Date: Mon, 8 Jan 2024 13:45:29 +0100 Subject: [PATCH 05/28] Run make fix-lint. --- draft-ietf-httpapi-ratelimit-headers.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index 76d1d8e..9a1e897 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -213,7 +213,7 @@ The following parameters are defined in this specification: r: : This parameter value conveys the remaining quota units for the identified policy ({{ratelimit-remaining-keyword}}). - + t: : This OPTIONAL parameter value conveys the time window reset time for the identified policy ({{ratelimit-reset-keyword}}). @@ -442,7 +442,7 @@ there's a high probability that all clients will show up at `18:00:00`. This could be mitigated by adding some jitter to the field-value. -Resource exhaustion issues can be associated with quota policies using a +Resource exhaustion issues can be associated with quota policies using a large time window, because a user agent by chance or on purpose might consume most of its quota units in a significantly shorter interval. @@ -730,7 +730,7 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -RateLimit-Policy: basic;l=100;w=60 +RateLimit-Policy: basic;l=100;w=60 RateLimit: basic;r=60;t=58 {"elapsed": 2, "issued": 40} @@ -753,7 +753,7 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -RateLimit-Policy: basic;l=100;w=60 +RateLimit-Policy: basic;l=100;w=60 RateLimit: basic;r=20;t=56 {"elapsed": 4, "issued": 41} @@ -1072,7 +1072,7 @@ RateLimit: day;r=100;t=36000 on the [httpwg ml](https://lists.w3.org/Archives/Public/ietf-http-wg/2019JulSep/0202.html) - almost all rate-limit headers implementations do not use it. -6. +6. 7. Shouldn't I limit concurrency instead of request rate? From 02a991c8b9ce369666ee3861faa32c4eaf36a17c Mon Sep 17 00:00:00 2001 From: Roberto Polli Date: Mon, 8 Jan 2024 13:52:03 +0100 Subject: [PATCH 06/28] remove unsupported 'example' sourcecode type. --- draft-ietf-httpapi-ratelimit-headers.md | 32 ++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index 9a1e897..c1dd1aa 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -154,7 +154,7 @@ The following parameters are defined in this specification: For example, a quota policy named "default" of 100 quota units per minute is expressed as: -~~~ example +~~~ default;l=100;w=60 ~~~ @@ -170,7 +170,7 @@ The activity being limited is usually the HTTP requests made by the client; for For example, a server could count requests like `/books/{id}` once, but count search requests like `/books?author=WuMing` twice. This might result in the following counters: -~~~ example +~~~ GET /books/123 ; service-limit=4, remaining: 3, status=200 GET /books?author=WuMing ; service-limit=4, remaining: 1, status=200 GET /books?author=Eco ; service-limit=4, remaining: 0, status=429 @@ -189,7 +189,7 @@ By default, a quota policy does not constrain the distribution of quota units wi For example, two quota policies containing further details via extension parameters: -~~~ example +~~~ tier1;l=100;w=60;comment="fixed window" protect;l=12;w=1;burst=1000 ~~~ @@ -219,7 +219,7 @@ The following parameters are defined in this specification: This field cannot appear in a trailer section. -~~~ example +~~~ RateLimit: protection;r=50;t=30 ~~~ @@ -238,7 +238,7 @@ When the value of the remaining keyword is low, it indicates that the server may For example: -~~~ example +~~~ r=50 ~~~ @@ -256,7 +256,7 @@ It is a non-negative Integer compatible with the delay-seconds rule, because: For example: -~~~ example +~~~ t=50 ~~~ @@ -272,21 +272,21 @@ Two quota policies MUST NOT be associated with the same quota units value unless This field can convey the time window associated with the expiring-limit, as shown in this example: -~~~ example +~~~ RateLimit-Policy: default;l=100;w=10 RateLimit: default;r=50;t=5 ~~~ These examples show multiple policies being returned: -~~~ example +~~~ RateLimit-Policy: persec;l=10;w=1, permin;l=50;w=60, perhr;l=1000;w=3600, perday;l=5000;w=86400 RateLimit-Policy: persec;l=10;w=1;burst=1000, perhr;l=1000;w=3600 ~~~ An example of invalid header field value with two policies associated with the same quota units without a unique "p" parameter value to differentiate them: -~~~ example +~~~ RateLimit-Policy: spike;l=10;w=1, rate;l=10;w=60 ~~~ @@ -327,7 +327,7 @@ The RateLimit header fields can be used by clients to determine whether the asso For example, a successful response with the following fields: -~~~ example +~~~ RateLimit: default;r=1;t=7 ~~~ @@ -433,7 +433,7 @@ This is true for Retry-After too. For example, if the quota resets every day at `18:00:00` and your server returns the reset parameter accordingly -~~~ example +~~~ Date: Tue, 15 Nov 1994 08:00:00 GMT RateLimit: daily;r=1;t=36000 ~~~ @@ -450,7 +450,7 @@ This behavior can be even triggered by the provided RateLimit header fields. The following example describes a service with an unconsumed quota policy of 10000 quota units per 1000 seconds. -~~~ example +~~~ RateLimit-Policy: somepolicy;l=10000;w=1000 RateLimit: somepolicy;r=10000;t=10 ~~~ @@ -1101,14 +1101,14 @@ RateLimit: day;r=100;t=36000 You can always return the simplest form -~~~ example +~~~ RateLimit:default;r=50;t=60 ~~~ The policy key clearly connects the current usage status of a policy to the defined limits. So for the following field: -~~~ example +~~~ RateLimit-Policy: sliding;l=100;w=60;burst=1000;comment="sliding window", fixed;l=5000;w=3600;burst=0;comment="fixed window" RateLimit: sliding;r=50;t=44 ~~~ @@ -1205,7 +1205,7 @@ remaining keyword value related to the ratio between the current and the maximum throughput. e.g. -~~~ example +~~~ RateLimit-Limit: 12 RateLimit-Policy: 12;w=1 RateLimit-Remaining: 6 ; using 50% of throughput, that is 6 units/s @@ -1214,7 +1214,7 @@ RateLimit-Reset: 1 If this is the case, the optimal solution is to achieve -~~~ example +~~~ RateLimit-Limit: 12 RateLimit-Policy: 12;w=1 RateLimit-Remaining: 1 ; using 100% of throughput, that is 12 units/s From 0fad367e7d6182af329b5ab0e59c09170bdf5cfc Mon Sep 17 00:00:00 2001 From: Roberto Polli Date: Mon, 8 Jan 2024 14:07:47 +0100 Subject: [PATCH 07/28] Fix section references. --- draft-ietf-httpapi-ratelimit-headers.md | 26 +++++++++---------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index c1dd1aa..ca41790 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -212,10 +212,10 @@ The field is a Dictionary. The allowed keys are defined in the "Hypertext Transf The following parameters are defined in this specification: r: - : This parameter value conveys the remaining quota units for the identified policy ({{ratelimit-remaining-keyword}}). + : This parameter value conveys the remaining quota units for the identified policy ({{ratelimit-remaining-parameter}}). t: - : This OPTIONAL parameter value conveys the time window reset time for the identified policy ({{ratelimit-reset-keyword}}). + : This OPTIONAL parameter value conveys the time window reset time for the identified policy ({{ratelimit-reset-parameter}}). This field cannot appear in a trailer section. @@ -417,7 +417,7 @@ or not serve the request regardless of the advertised quotas. ## Reliability of the reset keyword {#sec-reset-reliability} -Consider that service limit might not be restored after the moment referenced by the [reset keyword](#ratelimit-reset-keyword), +Consider that service limit might not be restored after the moment referenced by the [reset keyword](#ratelimit-reset-parameter), and the reset keyword value may not be fixed nor constant. Subsequent requests might return a higher reset keyword value @@ -550,18 +550,10 @@ The initial contents of this registry should be: |---|---|---|---|---|---| | Field Name | Token name | Token type | Description | Specification | Comments (optional) | |---|---|---|---|---|---| -| RateLimit | limit | Dictionary Key |Expiring limit | {{ratelimit-limit-keyword}} of {{&SELF}} | | -| RateLimit | remaining | Dictionary Key |Remaining quota units | {{ratelimit-remaining-keyword}} of {{&SELF}} | | -| RateLimit | reset | Dictionary Key |Quota reset interval | {{ratelimit-reset-keyword}} of {{&SELF}} | | -| RateLimit-Policy | w | Parameter name |Time window | {{quota-policy}} of {{&SELF}} | | -|---|---|---|---|---|---| -|---|---|---|---|---|---| -| Field Name | Token name | Token type | Description | Specification | Comments (optional) | -|---|---|---|---|---|---| -| RateLimit | limit | Dictionary Key |Expiring limit | {{ratelimit-limit-keyword}} of {{&SELF}} | | -| RateLimit | remaining | Dictionary Key |Remaining quota units | {{ratelimit-remaining-keyword}} of {{&SELF}} | | -| RateLimit | reset | Dictionary Key |Quota reset interval | {{ratelimit-reset-keyword}} of {{&SELF}} | | -| RateLimit-Policy | w | Parameter name |Time window | {{quota-policy}} of {{&SELF}} | | +| RateLimit | r | Dictionary Key |Remaining quota units | {{ratelimit-remaining-parameter}} of {{&SELF}} | | +| RateLimit | t | Dictionary Key |Quota reset interval | {{ratelimit-reset-parameter}} of {{&SELF}} | | +| RateLimit-Policy | l | Dictionary Key |Expiring limit | {{quota-policy}} of {{&SELF}} | | +| RateLimit-Policy | w | Dictionary Key |Time window | {{quota-policy}} of {{&SELF}} | | |---|---|---|---|---|---| --- back @@ -1095,7 +1087,7 @@ RateLimit: day;r=100;t=36000 8. Do a positive value of remaining keyword imply any service guarantee for my future requests to be served? - No. FAQ integrated in {{ratelimit-remaining-keyword}}. + No. FAQ integrated in {{ratelimit-remaining-parameter}}. 9. Is the quota-policy definition {{quota-policy}} too complex? @@ -1175,7 +1167,7 @@ Commonly used header field names are: - `X-RateLimit-Limit`, `X-RateLimit-Remaining`, - `X-RateLimit-Reset`; + `X-RateLimit-Reset`; There are variants too, where the window is specified in the header field name, eg: From fc0dc0b9374bb3eb6132b6b04f2bfeb2e281e9f3 Mon Sep 17 00:00:00 2001 From: Roberto Polli Date: Sun, 5 May 2024 19:17:10 +0200 Subject: [PATCH 08/28] Update draft-ietf-httpapi-ratelimit-headers.md Co-authored-by: Johanan --- draft-ietf-httpapi-ratelimit-headers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index ca41790..aaabcdb 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -455,7 +455,7 @@ RateLimit-Policy: somepolicy;l=10000;w=1000 RateLimit: somepolicy;r=10000;t=10 ~~~ -A client implementing a simple ratio between remaining keyword and reset keyword could infer an average throughput of 1000 quota units per second,while the limit keyword conveys a quota-policy with an average of 10 quota units per second. +A client implementing a simple ratio between remaining keyword and reset keyword could infer an average throughput of 1000 quota units per second, while the limit keyword conveys a quota-policy with an average of 10 quota units per second. If the service cannot handle such load, it should return either a lower remaining keyword value or an higher reset keyword value. Moreover, complementing large time window quota policies with a short time window one mitigates those risks. From 7a9433257c6bf4090befb5a62d61c45c000d2f16 Mon Sep 17 00:00:00 2001 From: Darrel Date: Sun, 2 Jun 2024 14:17:42 -0400 Subject: [PATCH 09/28] Update draft-ietf-httpapi-ratelimit-headers.md Co-authored-by: Johanan --- draft-ietf-httpapi-ratelimit-headers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index aaabcdb..40819fb 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -181,7 +181,7 @@ Often, the service limit advertised will match the server's actual limit. Howeve ## Time Window {#time-window} -Quota policies often limit the number of acceptable requests within a given time interval, known as a time window. +Quota policies MAY limit the number of acceptable requests within a given time interval, known as a time window. The time window is a non-negative Integer value expressing that interval in seconds, similar to the "delay-seconds" rule defined in {{Section 10.2.3 of HTTP}}. Subsecond precision is not supported. From 9b9c2d8da92434fa2aae090be681540e7eb3d4b3 Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Sun, 2 Jun 2024 14:22:14 -0400 Subject: [PATCH 10/28] Added author to assign appropriate blame --- draft-ietf-httpapi-ratelimit-headers.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index aaabcdb..be2e3af 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -32,6 +32,10 @@ author: name: Alejandro Martinez Ruiz org: Red Hat email: alex@flawedcode.org +- ins: D. Miller + name: Darrel Miller + org: Microsoft + email: darrel@tavis.ca entity: SELF: "RFC nnnn" @@ -1191,10 +1195,7 @@ Here are some interoperability issues: * X-RateLimit-Reset and X-Rate-Limit-Reset The semantic of RateLimit depends on the windowing algorithm. -The semantic of RateLimit depends on the windowing algorithm. -A sliding window policy for example may result in having a -remaining keyword -value related to the ratio between the current and the maximum throughput. +A sliding window policy for example, may result in having a remaining keyword value related to the ratio between the current and the maximum throughput. e.g. ~~~ @@ -1228,8 +1229,7 @@ Aapo Talvensaari, Nathan Friedly and Sanyam Dogra. -In addition to the people above, this document owes a lot to the extensive discussion -in the HTTPAPI workgroup, including +In addition to the people above, this document owes a lot to the extensive discussion in the HTTPAPI workgroup, including Rich Salz, Darrel Miller and Julian Reschke. From 2d203f3b5fd2c76592a6d98bebc1e309417bfe98 Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Mon, 8 Jul 2024 14:52:41 -0400 Subject: [PATCH 11/28] Updates based on feedback to PR --- draft-ietf-httpapi-ratelimit-headers.md | 83 ++++++++----------------- 1 file changed, 25 insertions(+), 58 deletions(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index 3b2d1d0..f31f328 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -1,4 +1,4 @@ ---- + # Introduction -Rate limiting HTTP clients has become a widespread practice, especially for HTTP APIs. Typically, servers who do so limit the number of acceptable requests in a given time window (e.g. 10 requests per second). See {{rate-limiting}} for further information on the current usage of rate limiting in HTTP. +Rate limiting of HTTP clients has become a widespread practice, especially for HTTP APIs. Typically, servers who do so limit the number of acceptable requests in a given time window (e.g. 10 requests per second). See {{rate-limiting}} for further information on the current usage of rate limiting in HTTP. -Currently, there is no standard way for servers to communicate quotas so that clients can throttle its requests to prevent errors. This document defines a set of standard HTTP header fields to enable rate limiting: +Currently, there is no standard way for servers to communicate quotas so that clients can throttle their requests to prevent errors. This document defines a set of standard HTTP header fields to enable rate limiting: - RateLimit: to convey the server's current limit of quota units available to the client in the policy time window, @@ -71,11 +72,10 @@ Currently, there is no standard way for servers to communicate quotas so that cl and the time remaining in the current window, specified in seconds, and - RateLimit-Policy: the service policy limits. -These fields allow the establishment of complex rate limiting policies, including using multiple and variable time windows and dynamic quotas, and implementing concurrency limits. +These fields enable establishing complex rate limiting policies, including using multiple and variable time windows and dynamic quotas, and implementing concurrency limits. The behavior of the RateLimit header field is compatible with the delay-seconds notation of Retry-After. - ## Goals {#goals} The goals of this document are: @@ -113,7 +113,7 @@ The following features are out of the scope of this document: successful (see {{Section 15.3 of HTTP}}) and non-successful responses. This specification does not cover whether non Successful responses count on quota usage, - nor it mandates any correlation between the RateLimit values + nor does it mandates any correlation between the RateLimit values and the returned status code. Throttling policy: @@ -145,16 +145,16 @@ A quota policy is maintained by a server to limit the activity (counted in quota Quota policies can be advertised by servers (see {{ratelimit-policy-field}}), but they are not required to be, and more than one quota policy can affect a given request from a client to a server. -A quota policy is expressed in Structured Fields {{STRUCTURED-FIELDS}} as a sf-Item that identifies the policy and its associated parameters. +A quota policy is expressed in Structured Fields {{STRUCTURED-FIELDS}} syntax as a sf-Item that identifies the policy and its associated parameters. The following parameters are defined in this specification: l: - : The REQUIRED "l" parameter uses a non-negative integer value to limit the activity (counted in quota units) of a given client ({{service-limit}}). + : The REQUIRED "l" parameter uses a non-negative integer value to "limit" the activity (counted in quota units) of a given client ({{service-limit}}). w: : The OPTIONAL "w" parameter value conveys - a time window ({{time-window}}). + a time "window" ({{time-window}}). For example, a quota policy named "default" of 100 quota units per minute is expressed as: @@ -189,29 +189,21 @@ Quota policies MAY limit the number of acceptable requests within a given time i The time window is a non-negative Integer value expressing that interval in seconds, similar to the "delay-seconds" rule defined in {{Section 10.2.3 of HTTP}}. Subsecond precision is not supported. -By default, a quota policy does not constrain the distribution of quota units within the time window. If necessary, these details can be conveyed as extension parameters. - -For example, two quota policies containing further details via extension parameters: - -~~~ - tier1;l=100;w=60;comment="fixed window" - protect;l=12;w=1;burst=1000 -~~~ - +By default, a quota policy does not constrain the distribution of quota units within the time window. # RateLimit header field Definitions -The following RateLimit response header fields are defined. +The following response header fields are defined. -## RateLimit {#ratelimit-field} +## RateLimit Field {#ratelimit-field} A server uses the "RateLimit" response header field to communicate the client quota consumption state. The field is expressed as a Structured Fields {{STRUCTURED-FIELDS}} sf-Item that identifies the policy and its associated consumption state as parameters. -An origin server MUST not return a response that contains multiple rate limit fields with the same policy value. +An origin server MAY return one or more rate limit fields. It MUST not return a response that contains multiple rate limit fields with the same policy value. Rate limit fields SHOULD use policy identifiers that correspond to policy identifiers declared in RateLimit-Policy fields. -The field is a Dictionary. The allowed keys are defined in the "Hypertext Transfer Protocol (HTTP) RateLimit Keywords and Parameters Registry", as described in {{iana-ratelimit-parameters}}. +The allowed parameters are defined in the "Hypertext Transfer Protocol (HTTP) RateLimit Parameters Registry", as described in {{iana-ratelimit-parameters}}. The following parameters are defined in this specification: @@ -228,26 +220,16 @@ This field cannot appear in a trailer section. ~~~ -## Remaining Parameter {#ratelimit-remaining-parameter} +### Remaining Parameter {#ratelimit-remaining-parameter} -The "r" parameter indicates the remaining quota units associated with the expiring-limit. - -It is an Item and its value is a non-negative Integer expressed in [quota units](#service-limit). -This specification does not define Parameters for it. -If they appear, they MUST be ignored. +The "r" parameter indicates the remaining quota units for the identified policy ({{ratelimit-remaining-parameter}}). +It is a non-negative Integer expressed in [quota units](#service-limit). Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. - When the value of the remaining keyword is low, it indicates that the server may soon throttle the client (see {{providing-ratelimit-fields}}). -For example: - -~~~ - r=50 -~~~ - -## Reset Keyword {#ratelimit-reset-parameter} +### Reset Parameter {#ratelimit-reset-parameter} The "t" parameter indicates the number of seconds until the quota associated with the expiring-limit resets. @@ -257,24 +239,15 @@ It is a non-negative Integer compatible with the delay-seconds rule, because: and clock skew between client and server (see {{Section 5.6.7 of HTTP}}); - it mitigates the risk related to thundering herd when too many clients are serviced with the same timestamp. - -For example: - -~~~ - t=50 -~~~ - -The client MUST NOT assume that all its service limit will be reset at the moment indicated by the reset keyword. The server MAY arbitrarily alter the reset keyword value between subsequent requests; for example, in case of resource saturation or to implement sliding window policies. - +The client MUST NOT assume that all its service limit will be reset at the moment indicated by the reset keyword. The server MAY arbitrarily alter the reset paramter value between subsequent requests; for example, in case of resource saturation or to implement sliding window policies. ## RateLimit-Policy {#ratelimit-policy-field} -The "RateLimit-Policy" response header field contains properties of the quota policy of the target resource that are expected to remain consistent over a the lifetime of a connection. It is this characteristic that differentiates itself from the [RateLimit](#ratelimit-field) that contains values that may change on every request. Its value is informative. +The "RateLimit-Policy" response header field contains information about the quota policy of the target resource that is expected to remain consistent over a the lifetime of a connection. It is this characteristic that differentiates itself from the [RateLimit](#ratelimit-field) that contains values that may change on every request. Its value is informative. The field is a non-empty List of Items. Each item is a [quota policy](#quota-policy). -Two quota policies MUST NOT be associated with the same quota units value unless they are differentiated with a unique p parameter value. -This field can convey the time window associated with the expiring-limit, as shown in this example: +This field MAY convey the time window associated with the expiring-limit, as shown in this example: ~~~ RateLimit-Policy: default;l=100;w=10 @@ -284,14 +257,8 @@ This field can convey the time window associated with the expiring-limit, as sho These examples show multiple policies being returned: ~~~ - RateLimit-Policy: persec;l=10;w=1, permin;l=50;w=60, perhr;l=1000;w=3600, perday;l=5000;w=86400 - RateLimit-Policy: persec;l=10;w=1;burst=1000, perhr;l=1000;w=3600 -~~~ - -An example of invalid header field value with two policies associated with the same quota units without a unique "p" parameter value to differentiate them: - -~~~ - RateLimit-Policy: spike;l=10;w=1, rate;l=10;w=60 + RateLimit-Policy: permin;l=50;w=60, perhr;l=1000;w=3600, perday;l=5000;w=86400 + RateLimit: permin;r=20;w=23, perhr;r=399;w=2402 ~~~ This field cannot appear in a trailer section. From 77e31a0aae513caa014f36f2bdc9c541b8fdd462 Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Mon, 8 Jul 2024 14:53:10 -0400 Subject: [PATCH 12/28] uncommented front matter --- draft-ietf-httpapi-ratelimit-headers.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index f31f328..27f176c 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -1,4 +1,4 @@ - +--- middle # Introduction From 4196337ff91293e2c09c7c4d7174cd5346292ba4 Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Sun, 14 Jul 2024 13:48:06 -0400 Subject: [PATCH 13/28] Add support to pk --- draft-ietf-httpapi-ratelimit-headers.md | 122 +++++++++++++----------- 1 file changed, 66 insertions(+), 56 deletions(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index 27f176c..f12ad2f 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -1,4 +1,4 @@ ---- + # Introduction @@ -101,13 +101,6 @@ The following features are out of the scope of this document: : RateLimit header fields are not meant to support authorization or other kinds of access controls. - Throttling scope: - : This specification does not cover the throttling scope, - that may be the given resource-target, its parent path or the whole - Origin (see {{Section 7 of !WEB-ORIGIN=RFC6454}}). - This can be addressed using extensibility mechanisms - such as the parameter registry {{iana-ratelimit-parameters}}. - Response status code: : RateLimit header fields may be returned in both successful (see {{Section 15.3 of HTTP}}) and non-successful responses. @@ -116,8 +109,8 @@ The following features are out of the scope of this document: nor does it mandates any correlation between the RateLimit values and the returned status code. - Throttling policy: - : This specification does not mandate a specific throttling policy. + Throttling algorithm: + : This specification does not mandate a specific throttling algorithm. The values published in the fields, including the window size, can be statically or dynamically evaluated. @@ -137,67 +130,105 @@ This document uses the terms List, Item and Integer from {{Section 3 of !STRUCTU The header fields defined in this document are collectively referred to as "RateLimit header fields". -# Concepts +# Terminology + +## Quota {#quota} + +A quota is an allocation of capacity that a server tracks to enable it to limit client requests. That capacity is counted in quota units and may be reallocated at the end of a time window {#time-window}. + +## Quota Partition {#quota-partition} + +A quota partition is a division of a server's capacity across different clients, users and owned resources. + +## Time Window {#time-window} + +A time window indicates a period of time associated to the allocated quota. + +The time window is a non-negative Integer value expressing that interval in seconds, similar to the "delay-seconds" rule defined in {{Section 10.2.3 of HTTP}}. Subsecond precision is not supported. ## Quota Policy {#quota-policy} -A quota policy is maintained by a server to limit the activity (counted in quota units) of a given client over a period of time (known as the [time window](#time-window)) to a specified amount (known as the [service limit](#service-limit)). +A quota policy is maintained by a server to limit the activity (counted in quota units) of a given [quota partition](#quota-partition) over a period of time (known as the [time window](#time-window)) to a specified amount known as the [quota](#quota). Quota policies can be advertised by servers (see {{ratelimit-policy-field}}), but they are not required to be, and more than one quota policy can affect a given request from a client to a server. +## Service Limit {#service-limit} + +A service limit is the current limit on the amount of activity that a server will allow based on the remaining quota for a particular quota partition. + +# RateLimit header field Definitions + +The following response header fields are defined. + +## RateLimit-Policy Field {#ratelimit-policy-field} + +The "RateLimit-Policy" response header field contains information about a server's policy for the quota partition associated with the request. Its value is informative. The values of the policy are expected to remain consistent over a the lifetime of a connection. It is this characteristic that differentiates itself from the [RateLimit](#ratelimit-field) that contains values that may change on every request. + +The field is a non-empty List of Items. Each item is a [quota policy](#quota-policy). + A quota policy is expressed in Structured Fields {{STRUCTURED-FIELDS}} syntax as a sf-Item that identifies the policy and its associated parameters. The following parameters are defined in this specification: - l: - : The REQUIRED "l" parameter uses a non-negative integer value to "limit" the activity (counted in quota units) of a given client ({{service-limit}}). + q: + : The REQUIRED "q" parameter indicates the quota allocated. ({{ratelimitpolicy-quota}}) + + qu: + : The OPTIONAL "qu" parameter value conveys the quota units associated to the "q" parameter. The default quota unit is "request". ({{ratelimitpolicy-quotaunit}}) w: - : The OPTIONAL "w" parameter value conveys - a time "window" ({{time-window}}). + : The OPTIONAL "w" parameter value conveys a time "window" ({{time-window}}). ({{ratelimitpolicy-window}}) + + pk: + : The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key. For example, a quota policy named "default" of 100 quota units per minute is expressed as: ~~~ - default;l=100;w=60 + default;q=100;w=60 ~~~ Other parameters are allowed and can be regarded as comments. Parameters for use by more than one implementation or service ought to be registered within the "Hypertext Transfer Protocol (HTTP) RateLimit Parameters Registry", as described in {{iana-ratelimit-parameters}}. Implementation- or service-specific parameters SHOULD be prefixed parameters with a vendor identifier, e.g. `acme-policy`, `acme-burst`. -## Service Limit {#service-limit} +### Quota Parameter {#ratelimitpolicy-quota} -The service limit is a non-negative Integer indicating the maximum amount of activity that the server is willing to accept from what it identifies as the client (e.g., based upon originating IP or user authentication) that MAY be constrained by a [time window](#time-window). + The "q" parameter uses a non-negative integer value to indicate the quota allocated for client activity (counted in quota units) of a given client ({{service-limit}}). -The activity being limited is usually the HTTP requests made by the client; for example "you can make 100 requests per minute". However, a server might only rate limit some requests (based upon URI, method, user identity, etc.), and it might weigh requests differently. Therefore, quota policies are defined in terms of "quota units". Servers SHOULD document how they count quota units. +### Quota Unit Parameter {#ratelimitpolicy-quotaunit} -For example, a server could count requests like `/books/{id}` once, but count search requests like `/books?author=WuMing` twice. This might result in the following counters: +The "qu" parameter value conveys the quota units associated to the "q" parameter. -~~~ -GET /books/123 ; service-limit=4, remaining: 3, status=200 -GET /books?author=WuMing ; service-limit=4, remaining: 1, status=200 -GET /books?author=Eco ; service-limit=4, remaining: 0, status=429 -~~~ +### Window Parameter {#ratelimitpolicy-window} -Often, the service limit advertised will match the server's actual limit. However, it MAY differ when weight mechanisms, bursts, or other server policies are implemented. In that case the difference SHOULD be communicated using an extension or documented separately. +The "w" parameter value conveys a time "window" ({{time-window}}). +### Partition Key Parameter {#ratelimitpolicy-partitionkey} -## Time Window {#time-window} +The "pk" parameter value conveys the partition key associated to the request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key. -Quota policies MAY limit the number of acceptable requests within a given time interval, known as a time window. -The time window is a non-negative Integer value expressing that interval in seconds, similar to the "delay-seconds" rule defined in {{Section 10.2.3 of HTTP}}. Subsecond precision is not supported. +This field MAY convey the time window associated with the expiring-limit, as shown in this example: + +~~~ + RateLimit-Policy: default;l=100;w=10 + RateLimit: default;r=50;t=5 +~~~ -By default, a quota policy does not constrain the distribution of quota units within the time window. +These examples show multiple policies being returned: -# RateLimit header field Definitions +~~~ + RateLimit-Policy: permin;l=50;w=60, perhr;l=1000;w=3600, perday;l=5000;w=86400 + RateLimit: permin;r=20;w=23, perhr;r=399;w=2402 +~~~ + +This field cannot appear in a trailer section. -The following response header fields are defined. ## RateLimit Field {#ratelimit-field} -A server uses the "RateLimit" response header field to communicate the client quota consumption state. +A server uses the "RateLimit" response header field to communicate the remaining allocation of quota for a quota partition. The field is expressed as a Structured Fields {{STRUCTURED-FIELDS}} sf-Item that identifies the policy and its associated consumption state as parameters. @@ -241,27 +272,6 @@ It is a non-negative Integer compatible with the delay-seconds rule, because: The client MUST NOT assume that all its service limit will be reset at the moment indicated by the reset keyword. The server MAY arbitrarily alter the reset paramter value between subsequent requests; for example, in case of resource saturation or to implement sliding window policies. -## RateLimit-Policy {#ratelimit-policy-field} - -The "RateLimit-Policy" response header field contains information about the quota policy of the target resource that is expected to remain consistent over a the lifetime of a connection. It is this characteristic that differentiates itself from the [RateLimit](#ratelimit-field) that contains values that may change on every request. Its value is informative. - -The field is a non-empty List of Items. Each item is a [quota policy](#quota-policy). - -This field MAY convey the time window associated with the expiring-limit, as shown in this example: - -~~~ - RateLimit-Policy: default;l=100;w=10 - RateLimit: default;r=50;t=5 -~~~ - -These examples show multiple policies being returned: - -~~~ - RateLimit-Policy: permin;l=50;w=60, perhr;l=1000;w=3600, perday;l=5000;w=86400 - RateLimit: permin;r=20;w=23, perhr;r=399;w=2402 -~~~ - -This field cannot appear in a trailer section. # Server Behavior {#providing-ratelimit-fields} From df6faac981b5ed14419e6e6752193c310495f455 Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Sun, 14 Jul 2024 13:53:31 -0400 Subject: [PATCH 14/28] Restoring front matter --- draft-ietf-httpapi-ratelimit-headers.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index f12ad2f..866712f 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -1,4 +1,4 @@ - +--- middle # Introduction From 55fcfee2b12f96054ea1338ddfd1c4afaae55133 Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Sun, 14 Jul 2024 13:54:37 -0400 Subject: [PATCH 15/28] fixed again --- draft-ietf-httpapi-ratelimit-headers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index 866712f..378d9e0 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -1,4 +1,4 @@ - --- +--- title: RateLimit header fields for HTTP abbrev: docname: draft-ietf-httpapi-ratelimit-headers-latest From c68377378c1513b2bb6e1d5504d72481f5da7229 Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Sun, 14 Jul 2024 13:55:50 -0400 Subject: [PATCH 16/28] added missing value to front matter --- draft-ietf-httpapi-ratelimit-headers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index 378d9e0..48197cd 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -1,6 +1,6 @@ --- title: RateLimit header fields for HTTP -abbrev: +abbrev: RateLimit Headers docname: draft-ietf-httpapi-ratelimit-headers-latest category: std From 00f5fa4951ead16494bcc3ec9e6cae43ee80dfe0 Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Sun, 14 Jul 2024 14:16:46 -0400 Subject: [PATCH 17/28] Fixed YAML frontmatter --- draft-ietf-httpapi-ratelimit-headers.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index 48197cd..62a6bd0 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -1,6 +1,6 @@ --- title: RateLimit header fields for HTTP -abbrev: RateLimit Headers +abbrev: docname: draft-ietf-httpapi-ratelimit-headers-latest category: std @@ -32,7 +32,7 @@ author: name: Alejandro Martinez Ruiz org: Red Hat email: alex@flawedcode.org -- + - ins: D. Miller name: Darrel Miller org: Microsoft @@ -53,7 +53,6 @@ informative: name: The Open Group ins: The Open Group date: 1997-02 - --- abstract This document defines the RateLimit-Policy and RateLimit HTTP header fields for servers to advertise their service policy limits and the current limits, thereby allowing clients to avoid being throttled. @@ -124,7 +123,7 @@ The following features are out of the scope of this document: This document uses the Augmented BNF defined in {{!RFC5234}} and updated by {{!RFC7405}} along with the "#rule" extension defined in {{Section 5.6.1 of HTTP}}. -The term Origin is to be interpreted as described in Section 7 of {{WEB-ORIGIN}}. +The term Origin is to be interpreted as described in Section 7 of {{!WEB-ORIGIN=RFC6454}}. This document uses the terms List, Item and Integer from {{Section 3 of !STRUCTURED-FIELDS=RFC8941}} to specify syntax and parsing, along with the concept of "bare item". From 62b57bff7d0f63ec4617c7a5f56eb850058dfb99 Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Sun, 14 Jul 2024 14:23:29 -0400 Subject: [PATCH 18/28] Fixed indent --- draft-ietf-httpapi-ratelimit-headers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index 62a6bd0..a05ab42 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -570,7 +570,7 @@ The common choice is to return three headers containing: - the time remaining in the current window expressed in seconds or as a timestamp; -### Interoperability issues +## Interoperability issues A major interoperability issue in throttling is the lack of standard headers, because: From 6c037ed925df36dd1c4235090ca091662318bcc2 Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Sun, 14 Jul 2024 14:26:31 -0400 Subject: [PATCH 19/28] Removed trailing whitespace --- draft-ietf-httpapi-ratelimit-headers.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index a05ab42..db4cfa0 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -1,6 +1,6 @@ --- title: RateLimit header fields for HTTP -abbrev: +abbrev: docname: draft-ietf-httpapi-ratelimit-headers-latest category: std @@ -32,7 +32,7 @@ author: name: Alejandro Martinez Ruiz org: Red Hat email: alex@flawedcode.org - - + - ins: D. Miller name: Darrel Miller org: Microsoft @@ -57,7 +57,7 @@ informative: This document defines the RateLimit-Policy and RateLimit HTTP header fields for servers to advertise their service policy limits and the current limits, thereby allowing clients to avoid being throttled. ---- middle +--- middle # Introduction @@ -137,7 +137,7 @@ A quota is an allocation of capacity that a server tracks to enable it to limit ## Quota Partition {#quota-partition} -A quota partition is a division of a server's capacity across different clients, users and owned resources. +A quota partition is a division of a server's capacity across different clients, users and owned resources. ## Time Window {#time-window} @@ -161,7 +161,7 @@ The following response header fields are defined. ## RateLimit-Policy Field {#ratelimit-policy-field} -The "RateLimit-Policy" response header field contains information about a server's policy for the quota partition associated with the request. Its value is informative. The values of the policy are expected to remain consistent over a the lifetime of a connection. It is this characteristic that differentiates itself from the [RateLimit](#ratelimit-field) that contains values that may change on every request. +The "RateLimit-Policy" response header field contains information about a server's policy for the quota partition associated with the request. Its value is informative. The values of the policy are expected to remain consistent over a the lifetime of a connection. It is this characteristic that differentiates itself from the [RateLimit](#ratelimit-field) that contains values that may change on every request. The field is a non-empty List of Items. Each item is a [quota policy](#quota-policy). @@ -170,7 +170,7 @@ A quota policy is expressed in Structured Fields {{STRUCTURED-FIELDS}} syntax as The following parameters are defined in this specification: q: - : The REQUIRED "q" parameter indicates the quota allocated. ({{ratelimitpolicy-quota}}) + : The REQUIRED "q" parameter indicates the quota allocated. ({{ratelimitpolicy-quota}}) qu: : The OPTIONAL "qu" parameter value conveys the quota units associated to the "q" parameter. The default quota unit is "request". ({{ratelimitpolicy-quotaunit}}) @@ -179,7 +179,7 @@ The following parameters are defined in this specification: : The OPTIONAL "w" parameter value conveys a time "window" ({{time-window}}). ({{ratelimitpolicy-window}}) pk: - : The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key. + : The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key. For example, a quota policy named "default" of 100 quota units per minute is expressed as: @@ -205,7 +205,7 @@ The "w" parameter value conveys a time "window" ({{time-window}}). ### Partition Key Parameter {#ratelimitpolicy-partitionkey} -The "pk" parameter value conveys the partition key associated to the request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key. +The "pk" parameter value conveys the partition key associated to the request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key. This field MAY convey the time window associated with the expiring-limit, as shown in this example: @@ -269,7 +269,7 @@ It is a non-negative Integer compatible with the delay-seconds rule, because: and clock skew between client and server (see {{Section 5.6.7 of HTTP}}); - it mitigates the risk related to thundering herd when too many clients are serviced with the same timestamp. -The client MUST NOT assume that all its service limit will be reset at the moment indicated by the reset keyword. The server MAY arbitrarily alter the reset paramter value between subsequent requests; for example, in case of resource saturation or to implement sliding window policies. +The client MUST NOT assume that all its service limit will be reset at the moment indicated by the reset keyword. The server MAY arbitrarily alter the reset paramter value between subsequent requests; for example, in case of resource saturation or to implement sliding window policies. From 93ef0f0dc375523e4a7b0d60fa08e9a93dca76ef Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Sun, 14 Jul 2024 15:09:05 -0400 Subject: [PATCH 20/28] Added specialized item headings --- draft-ietf-httpapi-ratelimit-headers.md | 28 +++++++++++++++---------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index db4cfa0..d9de5ee 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -1,4 +1,4 @@ ---- + # Introduction @@ -155,16 +155,13 @@ Quota policies can be advertised by servers (see {{ratelimit-policy-field}}), bu A service limit is the current limit on the amount of activity that a server will allow based on the remaining quota for a particular quota partition. -# RateLimit header field Definitions - -The following response header fields are defined. - -## RateLimit-Policy Field {#ratelimit-policy-field} +# RateLimit-Policy Field {#ratelimit-policy-field} The "RateLimit-Policy" response header field contains information about a server's policy for the quota partition associated with the request. Its value is informative. The values of the policy are expected to remain consistent over a the lifetime of a connection. It is this characteristic that differentiates itself from the [RateLimit](#ratelimit-field) that contains values that may change on every request. The field is a non-empty List of Items. Each item is a [quota policy](#quota-policy). +## Quota Policy Item {#quotapolicy-item} A quota policy is expressed in Structured Fields {{STRUCTURED-FIELDS}} syntax as a sf-Item that identifies the policy and its associated parameters. The following parameters are defined in this specification: @@ -207,6 +204,7 @@ The "w" parameter value conveys a time "window" ({{time-window}}). The "pk" parameter value conveys the partition key associated to the request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key. +## RateLimit Policy Field Examples This field MAY convey the time window associated with the expiring-limit, as shown in this example: @@ -225,13 +223,13 @@ These examples show multiple policies being returned: This field cannot appear in a trailer section. -## RateLimit Field {#ratelimit-field} +# RateLimit Field {#ratelimit-field} -A server uses the "RateLimit" response header field to communicate the remaining allocation of quota for a quota partition. +A server uses the "RateLimit" response header field to communicate the service limit for a quota policy for a particular partition key. -The field is expressed as a Structured Fields {{STRUCTURED-FIELDS}} sf-Item that identifies the policy and its associated consumption state as parameters. +The field is expressed as List of {{servicelimit-item}} that identifies the policy and the associated service limit. -An origin server MAY return one or more rate limit fields. It MUST not return a response that contains multiple rate limit fields with the same policy value. Rate limit fields SHOULD use policy identifiers that correspond to policy identifiers declared in RateLimit-Policy fields. +## Service Limit Item {#servicelimit-item} The allowed parameters are defined in the "Hypertext Transfer Protocol (HTTP) RateLimit Parameters Registry", as described in {{iana-ratelimit-parameters}}. @@ -243,6 +241,9 @@ The following parameters are defined in this specification: t: : This OPTIONAL parameter value conveys the time window reset time for the identified policy ({{ratelimit-reset-parameter}}). + pk: + : The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. + This field cannot appear in a trailer section. ~~~ @@ -271,6 +272,11 @@ It is a non-negative Integer compatible with the delay-seconds rule, because: The client MUST NOT assume that all its service limit will be reset at the moment indicated by the reset keyword. The server MAY arbitrarily alter the reset paramter value between subsequent requests; for example, in case of resource saturation or to implement sliding window policies. +### Partition Key Parameter {#ratelimit-partitionkey} + +The "pk" parameter value conveys the partition key associated to the request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key. + +## RateLimit Field Examples # Server Behavior {#providing-ratelimit-fields} From d909a833c7bd982d0d7cd4f4e1d832e9c392ef5c Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Sun, 14 Jul 2024 15:10:14 -0400 Subject: [PATCH 21/28] reenabled frontmatter --- draft-ietf-httpapi-ratelimit-headers.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index d9de5ee..37d7116 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -1,4 +1,4 @@ - +--- middle # Introduction From 7a1c8d1583a6b0bb2dcf1e76aa06114eff1218ff Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Sat, 28 Sep 2024 17:00:20 -0400 Subject: [PATCH 22/28] Major refresh --- draft-ietf-httpapi-ratelimit-headers.md | 174 ++++++++++-------------- 1 file changed, 73 insertions(+), 101 deletions(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index 37d7116..98aff48 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -80,7 +80,7 @@ The behavior of the RateLimit header field is compatible with the delay-seconds The goals of this document are: Interoperability: - : Standardization of the names and semantics of rate-limit headers + : Standardize the names and semantics of rate-limit headers to ease their enforcement and adoption; Resiliency: @@ -121,19 +121,19 @@ The following features are out of the scope of this document: {::boilerplate bcp14} -This document uses the Augmented BNF defined in {{!RFC5234}} and updated by {{!RFC7405}} along with the "#rule" extension defined in {{Section 5.6.1 of HTTP}}. - The term Origin is to be interpreted as described in Section 7 of {{!WEB-ORIGIN=RFC6454}}. This document uses the terms List, Item and Integer from {{Section 3 of !STRUCTURED-FIELDS=RFC8941}} to specify syntax and parsing, along with the concept of "bare item". -The header fields defined in this document are collectively referred to as "RateLimit header fields". - # Terminology ## Quota {#quota} -A quota is an allocation of capacity that a server tracks to enable it to limit client requests. That capacity is counted in quota units and may be reallocated at the end of a time window {#time-window}. +A quota is an allocation of capacity to enable a server to limit client requests. That capacity is counted in quota units and may be reallocated at the end of a time window {{time-window}}. + +## Quota Unit {#quota-unit} + +A quota unit is the unit of measure used to count the activity of a client. ## Quota Partition {#quota-partition} @@ -143,26 +143,28 @@ A quota partition is a division of a server's capacity across different clients, A time window indicates a period of time associated to the allocated quota. -The time window is a non-negative Integer value expressing that interval in seconds, similar to the "delay-seconds" rule defined in {{Section 10.2.3 of HTTP}}. Subsecond precision is not supported. +The time window is a non-negative Integer value expressing an interval in seconds, similar to the "delay-seconds" rule defined in {{Section 10.2.3 of HTTP}}. Sub-second precision is not supported. ## Quota Policy {#quota-policy} -A quota policy is maintained by a server to limit the activity (counted in quota units) of a given [quota partition](#quota-partition) over a period of time (known as the [time window](#time-window)) to a specified amount known as the [quota](#quota). +A quota policy is maintained by a server to limit the activity (counted in [quota units](#quota-units)) of a given [quota partition](#quota-partition) over a period of time (known as the [time window](#time-window)) to a specified amount known as the [quota](#quota). Quota policies can be advertised by servers (see {{ratelimit-policy-field}}), but they are not required to be, and more than one quota policy can affect a given request from a client to a server. ## Service Limit {#service-limit} -A service limit is the current limit on the amount of activity that a server will allow based on the remaining quota for a particular quota partition. +A service limit is the current limit of the amount of activity that a server will allow based on the remaining quota for a particular quota partition within the time-window, if defined. # RateLimit-Policy Field {#ratelimit-policy-field} -The "RateLimit-Policy" response header field contains information about a server's policy for the quota partition associated with the request. Its value is informative. The values of the policy are expected to remain consistent over a the lifetime of a connection. It is this characteristic that differentiates itself from the [RateLimit](#ratelimit-field) that contains values that may change on every request. +The "RateLimit-Policy" response header field is a non-empty List of {{quotapolicy-item}}. Its value is informative. The values are expected to remain consistent over a the lifetime of a connection. It is this characteristic that differentiates it from the [RateLimit](#ratelimit-field) that contains values that may change on every request. -The field is a non-empty List of Items. Each item is a [quota policy](#quota-policy). +~~~ + RateLimit-Policy: burst;q=100;w=60,daily;q=1000;w=86400 +~~~ ## Quota Policy Item {#quotapolicy-item} -A quota policy is expressed in Structured Fields {{STRUCTURED-FIELDS}} syntax as a sf-Item that identifies the policy and its associated parameters. +A quota policy Item contains information about a server's capacity allocation for a quota partition associated with the request. The following parameters are defined in this specification: @@ -176,21 +178,15 @@ The following parameters are defined in this specification: : The OPTIONAL "w" parameter value conveys a time "window" ({{time-window}}). ({{ratelimitpolicy-window}}) pk: - : The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key. + : The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. {{ratelimitpolicy-partitionkey}} -For example, a quota policy named "default" of 100 quota units per minute is expressed as: - -~~~ - default;q=100;w=60 -~~~ - -Other parameters are allowed and can be regarded as comments. Parameters for use by more than one implementation or service ought to be registered within the "Hypertext Transfer Protocol (HTTP) RateLimit Parameters Registry", as described in {{iana-ratelimit-parameters}}. +Other parameters are allowed and can be regarded as comments. Implementation- or service-specific parameters SHOULD be prefixed parameters with a vendor identifier, e.g. `acme-policy`, `acme-burst`. ### Quota Parameter {#ratelimitpolicy-quota} - The "q" parameter uses a non-negative integer value to indicate the quota allocated for client activity (counted in quota units) of a given client ({{service-limit}}). + The "q" parameter uses a non-negative integer value to indicate the quota allocated for client activity (counted in quota units) for a given quota partition ({{service-limit}}). ### Quota Unit Parameter {#ratelimitpolicy-quotaunit} @@ -198,7 +194,7 @@ The "qu" parameter value conveys the quota units associated to the "q" parameter ### Window Parameter {#ratelimitpolicy-window} -The "w" parameter value conveys a time "window" ({{time-window}}). +The "w" parameter value conveys a time "window" in seconds. ({{time-window}}). ### Partition Key Parameter {#ratelimitpolicy-partitionkey} @@ -210,28 +206,41 @@ This field MAY convey the time window associated with the expiring-limit, as sho ~~~ RateLimit-Policy: default;l=100;w=10 - RateLimit: default;r=50;t=5 ~~~ These examples show multiple policies being returned: ~~~ RateLimit-Policy: permin;l=50;w=60, perhr;l=1000;w=3600, perday;l=5000;w=86400 - RateLimit: permin;r=20;w=23, perhr;r=399;w=2402 ~~~ -This field cannot appear in a trailer section. +The following example shows a policy with a partition key: +~~~ + RateLimit-Policy: peruser;l=100;w=60;pk=user123 +~~~ + +The following example shows a policy with a partition key and a quota unit: + +~~~ + RateLimit-Policy: peruser;l=65535;w=10;pk=user123;qu=bytes +~~~ + +This field cannot appear in a trailer section. # RateLimit Field {#ratelimit-field} A server uses the "RateLimit" response header field to communicate the service limit for a quota policy for a particular partition key. -The field is expressed as List of {{servicelimit-item}} that identifies the policy and the associated service limit. +The field is expressed as List of {{servicelimit-item}}. + +~~~ + RateLimit: default;r=50;t=30 +~~~ ## Service Limit Item {#servicelimit-item} -The allowed parameters are defined in the "Hypertext Transfer Protocol (HTTP) RateLimit Parameters Registry", as described in {{iana-ratelimit-parameters}}. +Each service limit item in identifies the quota policy associated with the request and The following parameters are defined in this specification: @@ -244,25 +253,22 @@ The following parameters are defined in this specification: pk: : The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. -This field cannot appear in a trailer section. +This field cannot appear in a trailer section. Other parameters are allowed and can be regarded as comments. -~~~ - RateLimit: protection;r=50;t=30 -~~~ +Implementation- or service-specific parameters SHOULD be prefixed parameters with a vendor identifier, e.g. `acme-policy`, `acme-burst`. ### Remaining Parameter {#ratelimit-remaining-parameter} The "r" parameter indicates the remaining quota units for the identified policy ({{ratelimit-remaining-parameter}}). -It is a non-negative Integer expressed in [quota units](#service-limit). +It is a non-negative Integer expressed in [quota units](#quota-units). Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. -When the value of the remaining keyword is low, it indicates that the server may soon throttle the client (see {{providing-ratelimit-fields}}). - +When remaining parameter value is low, it indicates that the server may soon throttle the client (see {{providing-ratelimit-fields}}). ### Reset Parameter {#ratelimit-reset-parameter} -The "t" parameter indicates the number of seconds until the quota associated with the expiring-limit resets. +The "t" parameter indicates the number of seconds until the quota associated with the quota policy resets. It is a non-negative Integer compatible with the delay-seconds rule, because: @@ -270,14 +276,33 @@ It is a non-negative Integer compatible with the delay-seconds rule, because: and clock skew between client and server (see {{Section 5.6.7 of HTTP}}); - it mitigates the risk related to thundering herd when too many clients are serviced with the same timestamp. -The client MUST NOT assume that all its service limit will be reset at the moment indicated by the reset keyword. The server MAY arbitrarily alter the reset paramter value between subsequent requests; for example, in case of resource saturation or to implement sliding window policies. +The client MUST NOT assume that all its service limit will be reset at the moment indicated by the reset keyword. The server MAY arbitrarily alter the reset parameter value between subsequent requests; for example, in case of resource saturation or to implement sliding window policies. ### Partition Key Parameter {#ratelimit-partitionkey} The "pk" parameter value conveys the partition key associated to the request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key. + ## RateLimit Field Examples +This example shows a RateLimit field with a remaining quota of 50 units and a time window reset in 30 seconds: + +~~~ + RateLimit: default;r=50;t=30 +~~~ + +This example shows a remaining quota of 999 requests for a partition key that has no time window reset: + +~~~ + RateLimit: default;r=999;pk=trial-121323 +~~~ + +This example shows a 300MB remaining quota for an application in the next 60 seconds: + +~~~ + RateLimit: default;r=300000000;pk=App-999;t=60;qu=bytes +~~~ + # Server Behavior {#providing-ratelimit-fields} @@ -294,22 +319,20 @@ RateLimit: problemPolicy;r=0, t=10 If a response contains both the Retry-After and the RateLimit header fields, the reset keyword value SHOULD reference the same point in time as the Retry-After field value. -When using a policy involving more than one time window, the server MUST reply with the RateLimit header field related to the time window with the lower remaining keyword values. - A service using RateLimit header fields MUST NOT convey values exposing an unwanted volume of requests and SHOULD implement mechanisms to cap the ratio between the remaining and the reset keyword values (see {{sec-resource-exhaustion}}); this is especially important when a quota policy uses a large time window. Under certain conditions, a server MAY artificially lower RateLimit header field values between subsequent requests, e.g. to respond to Denial of Service attacks or in case of resource saturation. ## Performance Considerations -Servers are not required to return RateLimit header fields in every response, and clients need to take this into account. For example, an implementer concerned with performance might provide RateLimit header fields only when a given quota is going to expire. +Servers are not required to return RateLimit header fields in every response, and clients need to take this into account. For example, an implementer concerned with performance might provide RateLimit header fields only when a given quota is close to exhaustion. Implementers concerned with response fields' size, might take into account their ratio with respect to the content length, or use header-compression HTTP features such as {{?HPACK=RFC7541}}. # Client Behavior {#receiving-fields} -The RateLimit header fields can be used by clients to determine whether the associated request respected the server's quota policy, and as an indication of whether subsequent requests will. However, the server might apply other criteria when servicing future requests, and so the quota policy may not completely reflect whether they will succeed. +The RateLimit header fields can be used by clients to determine whether the associated request respected the server's quota policy, and as an indication of whether subsequent requests will. However, the server might apply other criteria when servicing future requests, and so the quota policy may not completely reflect whether requests will succeed. For example, a successful response with the following fields: @@ -317,7 +340,7 @@ For example, a successful response with the following fields: RateLimit: default;r=1;t=7 ~~~ -does not guarantee that the next request will be successful. Servers' behavior may be subject to other conditions like the one shown in the example from {{service-limit}}. +does not guarantee that the next request will be successful. Servers' behavior may be subject to other conditions. A client is responsible for ensuring that RateLimit header field values returned cause reasonable client behavior with respect to throughput and latency @@ -329,14 +352,10 @@ Malformed RateLimit header fields MUST be ignored. A client SHOULD NOT exceed the quota units conveyed by the remaining keyword before the time window expressed in the reset keyword. -A client MAY still probe the server if the reset keyword is considered too high. - -The value of the reset keyword is generated at response time: a client aware of a significant network latency MAY behave accordingly and use other information (e.g. the "Date" response header field, or otherwise gathered metrics) to better estimate the reset keyword moment intended by the server. The value of the reset keyword is generated at response time: a client aware of a significant network latency MAY behave accordingly and use other information (e.g. the "Date" response header field, or otherwise gathered metrics) to better estimate the reset keyword moment intended by the server. The details provided in the RateLimit-Policy header field are informative and MAY be ignored. -If a response contains both the RateLimit and Retry-After fields, the Retry-After field MUST take precedence and the reset keyword MAY be ignored. If a response contains both the RateLimit and Retry-After fields, the Retry-After field MUST take precedence and the reset keyword MAY be ignored. This specification does not mandate a specific throttling behavior and implementers can adopt their preferred policies, including: @@ -391,6 +410,8 @@ quota units without prior knowledge of the user agent, RateLimit header fields might reveal the existence of an intermediary to the user agent. +Where partition keys contain identifying information, either of the client application or the user, servers should be aware of the potential for impersonation and apply the appropriate security mechanisms. + ## Remaining quota units are not granted requests {#sec-remaining-not-granted} RateLimit header fields convey hints from the server @@ -403,15 +424,15 @@ or not serve the request regardless of the advertised quotas. ## Reliability of the reset keyword {#sec-reset-reliability} -Consider that service limit might not be restored after the moment referenced by the [reset keyword](#ratelimit-reset-parameter), -and the reset keyword value may not be fixed nor constant. +Consider that quota might not be restored after the moment referenced by the [reset keyword](#ratelimit-reset-parameter), +and the reset parameter value may not be constant. -Subsequent requests might return a higher reset keyword value +Subsequent requests might return a higher reset parameter value to limit concurrency or implement dynamic or adaptive throttling policies. ## Resource exhaustion {#sec-resource-exhaustion} -When returning reset keyword you must be aware that +When returning reset values, servers must be aware that many throttled clients may come back at the very moment specified. This is true for Retry-After too. @@ -420,13 +441,13 @@ For example, if the quota resets every day at `18:00:00` and your server returns the reset parameter accordingly ~~~ - Date: Tue, 15 Nov 1994 08:00:00 GMT - RateLimit: daily;r=1;t=36000 + Date: Tue, 15 Nov 1994 18:00:00 GMT + RateLimit: daily;r=1;t=36400 ~~~ there's a high probability that all clients will show up at `18:00:00`. -This could be mitigated by adding some jitter to the field-value. +This could be mitigated by adding some jitter to the reset value. Resource exhaustion issues can be associated with quota policies using a large time window, because a user agent by chance or on purpose @@ -493,55 +514,6 @@ Please add the following entries to the |---------------------|-----------|---------------| -## RateLimit Keywords and Parameters Registration {#iana-ratelimit-parameters} - -IANA is requested to create a new registry to be called -"Hypertext Transfer Protocol (HTTP) RateLimit Keywords and Parameters Registry", -to be located at -. -Registration is done on the advice of a Designated Expert, -appointed by the IESG or their delegate. -All entries are Specification Required ({{IANA, Section 4.6}}). - -Registration requests consist of the following information: - -- Token name: - The keyword or parameter name, conforming to {{STRUCTURED-FIELDS}}. - -- Token type: - Whether the token is a Dictionary Keyword or a Parameter Name. -- Token name: - The keyword or parameter name, conforming to {{STRUCTURED-FIELDS}}. - -- Token type: - Whether the token is a Dictionary Keyword or a Parameter Name. - -- Field name: - The RateLimit header field for which the parameter is registered. If a parameter is intended to be used - with multiple fields, it has to be registered - for each one. - -- Description: - A brief description of the parameter. - -- Specification document: - A reference to the document that specifies the parameter, preferably - including a URI that can be used to retrieve a copy of the document. - -- Comments (optional): - Any additional information that can be useful. - -The initial contents of this registry should be: - -|---|---|---|---|---|---| -| Field Name | Token name | Token type | Description | Specification | Comments (optional) | -|---|---|---|---|---|---| -| RateLimit | r | Dictionary Key |Remaining quota units | {{ratelimit-remaining-parameter}} of {{&SELF}} | | -| RateLimit | t | Dictionary Key |Quota reset interval | {{ratelimit-reset-parameter}} of {{&SELF}} | | -| RateLimit-Policy | l | Dictionary Key |Expiring limit | {{quota-policy}} of {{&SELF}} | | -| RateLimit-Policy | w | Dictionary Key |Time window | {{quota-policy}} of {{&SELF}} | | -|---|---|---|---|---|---| - --- back # Rate-limiting and quotas {#rate-limiting} From 82e1a15f1b6b490603a08f4d94b3674fdbe686a0 Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Sun, 29 Sep 2024 12:27:32 -0400 Subject: [PATCH 23/28] Updated examples --- draft-ietf-httpapi-ratelimit-headers.md | 132 ++++++++---------------- 1 file changed, 43 insertions(+), 89 deletions(-) diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index 98aff48..2294126 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -360,7 +360,7 @@ If a response contains both the RateLimit and Retry-After fields, the Retry-Afte This specification does not mandate a specific throttling behavior and implementers can adopt their preferred policies, including: -- slowing down or preemptively back-off their request rate when +- slowing down or pre-emptively back-off their request rate when approaching quota limits; - consuming all the quota according to the exposed limits and then wait. @@ -562,11 +562,13 @@ may reply with different throttling headers. # Examples -## Unparameterized responses +## Responses without defining policies + +Some servers may not expose the policy limits in the RateLimit-Policy header field. Clients can still use the RateLimit header field to throttle their requests. ### Throttling information in responses -The client exhausted its service-limit for the next 50 seconds. +The client exhausted its quota for the next 50 seconds. The limit and time-window is communicated out-of-band. Request: @@ -592,7 +594,6 @@ the response status code, a subsequent request is not required to fail. The example below shows that the server decided to serve the request even if remaining keyword value is 0. -even if remaining keyword value is 0. Another server, or the same server under other load conditions, could have decided to throttle the request instead. Request: @@ -613,11 +614,9 @@ RateLimit: default;r=0;t=48 {"still": "successful"} ~~~ -### Use in conjunction with custom fields {#use-with-custom-fields} +### Multiple policies in response -The server uses two custom fields, -namely `acme-RateLimit-DayLimit` and `acme-RateLimit-HourLimit` -to expose the following policy: +The server uses two different policies to limit the client's requests: - 5000 daily quota units; - 1000 hourly quota units. @@ -630,8 +629,9 @@ the closest limit to reach is the daily one. The server then exposes the RateLimit header fields to inform the client that: -- it has only 100 quota units left; -- the window will reset in 10 hours. +- it has only 100 quota units left in the daily quota and the window will reset in 10 hours; + +The server MAY choose to omit returning the hourly policy as it uses the same quota units as the daily policy and the daily policy is the one that is closest to being exhausted. Request: @@ -646,10 +646,7 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -acme-RateLimit-DayLimit: 5000 -acme-RateLimit-HourLimit: 1000 RateLimit: dayLimit;r=100;t=36000 -RateLimit: hourLimit;r=25;t=700 {"hello": "world"} ~~~ @@ -663,7 +660,6 @@ in case of saturation, thus increasing availability. The server adopted a basic policy of 100 quota units per minute, and in case of resource exhaustion adapts the returned values reducing both limit and remaining keyword values. -reducing both limit and remaining keyword values. After 2 seconds the client consumed 40 quota units @@ -687,8 +683,7 @@ RateLimit: basic;r=60;t=58 ~~~ At the subsequent request - due to resource exhaustion - -the server advertises only `remaining=20`. -the server advertises only `remaining=20`. +the server advertises only `r=20`. Request: @@ -743,7 +738,7 @@ RateLimit: default;r=0;t=5 } ~~~ -## Parameterized responses +## Responses with defined policies ### Throttling window specified via parameter @@ -812,8 +807,7 @@ RateLimit: dynamic;r=9;t=50 Continuing the previous example, let's say the client waits 10 seconds and performs a new request which, due to resource exhaustion, the server rejects -and pushes back, advertising `remaining=0` for the next 20 seconds. -and pushes back, advertising `remaining=0` for the next 20 seconds. +and pushes back, advertising `r=0` for the next 20 seconds. The server advertises a smaller window with a lower limit to slow down the client for the rest of its original window after the 20 seconds elapse. @@ -881,7 +875,7 @@ query again the server even if it is likely to have the request rejected. ### Missing Remaining information -The server does not expose remaining keyword values +The server does not expose remaining values (for example, because the underlying counters are not available). Instead, it resets the limit counter every second. @@ -901,7 +895,7 @@ Response: ~~~ http-message HTTP/1.1 200 Ok Content-Type: application/json -RateLimit-Policy: quota;l=100 +RateLimit-Policy: quota;l=100;w=1 RateLimit: quota;t=1 {"first": "request"} @@ -969,7 +963,7 @@ RateLimit: day;r=100;t=36000 1. Why defining standard fields for throttling? - To simplify enforcement of throttling policies. + To simplify enforcement of throttling policies and enable clients to constraint their requests to avoid being throttled. 2. Can I use RateLimit header fields in throttled responses (eg with status code 429)? @@ -979,27 +973,13 @@ RateLimit: day;r=100;t=36000 No. {{?RFC6585}} defines the `429` status code and we use it just as an example of a throttled request, that could instead use even `403` or whatever status code. - The goal of this specification is to standardize the name and semantic of three RateLimit header fields - widely used on the internet. Stricter relations with status codes or error response payloads - would impose behaviors to all the existing implementations making the adoption more complex. + +4. Why is the partition key necessary? -4. Why don't pass the throttling scope as a parameter? - - The word "scope" can have different meanings: - for example it can be an URL, or an authorization scope. - Since authorization is out of the scope of this document (see {{goals}}), - and that we rely only on {{HTTP}}, in {{goals}} we defined "scope" in terms of - URL. - - Since clients are not required to process quota policies (see {{receiving-fields}}), - we could add a new "RateLimit-Scope" field to this spec. - See this discussion on a [similar thread](https://github.com/httpwg/http-core/pull/317#issuecomment-585868767) - - Specific ecosystems can still bake their own prefixed parameters, - such as `acme-auth-scope` or `acme-url-scope` and ensure that clients process them. - This behavior cannot be relied upon when communicating between different ecosystems. - - We are open to suggestions: comment on [this issue](https://github.com/ioggstream/draft-polli-ratelimit-headers/issues/70) + Without a partition key, a server can only effectively only have one scope (aka partition), which is impractical for most services, or it needs to communicate the scopes out-of-band. + This prevents the development of generic connector code that can be used to prevent requests from being throttled. + Many APIs rely on API keys, user identity or client identity to allocate quota. + As soon as a single client processes requests for more than one partition, the client needs to know the corresponding partition key to properly track requests against allocated quota. 5. Why using delay-seconds instead of a UNIX Timestamp? Why not using subsecond precision? @@ -1022,14 +1002,11 @@ RateLimit: day;r=100;t=36000 on the [httpwg ml](https://lists.w3.org/Archives/Public/ietf-http-wg/2019JulSep/0202.html) - almost all rate-limit headers implementations do not use it. -6. - -7. Shouldn't I limit concurrency instead of request rate? +6. Shouldn't I limit concurrency instead of request rate? You can use this specification to limit concurrency at the HTTP level (see {#use-for-limiting-concurrency}) - and help clients to - shape their requests avoiding being throttled out. + and help clients to shape their requests avoiding being throttled out. A problematic way to limit concurrency is connection dropping, especially when connections are multiplexed (e.g. HTTP/2) @@ -1042,12 +1019,12 @@ RateLimit: day;r=100;t=36000 Saturation conditions can be either dynamic or static: all this is out of the scope for the current document. -8. Do a positive value of remaining keyword imply any service guarantee for my +7. Do a positive value of remaining paramter imply any service guarantee for my future requests to be served? No. FAQ integrated in {{ratelimit-remaining-parameter}}. -9. Is the quota-policy definition {{quota-policy}} too complex? +8. Is the quota-policy definition {{quota-policy}} too complex? You can always return the simplest form @@ -1065,35 +1042,7 @@ RateLimit: sliding;r=50;t=44 the value "sliding" identifies the policy being reported. -11. Can we use shorter names? Why don't put everything in one field? - - The most common syntax we found on the web is `X-RateLimit-*` and - when starting this I-D [we opted for it](https://github.com/ioggstream/draft-polli-ratelimit-headers/issues/34#issuecomment-519366481) - - The basic form of those fields is easily parseable, even by - implementers processing responses using technologies like - dynamic interpreter with limited syntax. - - Using a single field complicates parsing and takes - a significantly different approach from the existing - ones: this can limit adoption. - -12. Why don't mention connections? - - Beware of the term "connection": - - - it is just *one* possible saturation cause. Once you go that path - you will expose other infrastructural details (bandwidth, CPU, .. see {{sec-information-disclosure}}) - and complicate client compliance; - - it is an infrastructural detail defined in terms of server and network - rather than the consumed service. - This specification protects the services first, - and then the infrastructures through client cooperation (see {{sec-throttling-does-not-prevent}}). - - RateLimit header fields enable sending *on the same connection* different limit values - on each response, depending on the policy scope (e.g. per-user, per-custom-key, ..) - -13. Can intermediaries alter RateLimit header fields? +9. Can intermediaries alter RateLimit header fields? Generally, they should not because it might result in unserviced requests. There are reasonable use cases for intermediaries mangling RateLimit header fields though, @@ -1101,7 +1050,7 @@ RateLimit: sliding;r=50;t=44 or when they are an active component of the service. In those case we will consider them as part of the originating infrastructure. -14. Why the `w` parameter is just informative? +10. Why the `w` parameter is just informative? Could it be used by a client to determine the request rate? A non-informative `w` parameter might be fine in an environment @@ -1112,7 +1061,7 @@ RateLimit: sliding;r=50;t=44 for defining the throttling behavior. -15. Can I use RateLimit fields in trailers? +11. Can I use RateLimit fields in trailers? Servers usually establish whether the request is in-quota before creating a response, so the RateLimit field values should be already available in that moment. Supporting trailers has the only advantage that allows to provide more up-to-date information to the client in case of slow responses. However, this complicates client implementations with respect to combining fields from headers and accounting for intermediaries that drop trailers. @@ -1153,19 +1102,16 @@ A sliding window policy for example, may result in having a remaining keyword va e.g. ~~~ -RateLimit-Limit: 12 -RateLimit-Policy: 12;w=1 -RateLimit-Remaining: 6 ; using 50% of throughput, that is 6 units/s -RateLimit-Reset: 1 +RateLimit-Policy: sliding;l=12;w=1 +RateLimit: sliding;l=12;r=6;t=1 ; using 50% of throughput, that is 6 units/s + ~~~ If this is the case, the optimal solution is to achieve ~~~ -RateLimit-Limit: 12 -RateLimit-Policy: 12;w=1 -RateLimit-Remaining: 1 ; using 100% of throughput, that is 12 units/s -RateLimit-Reset: 1 +RateLimit-Policy: sliding;l=12;w=1 +RateLimit: sliding;l=12;r=1;t=1 ; using 100% of throughput, that is 12 units/s ~~~ At this point you should stop increasing your request rate. @@ -1191,10 +1137,18 @@ and Julian Reschke. # Changes {:numbered="false" removeinrfc="true"} +## Since draft-ietf-httpapi-ratelimit-headers-07 +{:numbered="false" removeinrfc="true"} + +* Refactored both fields to lists of Items that identify policy and use parameters +* Added quota unit parameter +* Added partition key parameter + + ## Since draft-ietf-httpapi-ratelimit-headers-03 {:numbered="false" removeinrfc="true"} -* Split policy informatio in RateLimit-Policy #81 +* Split policy informatiom in RateLimit-Policy #81 ## Since draft-ietf-httpapi-ratelimit-headers-02 From 2b47acdab290dc67bb13aa4b668ab8c7fb712597 Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Sun, 29 Sep 2024 14:37:29 -0400 Subject: [PATCH 24/28] Updated based on make linting errors --- .gitignore | 1 + draft-ietf-httpapi-ratelimit-headers.html | 2948 +++++++++++++++++++++ draft-ietf-httpapi-ratelimit-headers.md | 17 +- draft-ietf-httpapi-ratelimit-headers.md~ | 1169 ++++++++ draft-ietf-httpapi-ratelimit-headers.txt | 1435 ++++++++++ 5 files changed, 5561 insertions(+), 9 deletions(-) create mode 100644 .gitignore create mode 100644 draft-ietf-httpapi-ratelimit-headers.html create mode 100644 draft-ietf-httpapi-ratelimit-headers.md~ create mode 100644 draft-ietf-httpapi-ratelimit-headers.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7951405 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +lib \ No newline at end of file diff --git a/draft-ietf-httpapi-ratelimit-headers.html b/draft-ietf-httpapi-ratelimit-headers.html new file mode 100644 index 0000000..60ed7d9 --- /dev/null +++ b/draft-ietf-httpapi-ratelimit-headers.html @@ -0,0 +1,2948 @@ + + + + + + +RateLimit header fields for HTTP + + + + + + + + + + + + + + + + + + + + + + + + + +
Internet-DraftRateLimit header fields for HTTPSeptember 2024
Polli, et al.Expires 2 April 2025[Page]
+
+
+
+
Workgroup:
+
HTTPAPI
+
Internet-Draft:
+
draft-ietf-httpapi-ratelimit-headers-latest
+
Published:
+
+ +
+
Intended Status:
+
Standards Track
+
Expires:
+
+
Authors:
+
+
+
R. Polli
+
Team Digitale, Italian Government
+
+
+
A. Martinez
+
Red Hat
+
+
+
D. Miller
+
Microsoft
+
+
+
+
+

RateLimit header fields for HTTP

+
+

Abstract

+

This document defines the RateLimit-Policy and RateLimit HTTP header fields for servers to advertise their service policy limits and the current limits, thereby allowing clients to avoid being throttled.¶

+
+
+

+About This Document +

+

This note is to be removed before publishing as an RFC.¶

+

+ Status information for this document may be found at https://datatracker.ietf.org/doc/draft-ietf-httpapi-ratelimit-headers/.¶

+

+ Discussion of this document takes place on the + HTTPAPI Working Group mailing list (mailto:httpapi@ietf.org), + which is archived at https://mailarchive.ietf.org/arch/browse/httpapi/. + Subscribe at https://www.ietf.org/mailman/listinfo/httpapi/. + Working Group information can be found at https://datatracker.ietf.org/wg/httpapi/about/.¶

+

Source for this draft and an issue tracker can be found at + https://github.com/ietf-wg-httpapi/ratelimit-headers.¶

+
+
+
+

+Status of This Memo +

+

+ This Internet-Draft is submitted in full conformance with the + provisions of BCP 78 and BCP 79.¶

+

+ Internet-Drafts are working documents of the Internet Engineering Task + Force (IETF). Note that other groups may also distribute working + documents as Internet-Drafts. The list of current Internet-Drafts is + at https://datatracker.ietf.org/drafts/current/.¶

+

+ Internet-Drafts are draft documents valid for a maximum of six months + and may be updated, replaced, or obsoleted by other documents at any + time. It is inappropriate to use Internet-Drafts as reference + material or to cite them other than as "work in progress."¶

+

+ This Internet-Draft will expire on 2 April 2025.¶

+
+
+ +
+
+ â–²

+Table of Contents +

+ +
+
+
+
+

+1. Introduction +

+

Rate limiting of HTTP clients has become a widespread practice, especially for HTTP APIs. Typically, servers who do so limit the number of acceptable requests in a given time window (e.g. 10 requests per second). See Appendix A for further information on the current usage of rate limiting in HTTP.¶

+

Currently, there is no standard way for servers to communicate quotas so that clients can throttle their requests to prevent errors. This document defines a set of standard HTTP header fields to enable rate limiting:¶

+
    +
  • +

    RateLimit: to convey +the server's current limit of quota units available to the client in the policy time window, +the remaining quota units in the current window, +and the time remaining in the current window, specified in seconds, and¶

    +
  • +
  • +

    RateLimit-Policy: the service policy limits.¶

    +
  • +
+

These fields enable establishing complex rate limiting policies, including using multiple and variable time windows and dynamic quotas, and implementing concurrency limits.¶

+

The behavior of the RateLimit header field is compatible with the delay-seconds notation of Retry-After.¶

+
+
+

+1.1. Goals +

+

The goals of this document are:¶

+
+
Interoperability:
+
+

Standardize the names and semantics of rate-limit headers +to ease their enforcement and adoption;¶

+
+
+
Resiliency:
+
+

Improve resiliency of HTTP infrastructure by +providing clients with information useful +to throttle their requests and +prevent 4xx or 5xx responses;¶

+
+
+
Documentation:
+
+

Simplify API documentation by eliminating the need +to include detailed quota limits +and related fields in API documentation.¶

+
+
+
+

The following features are out of the scope of this document:¶

+
+
Authorization:
+
+

RateLimit header fields are not meant to support +authorization or other kinds of access controls.¶

+
+
+
Response status code:
+
+

RateLimit header fields may be returned in both +successful (see Section 15.3 of [HTTP]) and non-successful responses. +This specification does not cover whether non Successful +responses count on quota usage, +nor does it mandates any correlation between the RateLimit values +and the returned status code.¶

+
+
+
Throttling algorithm:
+
+

This specification does not mandate a specific throttling algorithm. +The values published in the fields, including the window size, +can be statically or dynamically evaluated.¶

+
+
+
Service Level Agreement:
+
+

Conveyed quota hints do not imply any service guarantee. +Server is free to throttle respectful clients under certain circumstances.¶

+
+
+
+
+
+
+
+

+1.2. Notational Conventions +

+

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL +NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", +"MAY", and "OPTIONAL" in this document are to be interpreted as +described in BCP 14 [RFC2119] [RFC8174] when, and only when, they +appear in all capitals, as shown here.¶

+

The term Origin is to be interpreted as described in Section 7 of [WEB-ORIGIN].¶

+

This document uses the terms List, Item and Integer from Section 3 of [STRUCTURED-FIELDS] to specify syntax and parsing, along with the concept of "bare item".¶

+
+
+
+
+
+
+

+2. Terminology +

+
+
+

+2.1. Quota +

+

A quota is an allocation of capacity to enable a server to limit client requests. That capacity is counted in quota units and may be reallocated at the end of a time window Section 2.4.¶

+
+
+
+
+

+2.2. Quota Unit +

+

A quota unit is the unit of measure used to count the activity of a client.¶

+
+
+
+
+

+2.3. Quota Partition +

+

A quota partition is a division of a server's capacity across different clients, users and owned resources.¶

+
+
+
+
+

+2.4. Time Window +

+

A time window indicates a period of time associated to the allocated quota.¶

+

The time window is a non-negative Integer value expressing an interval in seconds, similar to the "delay-seconds" rule defined in Section 10.2.3 of [HTTP]. Sub-second precision is not supported.¶

+
+
+
+
+

+2.5. Quota Policy +

+

A quota policy is maintained by a server to limit the activity (counted in quota units (Section 2.2)) of a given quota partition (Section 2.3) over a period of time (known as the time window (Section 2.4)) to a specified amount known as the Section 2.1.¶

+

Quota policies can be advertised by servers (see Section 3), but they are not required to be, and more than one quota policy can affect a given request from a client to a server.¶

+
+
+
+
+

+2.6. Service Limit +

+

A service limit is the current limit of the amount of activity that a server will allow based on the remaining quota for a particular quota partition within the time-window, if defined.¶

+
+
+
+
+
+
+

+3. RateLimit-Policy Field +

+

The "RateLimit-Policy" response header field is a non-empty List of Section 3.1. Its value is informative. The values are expected to remain consistent over a the lifetime of a connection. It is this characteristic that differentiates it from the RateLimit (Section 4) that contains values that may change on every request.¶

+
+
+   RateLimit-Policy: burst;q=100;w=60,daily;q=1000;w=86400
+
¶ +
+
+
+

+3.1. Quota Policy Item +

+

A quota policy Item contains information about a server's capacity allocation for a quota partition associated with the request.¶

+

The following parameters are defined in this specification:¶

+
+
q:
+
+

The REQUIRED "q" parameter indicates the quota allocated. (Section 3.1.1)¶

+
+
+
qu:
+
+

The OPTIONAL "qu" parameter value conveys the quota units associated to the "q" parameter. The default quota unit is "request". (Section 3.1.2)¶

+
+
+
w:
+
+

The OPTIONAL "w" parameter value conveys a time "window" (Section 2.4). (Section 3.1.3)¶

+
+
+
pk:
+
+

The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. Section 3.1.4¶

+
+
+
+

Other parameters are allowed and can be regarded as comments.¶

+

Implementation- or service-specific parameters SHOULD be prefixed parameters with a vendor identifier, e.g. acme-policy, acme-burst.¶

+
+
+

+3.1.1. Quota Parameter +

+

The "q" parameter uses a non-negative integer value to indicate the quota allocated for client activity (counted in quota units) for a given quota partition (Section 2.6).¶

+
+
+
+
+

+3.1.2. Quota Unit Parameter +

+

The "qu" parameter value conveys the quota units associated to the "q" parameter.¶

+
+
+
+
+

+3.1.3. Window Parameter +

+

The "w" parameter value conveys a time "window" in seconds. (Section 2.4).¶

+
+
+
+
+

+3.1.4. Partition Key Parameter +

+

The "pk" parameter value conveys the partition key associated to the request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key.¶

+
+
+
+
+
+
+

+3.2. RateLimit Policy Field Examples +

+

This field MAY convey the time window associated with the expiring-limit, as shown in this example:¶

+
+
+   RateLimit-Policy: default;l=100;w=10
+
¶ +
+

These examples show multiple policies being returned:¶

+
+
+   RateLimit-Policy: permin;l=50;w=60,perhr;l=1000;w=3600,perday;l=5000;w=86400
+
¶ +
+

The following example shows a policy with a partition key:¶

+
+
+   RateLimit-Policy: peruser;l=100;w=60;pk=user123
+
¶ +
+

The following example shows a policy with a partition key and a quota unit:¶

+
+
+   RateLimit-Policy: peruser;l=65535;w=10;pk=user123;qu=bytes
+
¶ +
+

This field cannot appear in a trailer section.¶

+
+
+
+
+
+
+

+4. RateLimit Field +

+

A server uses the "RateLimit" response header field to communicate the service limit for a quota policy for a particular partition key.¶

+

The field is expressed as List of Section 4.1.¶

+
+
+   RateLimit: default;r=50;t=30
+
¶ +
+
+
+

+4.1. Service Limit Item +

+

Each service limit item in identifies the quota policy associated with the request and¶

+

The following parameters are defined in this specification:¶

+
+
r:
+
+

This parameter value conveys the remaining quota units for the identified policy (Section 4.1.1).¶

+
+
+
t:
+
+

This OPTIONAL parameter value conveys the time window reset time for the identified policy (Section 4.1.2).¶

+
+
+
pk:
+
+

The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request.¶

+
+
+
+

This field cannot appear in a trailer section. Other parameters are allowed and can be regarded as comments.¶

+

Implementation- or service-specific parameters SHOULD be prefixed parameters with a vendor identifier, e.g. acme-policy, acme-burst.¶

+
+
+

+4.1.1. Remaining Parameter +

+

The "r" parameter indicates the remaining quota units for the identified policy (Section 4.1.1).¶

+

It is a non-negative Integer expressed in quota units (Section 2.2). +Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. +When remaining parameter value is low, it indicates that the server may soon throttle the client (see Section 5).¶

+
+
+
+
+

+4.1.2. Reset Parameter +

+

The "t" parameter indicates the number of seconds until the quota associated with the quota policy resets.¶

+

It is a non-negative Integer compatible with the delay-seconds rule, because:¶

+
    +
  • +

    it does not rely on clock synchronization and is resilient to clock adjustment +and clock skew between client and server (see Section 5.6.7 of [HTTP]);¶

    +
  • +
  • +

    it mitigates the risk related to thundering herd when too many clients are serviced with the same timestamp.¶

    +
  • +
+

The client MUST NOT assume that all its service limit will be reset at the moment indicated by the reset keyword. The server MAY arbitrarily alter the reset parameter value between subsequent requests; for example, in case of resource saturation or to implement sliding window policies.¶

+
+
+
+
+

+4.1.3. Partition Key Parameter +

+

The "pk" parameter value conveys the partition key associated to the request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key.¶

+
+
+
+
+
+
+

+4.2. RateLimit Field Examples +

+

This example shows a RateLimit field with a remaining quota of 50 units and a time window reset in 30 seconds:¶

+
+
+   RateLimit: default;r=50;t=30
+
¶ +
+

This example shows a remaining quota of 999 requests for a partition key that has no time window reset:¶

+
+
+   RateLimit: default;r=999;pk=trial-121323
+
¶ +
+

This example shows a 300MB remaining quota for an application in the next 60 seconds:¶

+
+
+   RateLimit: default;r=300000000;pk=App-999;t=60;qu=bytes
+
¶ +
+
+
+
+
+
+
+

+5. Server Behavior +

+

A server MAY return RateLimit header fields independently of the response status code. This includes on throttled responses. This document does not mandate any correlation between the RateLimit header field values and the returned status code.¶

+

Servers should be careful when returning RateLimit header fields in redirection responses (i.e., responses with 3xx status codes) because a low remaining keyword value could prevent the client from issuing requests. For example, given the RateLimit header fields below, a client could decide to wait 10 seconds before following the "Location" header field (see Section 10.2.2 of [HTTP]), because the remaining keyword value is 0.¶

+
+
+HTTP/1.1 301 Moved Permanently
+Location: /foo/123
+RateLimit: problemPolicy;r=0, t=10
+
+
¶ +
+

If a response contains both the Retry-After and the RateLimit header fields, the reset keyword value SHOULD reference the same point in time as the Retry-After field value.¶

+

A service using RateLimit header fields MUST NOT convey values exposing an unwanted volume of requests and SHOULD implement mechanisms to cap the ratio between the remaining and the reset keyword values (see Section 7.5); this is especially important when a quota policy uses a large time window.¶

+

Under certain conditions, a server MAY artificially lower RateLimit header field values between subsequent requests, e.g. to respond to Denial of Service attacks or in case of resource saturation.¶

+
+
+

+5.1. Performance Considerations +

+

Servers are not required to return RateLimit header fields in every response, and clients need to take this into account. For example, an implementer concerned with performance might provide RateLimit header fields only when a given quota is close to exhaustion.¶

+

Implementers concerned with response fields' size, might take into account their ratio with respect to the content length, or use header-compression HTTP features such as [HPACK].¶

+
+
+
+
+
+
+

+6. Client Behavior +

+

The RateLimit header fields can be used by clients to determine whether the associated request respected the server's quota policy, and as an indication of whether subsequent requests will. However, the server might apply other criteria when servicing future requests, and so the quota policy may not completely reflect whether requests will succeed.¶

+

For example, a successful response with the following fields:¶

+
+
+   RateLimit: default;r=1;t=7
+
¶ +
+

does not guarantee that the next request will be successful. Servers' behavior may be subject to other conditions.¶

+

A client is responsible for ensuring that RateLimit header field values returned +cause reasonable client behavior with respect to throughput and latency +(see Section 7.5 and Section 7.5.1).¶

+

A client receiving RateLimit header fields MUST NOT assume that future responses will contain the same RateLimit header fields, or any RateLimit header fields at all.¶

+

Malformed RateLimit header fields MUST be ignored.¶

+

A client SHOULD NOT exceed the quota units conveyed by the remaining keyword before the time window expressed in the reset keyword.¶

+

The value of the reset keyword is generated at response time: a client aware of a significant network latency MAY behave accordingly and use other information (e.g. the "Date" response header field, or otherwise gathered metrics) to better estimate the reset keyword moment intended by the server.¶

+

The details provided in the RateLimit-Policy header field are informative and MAY be ignored.¶

+

If a response contains both the RateLimit and Retry-After fields, the Retry-After field MUST take precedence and the reset keyword MAY be ignored.¶

+

This specification does not mandate a specific throttling behavior and implementers can adopt their preferred policies, including:¶

+
    +
  • +

    slowing down or pre-emptively back-off their request rate when +approaching quota limits;¶

    +
  • +
  • +

    consuming all the quota according to the exposed limits and then wait.¶

    +
  • +
+
+
+

+6.1. Intermediaries +

+

This section documents the considerations advised in Section 16.3.2 of [HTTP].¶

+

An intermediary that is not part of the originating service infrastructure and is not aware of the quota policy semantic used by the Origin Server SHOULD NOT alter the RateLimit header fields' values in such a way as to communicate a more permissive quota policy; this includes removing the RateLimit header fields.¶

+

An intermediary MAY alter the RateLimit header fields in such a way as to communicate a more restrictive quota policy when:¶

+
    +
  • +

    it is aware of the quota unit semantic used by the Origin Server;¶

    +
  • +
  • +

    it implements this specification and enforces a quota policy which +is more restrictive than the one conveyed in the fields.¶

    +
  • +
+

An intermediary SHOULD forward a request even when presuming that it might not be serviced; the service returning the RateLimit header fields is the sole responsible of enforcing the communicated quota policy, and it is always free to service incoming requests.¶

+

This specification does not mandate any behavior on intermediaries respect to retries, nor requires that intermediaries have any role in respecting quota policies. For example, it is legitimate for a proxy to retransmit a request without notifying the client, and thus consuming quota units.¶

+

Privacy considerations (Section 8) provide further guidance on intermediaries.¶

+
+
+
+
+

+6.2. Caching +

+

[HTTP-CACHING] defines how responses can be stored and reused for subsequent requests, +including those with RateLimit header fields. +Because the information in RateLimit header fields on a cached response may not be current, they SHOULD be ignored on responses that come from cache +(i.e., those with a positive current_age; see Section 4.2.3 of [HTTP-CACHING]).¶

+
+
+
+
+
+
+

+7. Security Considerations +

+
+
+

+7.1. Throttling does not prevent clients from issuing requests +

+

This specification does not prevent clients from making requests. +Servers should always implement mechanisms to prevent resource exhaustion.¶

+
+
+
+
+

+7.2. Information disclosure +

+

Servers should not disclose to untrusted parties operational capacity information +that can be used to saturate its infrastructural resources.¶

+

While this specification does not mandate whether non-successful responses consume quota, +if error responses (such as 401 (Unauthorized) and 403 (Forbidden)) count against quota, +a malicious client could probe the endpoint to get traffic information of another user.¶

+

As intermediaries might retransmit requests and consume +quota units without prior knowledge of the user agent, +RateLimit header fields might reveal the existence of an intermediary +to the user agent.¶

+

Where partition keys contain identifying information, either of the client application or the user, servers should be aware of the potential for impersonation and apply the appropriate security mechanisms.¶

+
+
+
+
+

+7.3. Remaining quota units are not granted requests +

+

RateLimit header fields convey hints from the server +to the clients in order to help them avoid being throttled out.¶

+

Clients MUST NOT consider the quota units (Section 2.6) returned in remaining keyword as a service level agreement.¶

+

In case of resource saturation, the server MAY artificially lower the returned values +or not serve the request regardless of the advertised quotas.¶

+
+
+
+
+

+7.4. Reliability of the reset keyword +

+

Consider that quota might not be restored after the moment referenced by the reset keyword (Section 4.1.2), +and the reset parameter value may not be constant.¶

+

Subsequent requests might return a higher reset parameter value +to limit concurrency or implement dynamic or adaptive throttling policies.¶

+
+
+
+
+

+7.5. Resource exhaustion +

+

When returning reset values, servers must be aware that +many throttled clients may come back at the very moment specified.¶

+

This is true for Retry-After too.¶

+

For example, if the quota resets every day at 18:00:00 +and your server returns the reset parameter accordingly¶

+
+
+   Date: Tue, 15 Nov 1994 18:00:00 GMT
+   RateLimit: daily;r=1;t=36400
+
¶ +
+

there's a high probability that all clients will show up at 18:00:00.¶

+

This could be mitigated by adding some jitter to the reset value.¶

+

Resource exhaustion issues can be associated with quota policies using a +large time window, because a user agent by chance or on purpose +might consume most of its quota units in a significantly shorter interval.¶

+

This behavior can be even triggered by the provided RateLimit header fields. +The following example describes a service +with an unconsumed quota policy of 10000 quota units per 1000 seconds.¶

+
+
+RateLimit-Policy: somepolicy;l=10000;w=1000
+RateLimit: somepolicy;r=10000;t=10
+
¶ +
+

A client implementing a simple ratio between remaining keyword and reset keyword could infer an average throughput of 1000 quota units per second, while the limit keyword conveys a quota-policy with an average of 10 quota units per second. +If the service cannot handle such load, it should return either a lower remaining keyword value or an higher reset keyword value. +Moreover, complementing large time window quota policies with a short time window one mitigates those risks.¶

+
+
+

+7.5.1. Denial of Service +

+

RateLimit header fields may contain unexpected values by chance or on purpose. +For example, an excessively high remaining keyword value may be:¶

+
    +
  • +

    used by a malicious intermediary to trigger a Denial of Service attack +or consume client resources boosting its requests;¶

    +
  • +
  • +

    passed by a misconfigured server;¶

    +
  • +
+

or a high reset keyword value could inhibit clients to contact the server (e.g. similarly to receiving "Retry-after: 1000000").¶

+

To mitigate this risk, clients can set thresholds that they consider reasonable in terms of quota units, time window, concurrent requests or throughput, and define a consistent behavior when the RateLimit exceed those thresholds. +For example this means capping the maximum number of request per second, or implementing retries when the reset keyword exceeds ten minutes.¶

+

The considerations above are not limited to RateLimit header fields, but apply to all fields affecting how clients behave in subsequent requests (e.g. Retry-After).¶

+
+
+
+
+
+
+
+
+

+8. Privacy Considerations +

+

Clients that act upon a request to rate limit +are potentially re-identifiable (see Section 5.2.1 of [PRIVACY]) +because they react to information that might only be given to them. +Note that this might apply to other fields too (e.g. Retry-After).¶

+

Since rate limiting is usually implemented in contexts where +clients are either identified or profiled +(e.g. assigning different quota units to different users), +this is rarely a concern.¶

+

Privacy enhancing infrastructures using RateLimit header fields +can define specific techniques to mitigate the risks of re-identification.¶

+
+
+
+
+

+9. IANA Considerations +

+

IANA is requested to update one registry and create one new registry.¶

+

Please add the following entries to the +"Hypertext Transfer Protocol (HTTP) Field Name Registry" registry ([HTTP]):¶

+ + + + + + + + + + + + + + + + + + + + + +
Table 1
Field NameStatusSpecification
RateLimitpermanent + Section 4 of RFC nnnn
RateLimit-Policypermanent + Section 3 of RFC nnnn
+
+
+
+

+10. References +

+
+
+

+10.1. Normative References +

+
+
[HTTP]
+
+Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, Ed., "HTTP Semantics", STD 97, RFC 9110, DOI 10.17487/RFC9110, , <https://www.rfc-editor.org/rfc/rfc9110>.
+
+
[IANA]
+
+Cotton, M., Leiba, B., and T. Narten, "Guidelines for Writing an IANA Considerations Section in RFCs", BCP 26, RFC 8126, DOI 10.17487/RFC8126, , <https://www.rfc-editor.org/rfc/rfc8126>.
+
+
[RFC2119]
+
+Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, , <https://www.rfc-editor.org/rfc/rfc2119>.
+
+
[RFC8174]
+
+Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, , <https://www.rfc-editor.org/rfc/rfc8174>.
+
+
[STRUCTURED-FIELDS]
+
+Nottingham, M. and P. Kamp, "Structured Field Values for HTTP", RFC 8941, DOI 10.17487/RFC8941, , <https://www.rfc-editor.org/rfc/rfc8941>.
+
+
[WEB-ORIGIN]
+
+Barth, A., "The Web Origin Concept", RFC 6454, DOI 10.17487/RFC6454, , <https://www.rfc-editor.org/rfc/rfc6454>.
+
+
+
+
+
+
+

+10.2. Informative References +

+
+
[HPACK]
+
+Peon, R. and H. Ruellan, "HPACK: Header Compression for HTTP/2", RFC 7541, DOI 10.17487/RFC7541, , <https://www.rfc-editor.org/rfc/rfc7541>.
+
+
[HTTP-CACHING]
+
+Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, Ed., "HTTP Caching", STD 98, RFC 9111, DOI 10.17487/RFC9111, , <https://www.rfc-editor.org/rfc/rfc9111>.
+
+
[PRIVACY]
+
+Cooper, A., Tschofenig, H., Aboba, B., Peterson, J., Morris, J., Hansen, M., and R. Smith, "Privacy Considerations for Internet Protocols", RFC 6973, DOI 10.17487/RFC6973, , <https://www.rfc-editor.org/rfc/rfc6973>.
+
+
[RFC3339]
+
+Klyne, G. and C. Newman, "Date and Time on the Internet: Timestamps", RFC 3339, DOI 10.17487/RFC3339, , <https://www.rfc-editor.org/rfc/rfc3339>.
+
+
[RFC6585]
+
+Nottingham, M. and R. Fielding, "Additional HTTP Status Codes", RFC 6585, DOI 10.17487/RFC6585, , <https://www.rfc-editor.org/rfc/rfc6585>.
+
+
[UNIX]
+
+The Open Group, "The Single UNIX Specification, Version 2 - 6 Vol Set for UNIX 98", .
+
+
+
+
+
+
+
+

+Appendix A. Rate-limiting and quotas +

+

Servers use quota mechanisms to avoid systems overload, to ensure an equitable distribution of computational resources or to enforce other policies - e.g. monetization.¶

+

A basic quota mechanism limits the number of acceptable requests in a given time window, e.g. 10 requests per second.¶

+

When quota is exceeded, servers usually do not serve the request replying instead with a 4xx HTTP status code (e.g. 429 or 403) or adopt more aggressive policies like dropping connections.¶

+

Quotas may be enforced on different basis (e.g. per user, per IP, per geographic area, ..) and at different levels. For example, an user may be allowed to issue:¶

+
    +
  • +

    10 requests per second;¶

    +
  • +
  • +

    limited to 60 requests per minute;¶

    +
  • +
  • +

    limited to 1000 requests per hour.¶

    +
  • +
+

Moreover system metrics, statistics and heuristics can be used to implement more complex policies, +where the number of acceptable requests and the time window are computed dynamically.¶

+

To help clients throttling their requests, +servers may expose the counters used to evaluate quota policies via HTTP header fields.¶

+

Those response headers may be added by HTTP intermediaries such as API gateways and reverse proxies.¶

+

On the web we can find many different rate-limit headers, +usually containing the number of allowed requests in a given time window, and when the window is reset.¶

+

The common choice is to return three headers containing:¶

+
    +
  • +

    the maximum number of allowed requests in the time window;¶

    +
  • +
  • +

    the number of remaining requests in the current window;¶

    +
  • +
  • +

    the time remaining in the current window expressed in seconds or +as a timestamp;¶

    +
  • +
+
+
+

+A.1. Interoperability issues +

+

A major interoperability issue in throttling is the lack of standard headers, because:¶

+
    +
  • +

    each implementation associates different semantics to the +same header field names;¶

    +
  • +
  • +

    header field names proliferates.¶

    +
  • +
+

User agents interfacing with different servers may thus need to process different headers, +or the very same application interface that sits behind different reverse proxies +may reply with different throttling headers.¶

+
+
+
+
+
+
+

+Appendix B. Examples +

+
+
+

+B.1. Responses without defining policies +

+

Some servers may not expose the policy limits in the RateLimit-Policy header field. Clients can still use the RateLimit header field to throttle their requests.¶

+
+
+

+B.1.1. Throttling information in responses +

+

The client exhausted its quota for the next 50 seconds. +The limit and time-window is communicated out-of-band.¶

+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 200 Ok
+Content-Type: application/json
+RateLimit: default;r=0;t=50
+
+{"hello": "world"}
+
¶ +
+

Since the field values are not necessarily correlated with +the response status code, +a subsequent request is not required to fail. +The example below shows that the server decided to serve the request +even if remaining keyword value is 0. +Another server, or the same server under other load conditions, could have decided to throttle the request instead.¶

+

Request:¶

+
+
+GET /items/456 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 200 Ok
+Content-Type: application/json
+RateLimit: default;r=0;t=48
+
+{"still": "successful"}
+
¶ +
+
+
+
+
+

+B.1.2. Multiple policies in response +

+

The server uses two different policies to limit the client's requests:¶

+
    +
  • +

    5000 daily quota units;¶

    +
  • +
  • +

    1000 hourly quota units.¶

    +
  • +
+

The client consumed 4900 quota units in the first 14 hours.¶

+

Despite the next hourly limit of 1000 quota units, +the closest limit to reach is the daily one.¶

+

The server then exposes the RateLimit header fields to +inform the client that:¶

+
    +
  • +

    it has only 100 quota units left in the daily quota and the window will reset in 10 hours;¶

    +
  • +
+

The server MAY choose to omit returning the hourly policy as it uses the same quota units as the daily policy and the daily policy is the one that is closest to being exhausted.¶

+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 200 Ok
+Content-Type: application/json
+RateLimit: dayLimit;r=100;t=36000
+
+{"hello": "world"}
+
¶ +
+
+
+
+
+

+B.1.3. Use for limiting concurrency +

+

RateLimit header fields may be used to limit concurrency, +advertising limits that are lower than the usual ones +in case of saturation, thus increasing availability.¶

+

The server adopted a basic policy of 100 quota units per minute, +and in case of resource exhaustion adapts the returned values +reducing both limit and remaining keyword values.¶

+

After 2 seconds the client consumed 40 quota units¶

+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 200 Ok
+Content-Type: application/json
+RateLimit-Policy: basic;l=100;w=60
+RateLimit: basic;r=60;t=58
+
+{"elapsed": 2, "issued": 40}
+
¶ +
+

At the subsequent request - due to resource exhaustion - +the server advertises only r=20.¶

+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 200 Ok
+Content-Type: application/json
+RateLimit-Policy: basic;l=100;w=60
+RateLimit: basic;r=20;t=56
+
+{"elapsed": 4, "issued": 41}
+
¶ +
+
+
+
+
+

+B.1.4. Use in throttled responses +

+

A client exhausted its quota and the server throttles it +sending Retry-After.¶

+

In this example, the values of Retry-After and RateLimit header field reference the same moment, +but this is not a requirement.¶

+

The 429 (Too Many Request) HTTP status code is just used as an example.¶

+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 429 Too Many Requests
+Content-Type: application/json
+Date: Mon, 05 Aug 2019 09:27:00 GMT
+Retry-After: Mon, 05 Aug 2019 09:27:05 GMT
+RateLimit: default;r=0;t=5
+
+{
+"title": "Too Many Requests",
+"status": 429,
+"detail": "You have exceeded your quota"
+}
+
¶ +
+
+
+
+
+
+
+

+B.2. Responses with defined policies +

+
+
+

+B.2.1. Throttling window specified via parameter +

+

The client has 99 quota units left for the next 50 seconds. +The time window is communicated by the w parameter, so we know the throughput is 100 quota units per minute.¶

+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 200 Ok
+Content-Type: application/json
+RateLimit: fixedwindow;r=99;t=50
+RateLimit-Policy: fixedwindow;l=100;w=60
+{"hello": "world"}
+
¶ +
+
+
+
+
+

+B.2.2. Dynamic limits with parameterized windows +

+

The policy conveyed by the RateLimit header field states that +the server accepts 100 quota units per minute.¶

+

To avoid resource exhaustion, the server artificially lowers +the actual limits returned in the throttling headers.¶

+

The remaining keyword then advertises +only 9 quota units for the next 50 seconds to slow down the client.¶

+

Note that the server could have lowered even the other +values in the RateLimit header field: this specification +does not mandate any relation between the field values +contained in subsequent responses.¶

+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 200 Ok
+Content-Type: application/json
+RateLimit-Policy: dynamic;l=100;w=60
+RateLimit: dynamic;r=9;t=50
+
+
+{
+  "status": 200,
+  "detail": "Just slow down without waiting."
+}
+
¶ +
+
+
+
+
+

+B.2.3. Dynamic limits for pushing back and slowing down +

+

Continuing the previous example, let's say the client waits 10 seconds and +performs a new request which, due to resource exhaustion, the server rejects +and pushes back, advertising r=0 for the next 20 seconds.¶

+

The server advertises a smaller window with a lower limit to slow +down the client for the rest of its original window after the 20 seconds elapse.¶

+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 429 Too Many Requests
+Content-Type: application/json
+RateLimit-Policy: dynamic;l=15;w=20
+RateLimit: dynamic;r=0;t=20
+
+{
+  "status": 429,
+  "detail": "Wait 20 seconds, then slow down!"
+}
+
¶ +
+
+
+
+
+
+
+

+B.3. Dynamic limits for pushing back with Retry-After and slow down +

+

Alternatively, given the same context where the previous example starts, we +can convey the same information to the client via Retry-After, with +the advantage that the server can now specify the policy's nominal limit and +window that will apply after the reset, e.g. assuming the resource exhaustion +is likely to be gone by then, so the advertised policy does not need to be +adjusted, yet we managed to stop requests for a while and slow down the rest of +the current window.¶

+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 429 Too Many Requests
+Content-Type: application/json
+Retry-After: 20
+RateLimit-Policy: dynamic;l=100;w=60
+RateLimit: dynamic;r=15;t=40
+
+{
+  "status": 429,
+  "detail": "Wait 20 seconds, then slow down!"
+}
+
¶ +
+

Note that in this last response the client is expected to honor +Retry-After and perform no requests for the specified amount of +time, whereas the previous example would not force the client to stop +requests before the reset time is elapsed, as it would still be free to +query again the server even if it is likely to have the request rejected.¶

+
+
+

+B.3.1. Missing Remaining information +

+

The server does not expose remaining values +(for example, because the underlying counters are not available). +Instead, it resets the limit counter every second.¶

+

It communicates to the client the limit of 10 quota units per second +always returning the limit and reset keywords.¶

+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 200 Ok
+Content-Type: application/json
+RateLimit-Policy: quota;l=100;w=1
+RateLimit: quota;t=1
+
+{"first": "request"}
+
¶ +
+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 200 Ok
+Content-Type: application/json
+RateLimit-Policy: quota;l=10
+RateLimit: quota;t=1
+
+{"second": "request"}
+
¶ +
+
+
+
+
+

+B.3.2. Use with multiple windows +

+

This is a standardized way of describing the policy +detailed in Appendix B.1.2:¶

+
    +
  • +

    5000 daily quota units;¶

    +
  • +
  • +

    1000 hourly quota units.¶

    +
  • +
+

The client consumed 4900 quota units in the first 14 hours.¶

+

Despite the next hourly limit of 1000 quota units, the closest limit +to reach is the daily one.¶

+

The server then exposes the RateLimit header fields to inform the client that:¶

+
    +
  • +

    it has only 100 quota units left;¶

    +
  • +
  • +

    the window will reset in 10 hours;¶

    +
  • +
  • +

    the expiring-limit is 5000.¶

    +
  • +
+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 200 OK
+Content-Type: application/json
+RateLimit-Policy: hour;l=1000;w=3600, day;l=5000;w=86400
+RateLimit: day;r=100;t=36000
+
+{"hello": "world"}
+
¶ +
+
+
+
+
+
+
+
+
+

+FAQ +

+

This section is to be removed before publishing as an RFC.¶

+
    +
  1. +

    Why defining standard fields for throttling?¶

    +

    +To simplify enforcement of throttling policies and enable clients to constraint their requests to avoid being throttled.¶

    +
  2. +
  3. +

    Can I use RateLimit header fields in throttled responses (eg with status code 429)?¶

    +

    +Yes, you can.¶

    +
  4. +
  5. +

    Are those specs tied to RFC 6585?¶

    +

    +No. [RFC6585] defines the 429 status code and we use it just as an example of a throttled request, +that could instead use even 403 or whatever status code.¶

    +
  6. +
  7. +

    Why is the partition key necessary?¶

    +

    +Without a partition key, a server can only effectively only have one scope (aka partition), which is impractical for most services, or it needs to communicate the scopes out-of-band. +This prevents the development of generic connector code that can be used to prevent requests from being throttled. +Many APIs rely on API keys, user identity or client identity to allocate quota. +As soon as a single client processes requests for more than one partition, the client needs to know the corresponding partition key to properly track requests against allocated quota.¶

    +
  8. +
  9. +

    Why using delay-seconds instead of a UNIX Timestamp? +Why not using subsecond precision?¶

    +

    +Using delay-seconds aligns with Retry-After, which is returned in similar contexts, +eg on 429 responses.¶

    +

    +Timestamps require a clock synchronization protocol +(see Section 5.6.7 of [HTTP]). +This may be problematic (e.g. clock adjustment, clock skew, failure of hardcoded clock synchronization servers, +IoT devices, ..). +Moreover timestamps may not be monotonically increasing due to clock adjustment. +See Another NTP client failure story¶

    +

    +We did not use subsecond precision because:¶

    +
      +
    • +

      that is more subject to system clock correction +like the one implemented via the adjtimex() Linux system call;¶

      +
    • +
    • +

      response-time latency may not make it worth. A brief discussion on the subject is +on the httpwg ml¶

      +
    • +
    • +

      almost all rate-limit headers implementations do not use it.¶

      +
    • +
    +
  10. +
  11. +

    Shouldn't I limit concurrency instead of request rate?¶

    +

    +You can use this specification to limit concurrency +at the HTTP level (see {#use-for-limiting-concurrency}) +and help clients to shape their requests avoiding being throttled out.¶

    +

    +A problematic way to limit concurrency is connection dropping, +especially when connections are multiplexed (e.g. HTTP/2) +because this results in unserviced client requests, +which is something we want to avoid.¶

    +

    +A semantic way to limit concurrency is to return 503 + Retry-After +in case of resource saturation (e.g. thrashing, connection queues too long, +Service Level Objectives not meet, ..). +Saturation conditions can be either dynamic or static: all this is out of +the scope for the current document.¶

    +
  12. +
  13. +

    Do a positive value of remaining paramter imply any service guarantee for my +future requests to be served?¶

    +

    +No. FAQ integrated in Section 4.1.1.¶

    +
  14. +
  15. +

    Is the quota-policy definition Section 2.5 too complex?¶

    +

    +You can always return the simplest form¶

    +
  16. +
+
+
+RateLimit:default;r=50;t=60
+
¶ +
+

The policy key clearly connects the current usage status of a policy to the defined limits. + So for the following field:¶

+
+
+RateLimit-Policy: sliding;l=100;w=60;burst=1000;comment="sliding window", fixed;l=5000;w=3600;burst=0;comment="fixed window"
+RateLimit: sliding;r=50;t=44
+
¶ +
+

the value "sliding" identifies the policy being reported.¶

+
    +
  1. +

    Can intermediaries alter RateLimit header fields?¶

    +

    +Generally, they should not because it might result in unserviced requests. + There are reasonable use cases for intermediaries mangling RateLimit header fields though, + e.g. when they enforce stricter quota-policies, + or when they are an active component of the service. + In those case we will consider them as part of the originating infrastructure.¶

    +
  2. +
  3. +

    Why the w parameter is just informative? +Could it be used by a client to determine the request rate?¶

    +

    +A non-informative w parameter might be fine in an environment +where clients and servers are tightly coupled. Conveying policies +with this detail on a large scale would be very complex and implementations +would be likely not interoperable. We thus decided to leave w as +an informational parameter and only rely on the limit, remaining and reset keywords +for defining the throttling +behavior.¶

    +
  4. +
  5. +

    Can I use RateLimit fields in trailers? +Servers usually establish whether the request is in-quota before creating a response, so the RateLimit field values should be already available in that moment. +Supporting trailers has the only advantage that allows to provide more up-to-date information to the client in case of slow responses. +However, this complicates client implementations with respect to combining fields from headers and accounting for intermediaries that drop trailers. +Since there are no current implementations that use trailers, we decided to leave this as a future-work.¶

    +
  6. +
+
+
+
+
+

+RateLimit header fields currently used on the web +

+

This section is to be removed before publishing as an RFC.¶

+

Commonly used header field names are:¶

+
    +
  • +

    X-RateLimit-Limit, +X-RateLimit-Remaining, +X-RateLimit-Reset;¶

    +
  • +
+

There are variants too, where the window is specified +in the header field name, eg:¶

+
    +
  • +

    x-ratelimit-limit-minute, x-ratelimit-limit-hour, x-ratelimit-limit-day¶

    +
  • +
  • +

    x-ratelimit-remaining-minute, x-ratelimit-remaining-hour, x-ratelimit-remaining-day¶

    +
  • +
+

Here are some interoperability issues:¶

+
    +
  • +

    X-RateLimit-Remaining references different values, depending on the implementation:¶

    +
      +
    • +

      seconds remaining to the window expiration¶

      +
    • +
    • +

      milliseconds remaining to the window expiration¶

      +
    • +
    • +

      seconds since UTC, in UNIX Timestamp [UNIX]¶

      +
    • +
    • +

      a datetime, either IMF-fixdate [HTTP] or [RFC3339]¶

      +
    • +
    +
  • +
  • +

    different headers, with the same semantic, are used by different implementers:¶

    +
      +
    • +

      X-RateLimit-Limit and X-Rate-Limit-Limit¶

      +
    • +
    • +

      X-RateLimit-Remaining and X-Rate-Limit-Remaining¶

      +
    • +
    • +

      X-RateLimit-Reset and X-Rate-Limit-Reset¶

      +
    • +
    +
  • +
+

The semantic of RateLimit depends on the windowing algorithm. +A sliding window policy for example, may result in having a remaining keyword value related to the ratio between the current and the maximum throughput. +e.g.¶

+
+
+RateLimit-Policy: sliding;l=12;w=1
+RateLimit: sliding;l=12;r=6;t=1          ; using 50% of throughput, that is 6 units/s
+
+
¶ +
+

If this is the case, the optimal solution is to achieve¶

+
+
+RateLimit-Policy: sliding;l=12;w=1
+RateLimit: sliding;l=12;r=1;t=1          ; using 100% of throughput, that is 12 units/s
+
¶ +
+

At this point you should stop increasing your request rate.¶

+
+
+
+
+

+Acknowledgements +

+

Thanks to Willi Schoenborn, Alejandro Martinez Ruiz, Alessandro Ranellucci, +Amos Jeffries, +Martin Thomson, +Erik Wilde and Mark Nottingham for being the initial contributors +of these specifications. +Kudos to the first community implementers: +Aapo Talvensaari, +Nathan Friedly +and Sanyam Dogra.¶

+

In addition to the people above, this document owes a lot to the extensive discussion in the HTTPAPI workgroup, including +Rich Salz, +Darrel Miller +and Julian Reschke.¶

+
+
+
+
+

+Changes +

+

This section is to be removed before publishing as an RFC.¶

+
+
+

+Since draft-ietf-httpapi-ratelimit-headers-07 +

+

This section is to be removed before publishing as an RFC.¶

+
    +
  • +

    Refactored both fields to lists of Items that identify policy and use parameters¶

    +
  • +
  • +

    Added quota unit parameter¶

    +
  • +
  • +

    Added partition key parameter¶

    +
  • +
+
+
+
+
+

+Since draft-ietf-httpapi-ratelimit-headers-03 +

+

This section is to be removed before publishing as an RFC.¶

+
    +
  • +

    Split policy informatiom in RateLimit-Policy #81¶

    +
  • +
+
+
+
+
+

+Since draft-ietf-httpapi-ratelimit-headers-02 +

+

This section is to be removed before publishing as an RFC.¶

+
    +
  • +

    Address throttling scope #83¶

    +
  • +
+
+
+
+
+

+Since draft-ietf-httpapi-ratelimit-headers-01 +

+

This section is to be removed before publishing as an RFC.¶

+
    +
  • +

    Update IANA considerations #60¶

    +
  • +
  • +

    Use Structured fields #58¶

    +
  • +
  • +

    Reorganize document #67¶

    +
  • +
+
+
+
+
+

+Since draft-ietf-httpapi-ratelimit-headers-00 +

+

This section is to be removed before publishing as an RFC.¶

+
    +
  • +

    Use I-D.httpbis-semantics, which includes referencing delay-seconds +instead of delta-seconds. #5¶

    +
  • +
+
+
+
+
+
+
+

+Authors' Addresses +

+
+
Roberto Polli
+
Team Digitale, Italian Government
+
Italy
+ +
+
+
Alejandro Martinez Ruiz
+
Red Hat
+ +
+
+
Darrel Miller
+
Microsoft
+ +
+
+
+ + + diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index 2294126..2fcf76d 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -147,7 +147,7 @@ The time window is a non-negative Integer value expressing an interval in second ## Quota Policy {#quota-policy} -A quota policy is maintained by a server to limit the activity (counted in [quota units](#quota-units)) of a given [quota partition](#quota-partition) over a period of time (known as the [time window](#time-window)) to a specified amount known as the [quota](#quota). +A quota policy is maintained by a server to limit the activity (counted in [quota units](#quota-unit)) of a given [quota partition](#quota-partition) over a period of time (known as the [time window](#time-window)) to a specified amount known as the [quota](#quota). Quota policies can be advertised by servers (see {{ratelimit-policy-field}}), but they are not required to be, and more than one quota policy can affect a given request from a client to a server. @@ -211,7 +211,7 @@ This field MAY convey the time window associated with the expiring-limit, as sho These examples show multiple policies being returned: ~~~ - RateLimit-Policy: permin;l=50;w=60, perhr;l=1000;w=3600, perday;l=5000;w=86400 + RateLimit-Policy: permin;l=50;w=60,perhr;l=1000;w=3600,perday;l=5000;w=86400 ~~~ The following example shows a policy with a partition key: @@ -240,7 +240,7 @@ The field is expressed as List of {{servicelimit-item}}. ## Service Limit Item {#servicelimit-item} -Each service limit item in identifies the quota policy associated with the request and +Each service limit item in identifies the quota policy associated with the request and The following parameters are defined in this specification: @@ -251,7 +251,7 @@ The following parameters are defined in this specification: : This OPTIONAL parameter value conveys the time window reset time for the identified policy ({{ratelimit-reset-parameter}}). pk: - : The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. + : The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. This field cannot appear in a trailer section. Other parameters are allowed and can be regarded as comments. @@ -262,7 +262,7 @@ Implementation- or service-specific parameters SHOULD be prefixed parameters wit The "r" parameter indicates the remaining quota units for the identified policy ({{ratelimit-remaining-parameter}}). -It is a non-negative Integer expressed in [quota units](#quota-units). +It is a non-negative Integer expressed in [quota units](#quota-unit). Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When remaining parameter value is low, it indicates that the server may soon throttle the client (see {{providing-ratelimit-fields}}). @@ -329,7 +329,6 @@ Servers are not required to return RateLimit header fields in every response, an Implementers concerned with response fields' size, might take into account their ratio with respect to the content length, or use header-compression HTTP features such as {{?HPACK=RFC7541}}. - # Client Behavior {#receiving-fields} The RateLimit header fields can be used by clients to determine whether the associated request respected the server's quota policy, and as an indication of whether subsequent requests will. However, the server might apply other criteria when servicing future requests, and so the quota policy may not completely reflect whether requests will succeed. @@ -614,7 +613,7 @@ RateLimit: default;r=0;t=48 {"still": "successful"} ~~~ -### Multiple policies in response +### Multiple policies in response {#use-with-multiple-policies} The server uses two different policies to limit the client's requests: @@ -923,7 +922,7 @@ RateLimit: quota;t=1 ### Use with multiple windows This is a standardized way of describing the policy -detailed in {{use-with-custom-fields}}: +detailed in {{use-with-multiple-policies}}: - 5000 daily quota units; - 1000 hourly quota units. @@ -973,7 +972,7 @@ RateLimit: day;r=100;t=36000 No. {{?RFC6585}} defines the `429` status code and we use it just as an example of a throttled request, that could instead use even `403` or whatever status code. - + 4. Why is the partition key necessary? Without a partition key, a server can only effectively only have one scope (aka partition), which is impractical for most services, or it needs to communicate the scopes out-of-band. diff --git a/draft-ietf-httpapi-ratelimit-headers.md~ b/draft-ietf-httpapi-ratelimit-headers.md~ new file mode 100644 index 0000000..2fcf76d --- /dev/null +++ b/draft-ietf-httpapi-ratelimit-headers.md~ @@ -0,0 +1,1169 @@ +--- +title: RateLimit header fields for HTTP +abbrev: +docname: draft-ietf-httpapi-ratelimit-headers-latest +category: std + +ipr: trust200902 +area: Applications and Real-Time +workgroup: HTTPAPI +keyword: Internet-Draft + +stand_alone: yes +pi: [toc, tocindent, sortrefs, symrefs, strict, compact, comments, inline, docmapping] + +venue: + group: HTTPAPI + type: Working Group + home: https://datatracker.ietf.org/wg/httpapi/about/ + mail: httpapi@ietf.org + arch: https://mailarchive.ietf.org/arch/browse/httpapi/ + repo: https://github.com/ietf-wg-httpapi/ratelimit-headers + +author: + - + ins: R. Polli + name: Roberto Polli + org: Team Digitale, Italian Government + email: robipolli@gmail.com + country: Italy + - + ins: A. Martinez + name: Alejandro Martinez Ruiz + org: Red Hat + email: alex@flawedcode.org + - + ins: D. Miller + name: Darrel Miller + org: Microsoft + email: darrel@tavis.ca + +entity: + SELF: "RFC nnnn" + +normative: + IANA: RFC8126 + HTTP: RFC9110 + +informative: + PRIVACY: RFC6973 + UNIX: + title: The Single UNIX Specification, Version 2 - 6 Vol Set for UNIX 98 + author: + name: The Open Group + ins: The Open Group + date: 1997-02 +--- abstract + +This document defines the RateLimit-Policy and RateLimit HTTP header fields for servers to advertise their service policy limits and the current limits, thereby allowing clients to avoid being throttled. + +--- middle + +# Introduction + +Rate limiting of HTTP clients has become a widespread practice, especially for HTTP APIs. Typically, servers who do so limit the number of acceptable requests in a given time window (e.g. 10 requests per second). See {{rate-limiting}} for further information on the current usage of rate limiting in HTTP. + +Currently, there is no standard way for servers to communicate quotas so that clients can throttle their requests to prevent errors. This document defines a set of standard HTTP header fields to enable rate limiting: + +- RateLimit: to convey + the server's current limit of quota units available to the client in the policy time window, + the remaining quota units in the current window, + and the time remaining in the current window, specified in seconds, and +- RateLimit-Policy: the service policy limits. + +These fields enable establishing complex rate limiting policies, including using multiple and variable time windows and dynamic quotas, and implementing concurrency limits. + +The behavior of the RateLimit header field is compatible with the delay-seconds notation of Retry-After. + +## Goals {#goals} + +The goals of this document are: + + Interoperability: + : Standardize the names and semantics of rate-limit headers + to ease their enforcement and adoption; + + Resiliency: + : Improve resiliency of HTTP infrastructure by + providing clients with information useful + to throttle their requests and + prevent 4xx or 5xx responses; + + Documentation: + : Simplify API documentation by eliminating the need + to include detailed quota limits + and related fields in API documentation. + +The following features are out of the scope of this document: + + Authorization: + : RateLimit header fields are not meant to support + authorization or other kinds of access controls. + + Response status code: + : RateLimit header fields may be returned in both + successful (see {{Section 15.3 of HTTP}}) and non-successful responses. + This specification does not cover whether non Successful + responses count on quota usage, + nor does it mandates any correlation between the RateLimit values + and the returned status code. + + Throttling algorithm: + : This specification does not mandate a specific throttling algorithm. + The values published in the fields, including the window size, + can be statically or dynamically evaluated. + + Service Level Agreement: + : Conveyed quota hints do not imply any service guarantee. + Server is free to throttle respectful clients under certain circumstances. + +## Notational Conventions + +{::boilerplate bcp14} + +The term Origin is to be interpreted as described in Section 7 of {{!WEB-ORIGIN=RFC6454}}. + +This document uses the terms List, Item and Integer from {{Section 3 of !STRUCTURED-FIELDS=RFC8941}} to specify syntax and parsing, along with the concept of "bare item". + +# Terminology + +## Quota {#quota} + +A quota is an allocation of capacity to enable a server to limit client requests. That capacity is counted in quota units and may be reallocated at the end of a time window {{time-window}}. + +## Quota Unit {#quota-unit} + +A quota unit is the unit of measure used to count the activity of a client. + +## Quota Partition {#quota-partition} + +A quota partition is a division of a server's capacity across different clients, users and owned resources. + +## Time Window {#time-window} + +A time window indicates a period of time associated to the allocated quota. + +The time window is a non-negative Integer value expressing an interval in seconds, similar to the "delay-seconds" rule defined in {{Section 10.2.3 of HTTP}}. Sub-second precision is not supported. + +## Quota Policy {#quota-policy} + +A quota policy is maintained by a server to limit the activity (counted in [quota units](#quota-unit)) of a given [quota partition](#quota-partition) over a period of time (known as the [time window](#time-window)) to a specified amount known as the [quota](#quota). + +Quota policies can be advertised by servers (see {{ratelimit-policy-field}}), but they are not required to be, and more than one quota policy can affect a given request from a client to a server. + +## Service Limit {#service-limit} + +A service limit is the current limit of the amount of activity that a server will allow based on the remaining quota for a particular quota partition within the time-window, if defined. + +# RateLimit-Policy Field {#ratelimit-policy-field} + +The "RateLimit-Policy" response header field is a non-empty List of {{quotapolicy-item}}. Its value is informative. The values are expected to remain consistent over a the lifetime of a connection. It is this characteristic that differentiates it from the [RateLimit](#ratelimit-field) that contains values that may change on every request. + +~~~ + RateLimit-Policy: burst;q=100;w=60,daily;q=1000;w=86400 +~~~ + +## Quota Policy Item {#quotapolicy-item} +A quota policy Item contains information about a server's capacity allocation for a quota partition associated with the request. + +The following parameters are defined in this specification: + + q: + : The REQUIRED "q" parameter indicates the quota allocated. ({{ratelimitpolicy-quota}}) + + qu: + : The OPTIONAL "qu" parameter value conveys the quota units associated to the "q" parameter. The default quota unit is "request". ({{ratelimitpolicy-quotaunit}}) + + w: + : The OPTIONAL "w" parameter value conveys a time "window" ({{time-window}}). ({{ratelimitpolicy-window}}) + + pk: + : The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. {{ratelimitpolicy-partitionkey}} + +Other parameters are allowed and can be regarded as comments. + +Implementation- or service-specific parameters SHOULD be prefixed parameters with a vendor identifier, e.g. `acme-policy`, `acme-burst`. + +### Quota Parameter {#ratelimitpolicy-quota} + + The "q" parameter uses a non-negative integer value to indicate the quota allocated for client activity (counted in quota units) for a given quota partition ({{service-limit}}). + +### Quota Unit Parameter {#ratelimitpolicy-quotaunit} + +The "qu" parameter value conveys the quota units associated to the "q" parameter. + +### Window Parameter {#ratelimitpolicy-window} + +The "w" parameter value conveys a time "window" in seconds. ({{time-window}}). + +### Partition Key Parameter {#ratelimitpolicy-partitionkey} + +The "pk" parameter value conveys the partition key associated to the request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key. + +## RateLimit Policy Field Examples + +This field MAY convey the time window associated with the expiring-limit, as shown in this example: + +~~~ + RateLimit-Policy: default;l=100;w=10 +~~~ + +These examples show multiple policies being returned: + +~~~ + RateLimit-Policy: permin;l=50;w=60,perhr;l=1000;w=3600,perday;l=5000;w=86400 +~~~ + +The following example shows a policy with a partition key: + +~~~ + RateLimit-Policy: peruser;l=100;w=60;pk=user123 +~~~ + +The following example shows a policy with a partition key and a quota unit: + +~~~ + RateLimit-Policy: peruser;l=65535;w=10;pk=user123;qu=bytes +~~~ + +This field cannot appear in a trailer section. + +# RateLimit Field {#ratelimit-field} + +A server uses the "RateLimit" response header field to communicate the service limit for a quota policy for a particular partition key. + +The field is expressed as List of {{servicelimit-item}}. + +~~~ + RateLimit: default;r=50;t=30 +~~~ + +## Service Limit Item {#servicelimit-item} + +Each service limit item in identifies the quota policy associated with the request and + +The following parameters are defined in this specification: + + r: + : This parameter value conveys the remaining quota units for the identified policy ({{ratelimit-remaining-parameter}}). + + t: + : This OPTIONAL parameter value conveys the time window reset time for the identified policy ({{ratelimit-reset-parameter}}). + + pk: + : The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. + +This field cannot appear in a trailer section. Other parameters are allowed and can be regarded as comments. + +Implementation- or service-specific parameters SHOULD be prefixed parameters with a vendor identifier, e.g. `acme-policy`, `acme-burst`. + + +### Remaining Parameter {#ratelimit-remaining-parameter} + +The "r" parameter indicates the remaining quota units for the identified policy ({{ratelimit-remaining-parameter}}). + +It is a non-negative Integer expressed in [quota units](#quota-unit). +Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. +When remaining parameter value is low, it indicates that the server may soon throttle the client (see {{providing-ratelimit-fields}}). + +### Reset Parameter {#ratelimit-reset-parameter} + +The "t" parameter indicates the number of seconds until the quota associated with the quota policy resets. + +It is a non-negative Integer compatible with the delay-seconds rule, because: + +- it does not rely on clock synchronization and is resilient to clock adjustment + and clock skew between client and server (see {{Section 5.6.7 of HTTP}}); +- it mitigates the risk related to thundering herd when too many clients are serviced with the same timestamp. + +The client MUST NOT assume that all its service limit will be reset at the moment indicated by the reset keyword. The server MAY arbitrarily alter the reset parameter value between subsequent requests; for example, in case of resource saturation or to implement sliding window policies. + +### Partition Key Parameter {#ratelimit-partitionkey} + +The "pk" parameter value conveys the partition key associated to the request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key. + + +## RateLimit Field Examples + +This example shows a RateLimit field with a remaining quota of 50 units and a time window reset in 30 seconds: + +~~~ + RateLimit: default;r=50;t=30 +~~~ + +This example shows a remaining quota of 999 requests for a partition key that has no time window reset: + +~~~ + RateLimit: default;r=999;pk=trial-121323 +~~~ + +This example shows a 300MB remaining quota for an application in the next 60 seconds: + +~~~ + RateLimit: default;r=300000000;pk=App-999;t=60;qu=bytes +~~~ + + +# Server Behavior {#providing-ratelimit-fields} + +A server MAY return RateLimit header fields independently of the response status code. This includes on throttled responses. This document does not mandate any correlation between the RateLimit header field values and the returned status code. + +Servers should be careful when returning RateLimit header fields in redirection responses (i.e., responses with 3xx status codes) because a low remaining keyword value could prevent the client from issuing requests. For example, given the RateLimit header fields below, a client could decide to wait 10 seconds before following the "Location" header field (see {{Section 10.2.2 of HTTP}}), because the remaining keyword value is 0. + +~~~ http-message +HTTP/1.1 301 Moved Permanently +Location: /foo/123 +RateLimit: problemPolicy;r=0, t=10 + +~~~ + +If a response contains both the Retry-After and the RateLimit header fields, the reset keyword value SHOULD reference the same point in time as the Retry-After field value. + +A service using RateLimit header fields MUST NOT convey values exposing an unwanted volume of requests and SHOULD implement mechanisms to cap the ratio between the remaining and the reset keyword values (see {{sec-resource-exhaustion}}); this is especially important when a quota policy uses a large time window. + +Under certain conditions, a server MAY artificially lower RateLimit header field values between subsequent requests, e.g. to respond to Denial of Service attacks or in case of resource saturation. + +## Performance Considerations + +Servers are not required to return RateLimit header fields in every response, and clients need to take this into account. For example, an implementer concerned with performance might provide RateLimit header fields only when a given quota is close to exhaustion. + +Implementers concerned with response fields' size, might take into account their ratio with respect to the content length, or use header-compression HTTP features such as {{?HPACK=RFC7541}}. + +# Client Behavior {#receiving-fields} + +The RateLimit header fields can be used by clients to determine whether the associated request respected the server's quota policy, and as an indication of whether subsequent requests will. However, the server might apply other criteria when servicing future requests, and so the quota policy may not completely reflect whether requests will succeed. + +For example, a successful response with the following fields: + +~~~ + RateLimit: default;r=1;t=7 +~~~ + +does not guarantee that the next request will be successful. Servers' behavior may be subject to other conditions. + +A client is responsible for ensuring that RateLimit header field values returned +cause reasonable client behavior with respect to throughput and latency +(see {{sec-resource-exhaustion}} and {{sec-dos}}). + +A client receiving RateLimit header fields MUST NOT assume that future responses will contain the same RateLimit header fields, or any RateLimit header fields at all. + +Malformed RateLimit header fields MUST be ignored. + +A client SHOULD NOT exceed the quota units conveyed by the remaining keyword before the time window expressed in the reset keyword. + +The value of the reset keyword is generated at response time: a client aware of a significant network latency MAY behave accordingly and use other information (e.g. the "Date" response header field, or otherwise gathered metrics) to better estimate the reset keyword moment intended by the server. + +The details provided in the RateLimit-Policy header field are informative and MAY be ignored. + +If a response contains both the RateLimit and Retry-After fields, the Retry-After field MUST take precedence and the reset keyword MAY be ignored. + +This specification does not mandate a specific throttling behavior and implementers can adopt their preferred policies, including: + +- slowing down or pre-emptively back-off their request rate when + approaching quota limits; +- consuming all the quota according to the exposed limits and then wait. + +## Intermediaries {#intermediaries} + +This section documents the considerations advised in {{Section 16.3.2 of HTTP}}. + +An intermediary that is not part of the originating service infrastructure and is not aware of the quota policy semantic used by the Origin Server SHOULD NOT alter the RateLimit header fields' values in such a way as to communicate a more permissive quota policy; this includes removing the RateLimit header fields. + +An intermediary MAY alter the RateLimit header fields in such a way as to communicate a more restrictive quota policy when: + +- it is aware of the quota unit semantic used by the Origin Server; +- it implements this specification and enforces a quota policy which + is more restrictive than the one conveyed in the fields. + +An intermediary SHOULD forward a request even when presuming that it might not be serviced; the service returning the RateLimit header fields is the sole responsible of enforcing the communicated quota policy, and it is always free to service incoming requests. + +This specification does not mandate any behavior on intermediaries respect to retries, nor requires that intermediaries have any role in respecting quota policies. For example, it is legitimate for a proxy to retransmit a request without notifying the client, and thus consuming quota units. + +[Privacy considerations](#privacy) provide further guidance on intermediaries. + +## Caching + +{{?HTTP-CACHING=RFC9111}} defines how responses can be stored and reused for subsequent requests, +including those with RateLimit header fields. +Because the information in RateLimit header fields on a cached response may not be current, they SHOULD be ignored on responses that come from cache +(i.e., those with a positive current_age; see {{Section 4.2.3 of HTTP-CACHING}}). + +# Security Considerations + +## Throttling does not prevent clients from issuing requests {#sec-throttling-does-not-prevent} + +This specification does not prevent clients from making requests. +Servers should always implement mechanisms to prevent resource exhaustion. + +## Information disclosure {#sec-information-disclosure} + +Servers should not disclose to untrusted parties operational capacity information +that can be used to saturate its infrastructural resources. + +While this specification does not mandate whether non-successful responses consume quota, +if error responses (such as 401 (Unauthorized) and 403 (Forbidden)) count against quota, +a malicious client could probe the endpoint to get traffic information of another user. + +As intermediaries might retransmit requests and consume +quota units without prior knowledge of the user agent, +RateLimit header fields might reveal the existence of an intermediary +to the user agent. + +Where partition keys contain identifying information, either of the client application or the user, servers should be aware of the potential for impersonation and apply the appropriate security mechanisms. + +## Remaining quota units are not granted requests {#sec-remaining-not-granted} + +RateLimit header fields convey hints from the server +to the clients in order to help them avoid being throttled out. + +Clients MUST NOT consider the [quota units](#service-limit) returned in remaining keyword as a service level agreement. + +In case of resource saturation, the server MAY artificially lower the returned values +or not serve the request regardless of the advertised quotas. + +## Reliability of the reset keyword {#sec-reset-reliability} + +Consider that quota might not be restored after the moment referenced by the [reset keyword](#ratelimit-reset-parameter), +and the reset parameter value may not be constant. + +Subsequent requests might return a higher reset parameter value +to limit concurrency or implement dynamic or adaptive throttling policies. + +## Resource exhaustion {#sec-resource-exhaustion} + +When returning reset values, servers must be aware that +many throttled clients may come back at the very moment specified. + +This is true for Retry-After too. + +For example, if the quota resets every day at `18:00:00` +and your server returns the reset parameter accordingly + +~~~ + Date: Tue, 15 Nov 1994 18:00:00 GMT + RateLimit: daily;r=1;t=36400 +~~~ + +there's a high probability that all clients will show up at `18:00:00`. + +This could be mitigated by adding some jitter to the reset value. + +Resource exhaustion issues can be associated with quota policies using a +large time window, because a user agent by chance or on purpose +might consume most of its quota units in a significantly shorter interval. + +This behavior can be even triggered by the provided RateLimit header fields. +The following example describes a service +with an unconsumed quota policy of 10000 quota units per 1000 seconds. + +~~~ +RateLimit-Policy: somepolicy;l=10000;w=1000 +RateLimit: somepolicy;r=10000;t=10 +~~~ + +A client implementing a simple ratio between remaining keyword and reset keyword could infer an average throughput of 1000 quota units per second, while the limit keyword conveys a quota-policy with an average of 10 quota units per second. +If the service cannot handle such load, it should return either a lower remaining keyword value or an higher reset keyword value. +Moreover, complementing large time window quota policies with a short time window one mitigates those risks. + + +### Denial of Service {#sec-dos} + +RateLimit header fields may contain unexpected values by chance or on purpose. +For example, an excessively high remaining keyword value may be: + +- used by a malicious intermediary to trigger a Denial of Service attack + or consume client resources boosting its requests; +- passed by a misconfigured server; + +or a high reset keyword value could inhibit clients to contact the server (e.g. similarly to receiving "Retry-after: 1000000"). + +To mitigate this risk, clients can set thresholds that they consider reasonable in terms of quota units, time window, concurrent requests or throughput, and define a consistent behavior when the RateLimit exceed those thresholds. +For example this means capping the maximum number of request per second, or implementing retries when the reset keyword exceeds ten minutes. + +The considerations above are not limited to RateLimit header fields, but apply to all fields affecting how clients behave in subsequent requests (e.g. Retry-After). + + +# Privacy Considerations {#privacy} + +Clients that act upon a request to rate limit +are potentially re-identifiable (see {{Section 5.2.1 of PRIVACY}}) +because they react to information that might only be given to them. +Note that this might apply to other fields too (e.g. Retry-After). + +Since rate limiting is usually implemented in contexts where +clients are either identified or profiled +(e.g. assigning different quota units to different users), +this is rarely a concern. + +Privacy enhancing infrastructures using RateLimit header fields +can define specific techniques to mitigate the risks of re-identification. + +# IANA Considerations + +IANA is requested to update one registry and create one new registry. + +Please add the following entries to the +"Hypertext Transfer Protocol (HTTP) Field Name Registry" registry ({{HTTP}}): + +|---------------------|-----------|---------------| +| Field Name | Status | Specification | +|---------------------|-----------|---------------| +| RateLimit | permanent | {{ratelimit-field}} of {{&SELF}} | +| RateLimit-Policy | permanent | {{ratelimit-policy-field}} of {{&SELF}} | +|---------------------|-----------|---------------| + + +--- back + +# Rate-limiting and quotas {#rate-limiting} + +Servers use quota mechanisms to avoid systems overload, to ensure an equitable distribution of computational resources or to enforce other policies - e.g. monetization. + +A basic quota mechanism limits the number of acceptable requests in a given time window, e.g. 10 requests per second. + +When quota is exceeded, servers usually do not serve the request replying instead with a 4xx HTTP status code (e.g. 429 or 403) or adopt more aggressive policies like dropping connections. + +Quotas may be enforced on different basis (e.g. per user, per IP, per geographic area, ..) and at different levels. For example, an user may be allowed to issue: + +- 10 requests per second; +- limited to 60 requests per minute; +- limited to 1000 requests per hour. + +Moreover system metrics, statistics and heuristics can be used to implement more complex policies, +where the number of acceptable requests and the time window are computed dynamically. + +To help clients throttling their requests, +servers may expose the counters used to evaluate quota policies via HTTP header fields. + +Those response headers may be added by HTTP intermediaries such as API gateways and reverse proxies. + +On the web we can find many different rate-limit headers, +usually containing the number of allowed requests in a given time window, and when the window is reset. + +The common choice is to return three headers containing: + +- the maximum number of allowed requests in the time window; +- the number of remaining requests in the current window; +- the time remaining in the current window expressed in seconds or + as a timestamp; + +## Interoperability issues + +A major interoperability issue in throttling is the lack of standard headers, because: + +- each implementation associates different semantics to the + same header field names; +- header field names proliferates. + +User agents interfacing with different servers may thus need to process different headers, +or the very same application interface that sits behind different reverse proxies +may reply with different throttling headers. + +# Examples + +## Responses without defining policies + +Some servers may not expose the policy limits in the RateLimit-Policy header field. Clients can still use the RateLimit header field to throttle their requests. + +### Throttling information in responses + +The client exhausted its quota for the next 50 seconds. +The limit and time-window is communicated out-of-band. + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 200 Ok +Content-Type: application/json +RateLimit: default;r=0;t=50 + +{"hello": "world"} +~~~ + +Since the field values are not necessarily correlated with +the response status code, +a subsequent request is not required to fail. +The example below shows that the server decided to serve the request +even if remaining keyword value is 0. +Another server, or the same server under other load conditions, could have decided to throttle the request instead. + +Request: + +~~~ http-message +GET /items/456 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 200 Ok +Content-Type: application/json +RateLimit: default;r=0;t=48 + +{"still": "successful"} +~~~ + +### Multiple policies in response {#use-with-multiple-policies} + +The server uses two different policies to limit the client's requests: + +- 5000 daily quota units; +- 1000 hourly quota units. + +The client consumed 4900 quota units in the first 14 hours. + +Despite the next hourly limit of 1000 quota units, +the closest limit to reach is the daily one. + +The server then exposes the RateLimit header fields to +inform the client that: + +- it has only 100 quota units left in the daily quota and the window will reset in 10 hours; + +The server MAY choose to omit returning the hourly policy as it uses the same quota units as the daily policy and the daily policy is the one that is closest to being exhausted. + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 200 Ok +Content-Type: application/json +RateLimit: dayLimit;r=100;t=36000 + +{"hello": "world"} +~~~ + +### Use for limiting concurrency {#use-for-limiting-concurrency} + +RateLimit header fields may be used to limit concurrency, +advertising limits that are lower than the usual ones +in case of saturation, thus increasing availability. + +The server adopted a basic policy of 100 quota units per minute, +and in case of resource exhaustion adapts the returned values +reducing both limit and remaining keyword values. + +After 2 seconds the client consumed 40 quota units + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 200 Ok +Content-Type: application/json +RateLimit-Policy: basic;l=100;w=60 +RateLimit: basic;r=60;t=58 + +{"elapsed": 2, "issued": 40} +~~~ + +At the subsequent request - due to resource exhaustion - +the server advertises only `r=20`. + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 200 Ok +Content-Type: application/json +RateLimit-Policy: basic;l=100;w=60 +RateLimit: basic;r=20;t=56 + +{"elapsed": 4, "issued": 41} +~~~ + +### Use in throttled responses + +A client exhausted its quota and the server throttles it +sending Retry-After. + +In this example, the values of Retry-After and RateLimit header field reference the same moment, +but this is not a requirement. + +The 429 (Too Many Request) HTTP status code is just used as an example. + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 429 Too Many Requests +Content-Type: application/json +Date: Mon, 05 Aug 2019 09:27:00 GMT +Retry-After: Mon, 05 Aug 2019 09:27:05 GMT +RateLimit: default;r=0;t=5 + +{ +"title": "Too Many Requests", +"status": 429, +"detail": "You have exceeded your quota" +} +~~~ + +## Responses with defined policies + +### Throttling window specified via parameter + +The client has 99 quota units left for the next 50 seconds. +The time window is communicated by the `w` parameter, so we know the throughput is 100 quota units per minute. + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 200 Ok +Content-Type: application/json +RateLimit: fixedwindow;r=99;t=50 +RateLimit-Policy: fixedwindow;l=100;w=60 +{"hello": "world"} +~~~ + + +### Dynamic limits with parameterized windows + +The policy conveyed by the RateLimit header field states that +the server accepts 100 quota units per minute. + +To avoid resource exhaustion, the server artificially lowers +the actual limits returned in the throttling headers. + +The remaining keyword then advertises +only 9 quota units for the next 50 seconds to slow down the client. + +Note that the server could have lowered even the other +values in the RateLimit header field: this specification +does not mandate any relation between the field values +contained in subsequent responses. + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 200 Ok +Content-Type: application/json +RateLimit-Policy: dynamic;l=100;w=60 +RateLimit: dynamic;r=9;t=50 + + +{ + "status": 200, + "detail": "Just slow down without waiting." +} +~~~ + +### Dynamic limits for pushing back and slowing down + +Continuing the previous example, let's say the client waits 10 seconds and +performs a new request which, due to resource exhaustion, the server rejects +and pushes back, advertising `r=0` for the next 20 seconds. + +The server advertises a smaller window with a lower limit to slow +down the client for the rest of its original window after the 20 seconds elapse. + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 429 Too Many Requests +Content-Type: application/json +RateLimit-Policy: dynamic;l=15;w=20 +RateLimit: dynamic;r=0;t=20 + +{ + "status": 429, + "detail": "Wait 20 seconds, then slow down!" +} +~~~ + +## Dynamic limits for pushing back with Retry-After and slow down + +Alternatively, given the same context where the previous example starts, we +can convey the same information to the client via Retry-After, with +the advantage that the server can now specify the policy's nominal limit and +window that will apply after the reset, e.g. assuming the resource exhaustion +is likely to be gone by then, so the advertised policy does not need to be +adjusted, yet we managed to stop requests for a while and slow down the rest of +the current window. + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 429 Too Many Requests +Content-Type: application/json +Retry-After: 20 +RateLimit-Policy: dynamic;l=100;w=60 +RateLimit: dynamic;r=15;t=40 + +{ + "status": 429, + "detail": "Wait 20 seconds, then slow down!" +} +~~~ + +Note that in this last response the client is expected to honor +Retry-After and perform no requests for the specified amount of +time, whereas the previous example would not force the client to stop +requests before the reset time is elapsed, as it would still be free to +query again the server even if it is likely to have the request rejected. + +### Missing Remaining information + +The server does not expose remaining values +(for example, because the underlying counters are not available). +Instead, it resets the limit counter every second. + +It communicates to the client the limit of 10 quota units per second +always returning the limit and reset keywords. + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 200 Ok +Content-Type: application/json +RateLimit-Policy: quota;l=100;w=1 +RateLimit: quota;t=1 + +{"first": "request"} +~~~ + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 200 Ok +Content-Type: application/json +RateLimit-Policy: quota;l=10 +RateLimit: quota;t=1 + +{"second": "request"} +~~~ + +### Use with multiple windows + +This is a standardized way of describing the policy +detailed in {{use-with-multiple-policies}}: + +- 5000 daily quota units; +- 1000 hourly quota units. + +The client consumed 4900 quota units in the first 14 hours. + +Despite the next hourly limit of 1000 quota units, the closest limit +to reach is the daily one. + +The server then exposes the RateLimit header fields to inform the client that: + +- it has only 100 quota units left; +- the window will reset in 10 hours; +- the expiring-limit is 5000. + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 200 OK +Content-Type: application/json +RateLimit-Policy: hour;l=1000;w=3600, day;l=5000;w=86400 +RateLimit: day;r=100;t=36000 + +{"hello": "world"} +~~~ + +# FAQ +{:numbered="false" removeinrfc="true"} + +1. Why defining standard fields for throttling? + + To simplify enforcement of throttling policies and enable clients to constraint their requests to avoid being throttled. + +2. Can I use RateLimit header fields in throttled responses (eg with status code 429)? + + Yes, you can. + +3. Are those specs tied to RFC 6585? + + No. {{?RFC6585}} defines the `429` status code and we use it just as an example of a throttled request, + that could instead use even `403` or whatever status code. + +4. Why is the partition key necessary? + + Without a partition key, a server can only effectively only have one scope (aka partition), which is impractical for most services, or it needs to communicate the scopes out-of-band. + This prevents the development of generic connector code that can be used to prevent requests from being throttled. + Many APIs rely on API keys, user identity or client identity to allocate quota. + As soon as a single client processes requests for more than one partition, the client needs to know the corresponding partition key to properly track requests against allocated quota. + +5. Why using delay-seconds instead of a UNIX Timestamp? + Why not using subsecond precision? + + Using delay-seconds aligns with Retry-After, which is returned in similar contexts, + eg on 429 responses. + + Timestamps require a clock synchronization protocol + (see {{Section 5.6.7 of HTTP}}). + This may be problematic (e.g. clock adjustment, clock skew, failure of hardcoded clock synchronization servers, + IoT devices, ..). + Moreover timestamps may not be monotonically increasing due to clock adjustment. + See [Another NTP client failure story](https://community.ntppool.org/t/another-ntp-client-failure-story/1014/) + + We did not use subsecond precision because: + + - that is more subject to system clock correction + like the one implemented via the adjtimex() Linux system call; + - response-time latency may not make it worth. A brief discussion on the subject is + on the [httpwg ml](https://lists.w3.org/Archives/Public/ietf-http-wg/2019JulSep/0202.html) + - almost all rate-limit headers implementations do not use it. + +6. Shouldn't I limit concurrency instead of request rate? + + You can use this specification to limit concurrency + at the HTTP level (see {#use-for-limiting-concurrency}) + and help clients to shape their requests avoiding being throttled out. + + A problematic way to limit concurrency is connection dropping, + especially when connections are multiplexed (e.g. HTTP/2) + because this results in unserviced client requests, + which is something we want to avoid. + + A semantic way to limit concurrency is to return 503 + Retry-After + in case of resource saturation (e.g. thrashing, connection queues too long, + Service Level Objectives not meet, ..). + Saturation conditions can be either dynamic or static: all this is out of + the scope for the current document. + +7. Do a positive value of remaining paramter imply any service guarantee for my + future requests to be served? + + No. FAQ integrated in {{ratelimit-remaining-parameter}}. + +8. Is the quota-policy definition {{quota-policy}} too complex? + + You can always return the simplest form + +~~~ +RateLimit:default;r=50;t=60 +~~~ + + The policy key clearly connects the current usage status of a policy to the defined limits. + So for the following field: + +~~~ +RateLimit-Policy: sliding;l=100;w=60;burst=1000;comment="sliding window", fixed;l=5000;w=3600;burst=0;comment="fixed window" +RateLimit: sliding;r=50;t=44 +~~~ + + the value "sliding" identifies the policy being reported. + +9. Can intermediaries alter RateLimit header fields? + + Generally, they should not because it might result in unserviced requests. + There are reasonable use cases for intermediaries mangling RateLimit header fields though, + e.g. when they enforce stricter quota-policies, + or when they are an active component of the service. + In those case we will consider them as part of the originating infrastructure. + +10. Why the `w` parameter is just informative? + Could it be used by a client to determine the request rate? + + A non-informative `w` parameter might be fine in an environment + where clients and servers are tightly coupled. Conveying policies + with this detail on a large scale would be very complex and implementations + would be likely not interoperable. We thus decided to leave `w` as + an informational parameter and only rely on the limit, remaining and reset keywords + for defining the throttling + behavior. + +11. Can I use RateLimit fields in trailers? + Servers usually establish whether the request is in-quota before creating a response, so the RateLimit field values should be already available in that moment. + Supporting trailers has the only advantage that allows to provide more up-to-date information to the client in case of slow responses. + However, this complicates client implementations with respect to combining fields from headers and accounting for intermediaries that drop trailers. + Since there are no current implementations that use trailers, we decided to leave this as a future-work. + +# RateLimit header fields currently used on the web +{:numbered="false" removeinrfc="true"} + +Commonly used header field names are: + +- `X-RateLimit-Limit`, + `X-RateLimit-Remaining`, + `X-RateLimit-Reset`; + +There are variants too, where the window is specified +in the header field name, eg: + +- `x-ratelimit-limit-minute`, `x-ratelimit-limit-hour`, `x-ratelimit-limit-day` +- `x-ratelimit-remaining-minute`, `x-ratelimit-remaining-hour`, `x-ratelimit-remaining-day` + +Here are some interoperability issues: + +- `X-RateLimit-Remaining` references different values, depending on the implementation: + + * seconds remaining to the window expiration + * milliseconds remaining to the window expiration + * seconds since UTC, in UNIX Timestamp [UNIX] + * a datetime, either `IMF-fixdate` {{HTTP}} or {{?RFC3339}} + +- different headers, with the same semantic, are used by different implementers: + + * X-RateLimit-Limit and X-Rate-Limit-Limit + * X-RateLimit-Remaining and X-Rate-Limit-Remaining + * X-RateLimit-Reset and X-Rate-Limit-Reset + +The semantic of RateLimit depends on the windowing algorithm. +A sliding window policy for example, may result in having a remaining keyword value related to the ratio between the current and the maximum throughput. +e.g. + +~~~ +RateLimit-Policy: sliding;l=12;w=1 +RateLimit: sliding;l=12;r=6;t=1 ; using 50% of throughput, that is 6 units/s + +~~~ + +If this is the case, the optimal solution is to achieve + +~~~ +RateLimit-Policy: sliding;l=12;w=1 +RateLimit: sliding;l=12;r=1;t=1 ; using 100% of throughput, that is 12 units/s +~~~ + +At this point you should stop increasing your request rate. + +# Acknowledgements +{:numbered="false"} + +Thanks to Willi Schoenborn, Alejandro Martinez Ruiz, Alessandro Ranellucci, +Amos Jeffries, +Martin Thomson, +Erik Wilde and Mark Nottingham for being the initial contributors +of these specifications. +Kudos to the first community implementers: +Aapo Talvensaari, +Nathan Friedly +and Sanyam Dogra. + +In addition to the people above, this document owes a lot to the extensive discussion in the HTTPAPI workgroup, including +Rich Salz, +Darrel Miller +and Julian Reschke. + +# Changes +{:numbered="false" removeinrfc="true"} + +## Since draft-ietf-httpapi-ratelimit-headers-07 +{:numbered="false" removeinrfc="true"} + +* Refactored both fields to lists of Items that identify policy and use parameters +* Added quota unit parameter +* Added partition key parameter + + +## Since draft-ietf-httpapi-ratelimit-headers-03 +{:numbered="false" removeinrfc="true"} + +* Split policy informatiom in RateLimit-Policy #81 + + +## Since draft-ietf-httpapi-ratelimit-headers-02 +{:numbered="false" removeinrfc="true"} + +* Address throttling scope #83 + +## Since draft-ietf-httpapi-ratelimit-headers-01 +{:numbered="false" removeinrfc="true"} + +* Update IANA considerations #60 +* Use Structured fields #58 +* Reorganize document #67 + +## Since draft-ietf-httpapi-ratelimit-headers-00 +{:numbered="false" removeinrfc="true"} + +* Use I-D.httpbis-semantics, which includes referencing delay-seconds + instead of delta-seconds. #5 diff --git a/draft-ietf-httpapi-ratelimit-headers.txt b/draft-ietf-httpapi-ratelimit-headers.txt new file mode 100644 index 0000000..1deaa44 --- /dev/null +++ b/draft-ietf-httpapi-ratelimit-headers.txt @@ -0,0 +1,1435 @@ + + + + +HTTPAPI R. Polli +Internet-Draft Team Digitale, Italian Government +Intended status: Standards Track A. Martinez +Expires: 2 April 2025 Red Hat + D. Miller + Microsoft + 29 September 2024 + + + RateLimit header fields for HTTP + draft-ietf-httpapi-ratelimit-headers-latest + +Abstract + + This document defines the RateLimit-Policy and RateLimit HTTP header + fields for servers to advertise their service policy limits and the + current limits, thereby allowing clients to avoid being throttled. + +About This Document + + This note is to be removed before publishing as an RFC. + + Status information for this document may be found at + https://datatracker.ietf.org/doc/draft-ietf-httpapi-ratelimit- + headers/. + + Discussion of this document takes place on the HTTPAPI Working Group + mailing list (mailto:httpapi@ietf.org), which is archived at + https://mailarchive.ietf.org/arch/browse/httpapi/. Subscribe at + https://www.ietf.org/mailman/listinfo/httpapi/. Working Group + information can be found at https://datatracker.ietf.org/wg/httpapi/ + about/. + + Source for this draft and an issue tracker can be found at + https://github.com/ietf-wg-httpapi/ratelimit-headers. + +Status of This Memo + + This Internet-Draft is submitted in full conformance with the + provisions of BCP 78 and BCP 79. + + Internet-Drafts are working documents of the Internet Engineering + Task Force (IETF). Note that other groups may also distribute + working documents as Internet-Drafts. The list of current Internet- + Drafts is at https://datatracker.ietf.org/drafts/current/. + + Internet-Drafts are draft documents valid for a maximum of six months + and may be updated, replaced, or obsoleted by other documents at any + time. It is inappropriate to use Internet-Drafts as reference + material or to cite them other than as "work in progress." + + This Internet-Draft will expire on 2 April 2025. + +Copyright Notice + + Copyright (c) 2024 IETF Trust and the persons identified as the + document authors. All rights reserved. + + This document is subject to BCP 78 and the IETF Trust's Legal + Provisions Relating to IETF Documents (https://trustee.ietf.org/ + license-info) in effect on the date of publication of this document. + Please review these documents carefully, as they describe your rights + and restrictions with respect to this document. Code Components + extracted from this document must include Revised BSD License text as + described in Section 4.e of the Trust Legal Provisions and are + provided without warranty as described in the Revised BSD License. + +Table of Contents + + 1. Introduction + 1.1. Goals + 1.2. Notational Conventions + 2. Terminology + 2.1. Quota + 2.2. Quota Unit + 2.3. Quota Partition + 2.4. Time Window + 2.5. Quota Policy + 2.6. Service Limit + 3. RateLimit-Policy Field + 3.1. Quota Policy Item + 3.1.1. Quota Parameter + 3.1.2. Quota Unit Parameter + 3.1.3. Window Parameter + 3.1.4. Partition Key Parameter + 3.2. RateLimit Policy Field Examples + 4. RateLimit Field + 4.1. Service Limit Item + 4.1.1. Remaining Parameter + 4.1.2. Reset Parameter + 4.1.3. Partition Key Parameter + 4.2. RateLimit Field Examples + 5. Server Behavior + 5.1. Performance Considerations + 6. Client Behavior + 6.1. Intermediaries + 6.2. Caching + 7. Security Considerations + 7.1. Throttling does not prevent clients from issuing requests + 7.2. Information disclosure + 7.3. Remaining quota units are not granted requests + 7.4. Reliability of the reset keyword + 7.5. Resource exhaustion + 7.5.1. Denial of Service + 8. Privacy Considerations + 9. IANA Considerations + 10. References + 10.1. Normative References + 10.2. Informative References + Appendix A. Rate-limiting and quotas + A.1. Interoperability issues + Appendix B. Examples + B.1. Responses without defining policies + B.1.1. Throttling information in responses + B.1.2. Multiple policies in response + B.1.3. Use for limiting concurrency + B.1.4. Use in throttled responses + B.2. Responses with defined policies + B.2.1. Throttling window specified via parameter + B.2.2. Dynamic limits with parameterized windows + B.2.3. Dynamic limits for pushing back and slowing down + B.3. Dynamic limits for pushing back with Retry-After and slow + down + B.3.1. Missing Remaining information + B.3.2. Use with multiple windows + FAQ + RateLimit header fields currently used on the web + Acknowledgements + Changes + Since draft-ietf-httpapi-ratelimit-headers-07 + Since draft-ietf-httpapi-ratelimit-headers-03 + Since draft-ietf-httpapi-ratelimit-headers-02 + Since draft-ietf-httpapi-ratelimit-headers-01 + Since draft-ietf-httpapi-ratelimit-headers-00 + Authors' Addresses + +1. Introduction + + Rate limiting of HTTP clients has become a widespread practice, + especially for HTTP APIs. Typically, servers who do so limit the + number of acceptable requests in a given time window (e.g. 10 + requests per second). See Appendix A for further information on the + current usage of rate limiting in HTTP. + + Currently, there is no standard way for servers to communicate quotas + so that clients can throttle their requests to prevent errors. This + document defines a set of standard HTTP header fields to enable rate + limiting: + + * RateLimit: to convey the server's current limit of quota units + available to the client in the policy time window, the remaining + quota units in the current window, and the time remaining in the + current window, specified in seconds, and + + * RateLimit-Policy: the service policy limits. + + These fields enable establishing complex rate limiting policies, + including using multiple and variable time windows and dynamic + quotas, and implementing concurrency limits. + + The behavior of the RateLimit header field is compatible with the + delay-seconds notation of Retry-After. + +1.1. Goals + + The goals of this document are: + + Interoperability: Standardize the names and semantics of rate-limit + headers to ease their enforcement and adoption; + + Resiliency: Improve resiliency of HTTP infrastructure by providing + clients with information useful to throttle their requests and + prevent 4xx or 5xx responses; + + Documentation: Simplify API documentation by eliminating the need to + include detailed quota limits and related fields in API + documentation. + + The following features are out of the scope of this document: + + Authorization: RateLimit header fields are not meant to support + authorization or other kinds of access controls. + + Response status code: RateLimit header fields may be returned in + both successful (see Section 15.3 of [HTTP]) and non-successful + responses. This specification does not cover whether non + Successful responses count on quota usage, nor does it mandates + any correlation between the RateLimit values and the returned + status code. + + Throttling algorithm: This specification does not mandate a specific + throttling algorithm. The values published in the fields, + including the window size, can be statically or dynamically + evaluated. + + Service Level Agreement: Conveyed quota hints do not imply any + service guarantee. Server is free to throttle respectful clients + under certain circumstances. + +1.2. Notational Conventions + + The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", + "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and + "OPTIONAL" in this document are to be interpreted as described in + BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all + capitals, as shown here. + + The term Origin is to be interpreted as described in Section 7 of + [WEB-ORIGIN]. + + This document uses the terms List, Item and Integer from Section 3 of + [STRUCTURED-FIELDS] to specify syntax and parsing, along with the + concept of "bare item". + +2. Terminology + +2.1. Quota + + A quota is an allocation of capacity to enable a server to limit + client requests. That capacity is counted in quota units and may be + reallocated at the end of a time window Section 2.4. + +2.2. Quota Unit + + A quota unit is the unit of measure used to count the activity of a + client. + +2.3. Quota Partition + + A quota partition is a division of a server's capacity across + different clients, users and owned resources. + +2.4. Time Window + + A time window indicates a period of time associated to the allocated + quota. + + The time window is a non-negative Integer value expressing an + interval in seconds, similar to the "delay-seconds" rule defined in + Section 10.2.3 of [HTTP]. Sub-second precision is not supported. + +2.5. Quota Policy + + A quota policy is maintained by a server to limit the activity + (counted in quota units (Section 2.2)) of a given quota partition + (Section 2.3) over a period of time (known as the time window + (Section 2.4)) to a specified amount known as the Section 2.1. + + Quota policies can be advertised by servers (see Section 3), but they + are not required to be, and more than one quota policy can affect a + given request from a client to a server. + +2.6. Service Limit + + A service limit is the current limit of the amount of activity that a + server will allow based on the remaining quota for a particular quota + partition within the time-window, if defined. + +3. RateLimit-Policy Field + + The "RateLimit-Policy" response header field is a non-empty List of + Section 3.1. Its value is informative. The values are expected to + remain consistent over a the lifetime of a connection. It is this + characteristic that differentiates it from the RateLimit (Section 4) + that contains values that may change on every request. + + RateLimit-Policy: burst;q=100;w=60,daily;q=1000;w=86400 + +3.1. Quota Policy Item + + A quota policy Item contains information about a server's capacity + allocation for a quota partition associated with the request. + + The following parameters are defined in this specification: + + q: The REQUIRED "q" parameter indicates the quota allocated. + (Section 3.1.1) + + qu: The OPTIONAL "qu" parameter value conveys the quota units + associated to the "q" parameter. The default quota unit is + "request". (Section 3.1.2) + + w: The OPTIONAL "w" parameter value conveys a time "window" + (Section 2.4). (Section 3.1.3) + + pk: The OPTIONAL "pk" parameter value conveys the partition key + associated to the corresponding request. Section 3.1.4 + + Other parameters are allowed and can be regarded as comments. + + Implementation- or service-specific parameters SHOULD be prefixed + parameters with a vendor identifier, e.g. acme-policy, acme-burst. + +3.1.1. Quota Parameter + + The "q" parameter uses a non-negative integer value to indicate the + quota allocated for client activity (counted in quota units) for a + given quota partition (Section 2.6). + +3.1.2. Quota Unit Parameter + + The "qu" parameter value conveys the quota units associated to the + "q" parameter. + +3.1.3. Window Parameter + + The "w" parameter value conveys a time "window" in seconds. + (Section 2.4). + +3.1.4. Partition Key Parameter + + The "pk" parameter value conveys the partition key associated to the + request. Servers MAY use the partition key to divide server capacity + across different clients and resources. Quotas are allocated per + partition key. + +3.2. RateLimit Policy Field Examples + + This field MAY convey the time window associated with the expiring- + limit, as shown in this example: + + RateLimit-Policy: default;l=100;w=10 + + These examples show multiple policies being returned: + + RateLimit-Policy: permin;l=50;w=60,perhr;l=1000;w=3600,perday;l=5000;w=86400 + + The following example shows a policy with a partition key: + + RateLimit-Policy: peruser;l=100;w=60;pk=user123 + + The following example shows a policy with a partition key and a quota + unit: + + RateLimit-Policy: peruser;l=65535;w=10;pk=user123;qu=bytes + + This field cannot appear in a trailer section. + +4. RateLimit Field + + A server uses the "RateLimit" response header field to communicate + the service limit for a quota policy for a particular partition key. + + The field is expressed as List of Section 4.1. + + RateLimit: default;r=50;t=30 + +4.1. Service Limit Item + + Each service limit item in identifies the quota policy associated + with the request and + + The following parameters are defined in this specification: + + r: This parameter value conveys the remaining quota units for the + identified policy (Section 4.1.1). + + t: This OPTIONAL parameter value conveys the time window reset time + for the identified policy (Section 4.1.2). + + pk: The OPTIONAL "pk" parameter value conveys the partition key + associated to the corresponding request. + + This field cannot appear in a trailer section. Other parameters are + allowed and can be regarded as comments. + + Implementation- or service-specific parameters SHOULD be prefixed + parameters with a vendor identifier, e.g. acme-policy, acme-burst. + +4.1.1. Remaining Parameter + + The "r" parameter indicates the remaining quota units for the + identified policy (Section 4.1.1). + + It is a non-negative Integer expressed in quota units (Section 2.2). + Clients MUST NOT assume that a positive remaining value is a + guarantee that further requests will be served. When remaining + parameter value is low, it indicates that the server may soon + throttle the client (see Section 5). + +4.1.2. Reset Parameter + + The "t" parameter indicates the number of seconds until the quota + associated with the quota policy resets. + + It is a non-negative Integer compatible with the delay-seconds rule, + because: + + * it does not rely on clock synchronization and is resilient to + clock adjustment and clock skew between client and server (see + Section 5.6.7 of [HTTP]); + + * it mitigates the risk related to thundering herd when too many + clients are serviced with the same timestamp. + + The client MUST NOT assume that all its service limit will be reset + at the moment indicated by the reset keyword. The server MAY + arbitrarily alter the reset parameter value between subsequent + requests; for example, in case of resource saturation or to implement + sliding window policies. + +4.1.3. Partition Key Parameter + + The "pk" parameter value conveys the partition key associated to the + request. Servers MAY use the partition key to divide server capacity + across different clients and resources. Quotas are allocated per + partition key. + +4.2. RateLimit Field Examples + + This example shows a RateLimit field with a remaining quota of 50 + units and a time window reset in 30 seconds: + + RateLimit: default;r=50;t=30 + + This example shows a remaining quota of 999 requests for a partition + key that has no time window reset: + + RateLimit: default;r=999;pk=trial-121323 + + This example shows a 300MB remaining quota for an application in the + next 60 seconds: + + RateLimit: default;r=300000000;pk=App-999;t=60;qu=bytes + +5. Server Behavior + + A server MAY return RateLimit header fields independently of the + response status code. This includes on throttled responses. This + document does not mandate any correlation between the RateLimit + header field values and the returned status code. + + Servers should be careful when returning RateLimit header fields in + redirection responses (i.e., responses with 3xx status codes) because + a low remaining keyword value could prevent the client from issuing + requests. For example, given the RateLimit header fields below, a + client could decide to wait 10 seconds before following the + "Location" header field (see Section 10.2.2 of [HTTP]), because the + remaining keyword value is 0. + + HTTP/1.1 301 Moved Permanently + Location: /foo/123 + RateLimit: problemPolicy;r=0, t=10 + + If a response contains both the Retry-After and the RateLimit header + fields, the reset keyword value SHOULD reference the same point in + time as the Retry-After field value. + + A service using RateLimit header fields MUST NOT convey values + exposing an unwanted volume of requests and SHOULD implement + mechanisms to cap the ratio between the remaining and the reset + keyword values (see Section 7.5); this is especially important when a + quota policy uses a large time window. + + Under certain conditions, a server MAY artificially lower RateLimit + header field values between subsequent requests, e.g. to respond to + Denial of Service attacks or in case of resource saturation. + +5.1. Performance Considerations + + Servers are not required to return RateLimit header fields in every + response, and clients need to take this into account. For example, + an implementer concerned with performance might provide RateLimit + header fields only when a given quota is close to exhaustion. + + Implementers concerned with response fields' size, might take into + account their ratio with respect to the content length, or use + header-compression HTTP features such as [HPACK]. + +6. Client Behavior + + The RateLimit header fields can be used by clients to determine + whether the associated request respected the server's quota policy, + and as an indication of whether subsequent requests will. However, + the server might apply other criteria when servicing future requests, + and so the quota policy may not completely reflect whether requests + will succeed. + + For example, a successful response with the following fields: + + RateLimit: default;r=1;t=7 + + does not guarantee that the next request will be successful. + Servers' behavior may be subject to other conditions. + + A client is responsible for ensuring that RateLimit header field + values returned cause reasonable client behavior with respect to + throughput and latency (see Section 7.5 and Section 7.5.1). + + A client receiving RateLimit header fields MUST NOT assume that + future responses will contain the same RateLimit header fields, or + any RateLimit header fields at all. + + Malformed RateLimit header fields MUST be ignored. + + A client SHOULD NOT exceed the quota units conveyed by the remaining + keyword before the time window expressed in the reset keyword. + + The value of the reset keyword is generated at response time: a + client aware of a significant network latency MAY behave accordingly + and use other information (e.g. the "Date" response header field, or + otherwise gathered metrics) to better estimate the reset keyword + moment intended by the server. + + The details provided in the RateLimit-Policy header field are + informative and MAY be ignored. + + If a response contains both the RateLimit and Retry-After fields, the + Retry-After field MUST take precedence and the reset keyword MAY be + ignored. + + This specification does not mandate a specific throttling behavior + and implementers can adopt their preferred policies, including: + + * slowing down or pre-emptively back-off their request rate when + approaching quota limits; + + * consuming all the quota according to the exposed limits and then + wait. + +6.1. Intermediaries + + This section documents the considerations advised in Section 16.3.2 + of [HTTP]. + + An intermediary that is not part of the originating service + infrastructure and is not aware of the quota policy semantic used by + the Origin Server SHOULD NOT alter the RateLimit header fields' + values in such a way as to communicate a more permissive quota + policy; this includes removing the RateLimit header fields. + + An intermediary MAY alter the RateLimit header fields in such a way + as to communicate a more restrictive quota policy when: + + * it is aware of the quota unit semantic used by the Origin Server; + + * it implements this specification and enforces a quota policy which + is more restrictive than the one conveyed in the fields. + + An intermediary SHOULD forward a request even when presuming that it + might not be serviced; the service returning the RateLimit header + fields is the sole responsible of enforcing the communicated quota + policy, and it is always free to service incoming requests. + + This specification does not mandate any behavior on intermediaries + respect to retries, nor requires that intermediaries have any role in + respecting quota policies. For example, it is legitimate for a proxy + to retransmit a request without notifying the client, and thus + consuming quota units. + + Privacy considerations (Section 8) provide further guidance on + intermediaries. + +6.2. Caching + + [HTTP-CACHING] defines how responses can be stored and reused for + subsequent requests, including those with RateLimit header fields. + Because the information in RateLimit header fields on a cached + response may not be current, they SHOULD be ignored on responses that + come from cache (i.e., those with a positive current_age; see + Section 4.2.3 of [HTTP-CACHING]). + +7. Security Considerations + +7.1. Throttling does not prevent clients from issuing requests + + This specification does not prevent clients from making requests. + Servers should always implement mechanisms to prevent resource + exhaustion. + +7.2. Information disclosure + + Servers should not disclose to untrusted parties operational capacity + information that can be used to saturate its infrastructural + resources. + + While this specification does not mandate whether non-successful + responses consume quota, if error responses (such as 401 + (Unauthorized) and 403 (Forbidden)) count against quota, a malicious + client could probe the endpoint to get traffic information of another + user. + + As intermediaries might retransmit requests and consume quota units + without prior knowledge of the user agent, RateLimit header fields + might reveal the existence of an intermediary to the user agent. + + Where partition keys contain identifying information, either of the + client application or the user, servers should be aware of the + potential for impersonation and apply the appropriate security + mechanisms. + +7.3. Remaining quota units are not granted requests + + RateLimit header fields convey hints from the server to the clients + in order to help them avoid being throttled out. + + Clients MUST NOT consider the quota units (Section 2.6) returned in + remaining keyword as a service level agreement. + + In case of resource saturation, the server MAY artificially lower the + returned values or not serve the request regardless of the advertised + quotas. + +7.4. Reliability of the reset keyword + + Consider that quota might not be restored after the moment referenced + by the reset keyword (Section 4.1.2), and the reset parameter value + may not be constant. + + Subsequent requests might return a higher reset parameter value to + limit concurrency or implement dynamic or adaptive throttling + policies. + +7.5. Resource exhaustion + + When returning reset values, servers must be aware that many + throttled clients may come back at the very moment specified. + + This is true for Retry-After too. + + For example, if the quota resets every day at 18:00:00 and your + server returns the reset parameter accordingly + + Date: Tue, 15 Nov 1994 18:00:00 GMT + RateLimit: daily;r=1;t=36400 + + there's a high probability that all clients will show up at 18:00:00. + + This could be mitigated by adding some jitter to the reset value. + + Resource exhaustion issues can be associated with quota policies + using a large time window, because a user agent by chance or on + purpose might consume most of its quota units in a significantly + shorter interval. + + This behavior can be even triggered by the provided RateLimit header + fields. The following example describes a service with an unconsumed + quota policy of 10000 quota units per 1000 seconds. + + RateLimit-Policy: somepolicy;l=10000;w=1000 + RateLimit: somepolicy;r=10000;t=10 + + A client implementing a simple ratio between remaining keyword and + reset keyword could infer an average throughput of 1000 quota units + per second, while the limit keyword conveys a quota-policy with an + average of 10 quota units per second. If the service cannot handle + such load, it should return either a lower remaining keyword value or + an higher reset keyword value. Moreover, complementing large time + window quota policies with a short time window one mitigates those + risks. + +7.5.1. Denial of Service + + RateLimit header fields may contain unexpected values by chance or on + purpose. For example, an excessively high remaining keyword value + may be: + + * used by a malicious intermediary to trigger a Denial of Service + attack or consume client resources boosting its requests; + + * passed by a misconfigured server; + + or a high reset keyword value could inhibit clients to contact the + server (e.g. similarly to receiving "Retry-after: 1000000"). + + To mitigate this risk, clients can set thresholds that they consider + reasonable in terms of quota units, time window, concurrent requests + or throughput, and define a consistent behavior when the RateLimit + exceed those thresholds. For example this means capping the maximum + number of request per second, or implementing retries when the reset + keyword exceeds ten minutes. + + The considerations above are not limited to RateLimit header fields, + but apply to all fields affecting how clients behave in subsequent + requests (e.g. Retry-After). + +8. Privacy Considerations + + Clients that act upon a request to rate limit are potentially re- + identifiable (see Section 5.2.1 of [PRIVACY]) because they react to + information that might only be given to them. Note that this might + apply to other fields too (e.g. Retry-After). + + Since rate limiting is usually implemented in contexts where clients + are either identified or profiled (e.g. assigning different quota + units to different users), this is rarely a concern. + + Privacy enhancing infrastructures using RateLimit header fields can + define specific techniques to mitigate the risks of re- + identification. + +9. IANA Considerations + + IANA is requested to update one registry and create one new registry. + + Please add the following entries to the "Hypertext Transfer Protocol + (HTTP) Field Name Registry" registry ([HTTP]): + + +==================+===========+=======================+ + | Field Name | Status | Specification | + +==================+===========+=======================+ + | RateLimit | permanent | Section 4 of RFC nnnn | + +------------------+-----------+-----------------------+ + | RateLimit-Policy | permanent | Section 3 of RFC nnnn | + +------------------+-----------+-----------------------+ + + Table 1 + +10. References + +10.1. Normative References + + [HTTP] Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, + Ed., "HTTP Semantics", STD 97, RFC 9110, + DOI 10.17487/RFC9110, June 2022, + . + + [IANA] Cotton, M., Leiba, B., and T. Narten, "Guidelines for + Writing an IANA Considerations Section in RFCs", BCP 26, + RFC 8126, DOI 10.17487/RFC8126, June 2017, + . + + [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate + Requirement Levels", BCP 14, RFC 2119, + DOI 10.17487/RFC2119, March 1997, + . + + [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC + 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, + May 2017, . + + [STRUCTURED-FIELDS] + Nottingham, M. and P. Kamp, "Structured Field Values for + HTTP", RFC 8941, DOI 10.17487/RFC8941, February 2021, + . + + [WEB-ORIGIN] + Barth, A., "The Web Origin Concept", RFC 6454, + DOI 10.17487/RFC6454, December 2011, + . + +10.2. Informative References + + [HPACK] Peon, R. and H. Ruellan, "HPACK: Header Compression for + HTTP/2", RFC 7541, DOI 10.17487/RFC7541, May 2015, + . + + [HTTP-CACHING] + Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, + Ed., "HTTP Caching", STD 98, RFC 9111, + DOI 10.17487/RFC9111, June 2022, + . + + [PRIVACY] Cooper, A., Tschofenig, H., Aboba, B., Peterson, J., + Morris, J., Hansen, M., and R. Smith, "Privacy + Considerations for Internet Protocols", RFC 6973, + DOI 10.17487/RFC6973, July 2013, + . + + [RFC3339] Klyne, G. and C. Newman, "Date and Time on the Internet: + Timestamps", RFC 3339, DOI 10.17487/RFC3339, July 2002, + . + + [RFC6585] Nottingham, M. and R. Fielding, "Additional HTTP Status + Codes", RFC 6585, DOI 10.17487/RFC6585, April 2012, + . + + [UNIX] The Open Group, "The Single UNIX Specification, Version 2 + - 6 Vol Set for UNIX 98", February 1997. + +Appendix A. Rate-limiting and quotas + + Servers use quota mechanisms to avoid systems overload, to ensure an + equitable distribution of computational resources or to enforce other + policies - e.g. monetization. + + A basic quota mechanism limits the number of acceptable requests in a + given time window, e.g. 10 requests per second. + + When quota is exceeded, servers usually do not serve the request + replying instead with a 4xx HTTP status code (e.g. 429 or 403) or + adopt more aggressive policies like dropping connections. + + Quotas may be enforced on different basis (e.g. per user, per IP, per + geographic area, ..) and at different levels. For example, an user + may be allowed to issue: + + * 10 requests per second; + + * limited to 60 requests per minute; + + * limited to 1000 requests per hour. + + Moreover system metrics, statistics and heuristics can be used to + implement more complex policies, where the number of acceptable + requests and the time window are computed dynamically. + + To help clients throttling their requests, servers may expose the + counters used to evaluate quota policies via HTTP header fields. + + Those response headers may be added by HTTP intermediaries such as + API gateways and reverse proxies. + + On the web we can find many different rate-limit headers, usually + containing the number of allowed requests in a given time window, and + when the window is reset. + + The common choice is to return three headers containing: + + * the maximum number of allowed requests in the time window; + + * the number of remaining requests in the current window; + + * the time remaining in the current window expressed in seconds or + as a timestamp; + +A.1. Interoperability issues + + A major interoperability issue in throttling is the lack of standard + headers, because: + + * each implementation associates different semantics to the same + header field names; + + * header field names proliferates. + + User agents interfacing with different servers may thus need to + process different headers, or the very same application interface + that sits behind different reverse proxies may reply with different + throttling headers. + +Appendix B. Examples + +B.1. Responses without defining policies + + Some servers may not expose the policy limits in the RateLimit-Policy + header field. Clients can still use the RateLimit header field to + throttle their requests. + +B.1.1. Throttling information in responses + + The client exhausted its quota for the next 50 seconds. The limit + and time-window is communicated out-of-band. + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 200 Ok + Content-Type: application/json + RateLimit: default;r=0;t=50 + + {"hello": "world"} + + Since the field values are not necessarily correlated with the + response status code, a subsequent request is not required to fail. + The example below shows that the server decided to serve the request + even if remaining keyword value is 0. Another server, or the same + server under other load conditions, could have decided to throttle + the request instead. + + Request: + + GET /items/456 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 200 Ok + Content-Type: application/json + RateLimit: default;r=0;t=48 + + {"still": "successful"} + +B.1.2. Multiple policies in response + + The server uses two different policies to limit the client's + requests: + + * 5000 daily quota units; + + * 1000 hourly quota units. + + The client consumed 4900 quota units in the first 14 hours. + + Despite the next hourly limit of 1000 quota units, the closest limit + to reach is the daily one. + + The server then exposes the RateLimit header fields to inform the + client that: + + * it has only 100 quota units left in the daily quota and the window + will reset in 10 hours; + + The server MAY choose to omit returning the hourly policy as it uses + the same quota units as the daily policy and the daily policy is the + one that is closest to being exhausted. + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 200 Ok + Content-Type: application/json + RateLimit: dayLimit;r=100;t=36000 + + {"hello": "world"} + +B.1.3. Use for limiting concurrency + + RateLimit header fields may be used to limit concurrency, advertising + limits that are lower than the usual ones in case of saturation, thus + increasing availability. + + The server adopted a basic policy of 100 quota units per minute, and + in case of resource exhaustion adapts the returned values reducing + both limit and remaining keyword values. + + After 2 seconds the client consumed 40 quota units + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 200 Ok + Content-Type: application/json + RateLimit-Policy: basic;l=100;w=60 + RateLimit: basic;r=60;t=58 + + {"elapsed": 2, "issued": 40} + + At the subsequent request - due to resource exhaustion - the server + advertises only r=20. + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 200 Ok + Content-Type: application/json + RateLimit-Policy: basic;l=100;w=60 + RateLimit: basic;r=20;t=56 + + {"elapsed": 4, "issued": 41} + +B.1.4. Use in throttled responses + + A client exhausted its quota and the server throttles it sending + Retry-After. + + In this example, the values of Retry-After and RateLimit header field + reference the same moment, but this is not a requirement. + + The 429 (Too Many Request) HTTP status code is just used as an + example. + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 429 Too Many Requests + Content-Type: application/json + Date: Mon, 05 Aug 2019 09:27:00 GMT + Retry-After: Mon, 05 Aug 2019 09:27:05 GMT + RateLimit: default;r=0;t=5 + + { + "title": "Too Many Requests", + "status": 429, + "detail": "You have exceeded your quota" + } + +B.2. Responses with defined policies + +B.2.1. Throttling window specified via parameter + + The client has 99 quota units left for the next 50 seconds. The time + window is communicated by the w parameter, so we know the throughput + is 100 quota units per minute. + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 200 Ok + Content-Type: application/json + RateLimit: fixedwindow;r=99;t=50 + RateLimit-Policy: fixedwindow;l=100;w=60 + {"hello": "world"} + +B.2.2. Dynamic limits with parameterized windows + + The policy conveyed by the RateLimit header field states that the + server accepts 100 quota units per minute. + + To avoid resource exhaustion, the server artificially lowers the + actual limits returned in the throttling headers. + + The remaining keyword then advertises only 9 quota units for the next + 50 seconds to slow down the client. + + Note that the server could have lowered even the other values in the + RateLimit header field: this specification does not mandate any + relation between the field values contained in subsequent responses. + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 200 Ok + Content-Type: application/json + RateLimit-Policy: dynamic;l=100;w=60 + RateLimit: dynamic;r=9;t=50 + + + { + "status": 200, + "detail": "Just slow down without waiting." + } + +B.2.3. Dynamic limits for pushing back and slowing down + + Continuing the previous example, let's say the client waits 10 + seconds and performs a new request which, due to resource exhaustion, + the server rejects and pushes back, advertising r=0 for the next 20 + seconds. + + The server advertises a smaller window with a lower limit to slow + down the client for the rest of its original window after the 20 + seconds elapse. + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 429 Too Many Requests + Content-Type: application/json + RateLimit-Policy: dynamic;l=15;w=20 + RateLimit: dynamic;r=0;t=20 + + { + "status": 429, + "detail": "Wait 20 seconds, then slow down!" + } + +B.3. Dynamic limits for pushing back with Retry-After and slow down + + Alternatively, given the same context where the previous example + starts, we can convey the same information to the client via Retry- + After, with the advantage that the server can now specify the + policy's nominal limit and window that will apply after the reset, + e.g. assuming the resource exhaustion is likely to be gone by then, + so the advertised policy does not need to be adjusted, yet we managed + to stop requests for a while and slow down the rest of the current + window. + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 429 Too Many Requests + Content-Type: application/json + Retry-After: 20 + RateLimit-Policy: dynamic;l=100;w=60 + RateLimit: dynamic;r=15;t=40 + + { + "status": 429, + "detail": "Wait 20 seconds, then slow down!" + } + + Note that in this last response the client is expected to honor + Retry-After and perform no requests for the specified amount of time, + whereas the previous example would not force the client to stop + requests before the reset time is elapsed, as it would still be free + to query again the server even if it is likely to have the request + rejected. + +B.3.1. Missing Remaining information + + The server does not expose remaining values (for example, because the + underlying counters are not available). Instead, it resets the limit + counter every second. + + It communicates to the client the limit of 10 quota units per second + always returning the limit and reset keywords. + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 200 Ok + Content-Type: application/json + RateLimit-Policy: quota;l=100;w=1 + RateLimit: quota;t=1 + + {"first": "request"} + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 200 Ok + Content-Type: application/json + RateLimit-Policy: quota;l=10 + RateLimit: quota;t=1 + + {"second": "request"} + +B.3.2. Use with multiple windows + + This is a standardized way of describing the policy detailed in + Appendix B.1.2: + + * 5000 daily quota units; + + * 1000 hourly quota units. + + The client consumed 4900 quota units in the first 14 hours. + + Despite the next hourly limit of 1000 quota units, the closest limit + to reach is the daily one. + + The server then exposes the RateLimit header fields to inform the + client that: + + * it has only 100 quota units left; + + * the window will reset in 10 hours; + + * the expiring-limit is 5000. + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 200 OK + Content-Type: application/json + RateLimit-Policy: hour;l=1000;w=3600, day;l=5000;w=86400 + RateLimit: day;r=100;t=36000 + + {"hello": "world"} + +FAQ + + This section is to be removed before publishing as an RFC. + + 1. Why defining standard fields for throttling? + + To simplify enforcement of throttling policies and enable clients + to constraint their requests to avoid being throttled. + + 2. Can I use RateLimit header fields in throttled responses (eg with + status code 429)? + + Yes, you can. + + 3. Are those specs tied to RFC 6585? + + No. [RFC6585] defines the 429 status code and we use it just as + an example of a throttled request, that could instead use even + 403 or whatever status code. + + 4. Why is the partition key necessary? + + Without a partition key, a server can only effectively only have + one scope (aka partition), which is impractical for most + services, or it needs to communicate the scopes out-of-band. + This prevents the development of generic connector code that can + be used to prevent requests from being throttled. Many APIs rely + on API keys, user identity or client identity to allocate quota. + As soon as a single client processes requests for more than one + partition, the client needs to know the corresponding partition + key to properly track requests against allocated quota. + + 5. Why using delay-seconds instead of a UNIX Timestamp? Why not + using subsecond precision? + + Using delay-seconds aligns with Retry-After, which is returned in + similar contexts, eg on 429 responses. + + Timestamps require a clock synchronization protocol (see + Section 5.6.7 of [HTTP]). This may be problematic (e.g. clock + adjustment, clock skew, failure of hardcoded clock + synchronization servers, IoT devices, ..). Moreover timestamps + may not be monotonically increasing due to clock adjustment. See + Another NTP client failure story + (https://community.ntppool.org/t/another-ntp-client-failure- + story/1014/) + + We did not use subsecond precision because: + + * that is more subject to system clock correction like the one + implemented via the adjtimex() Linux system call; + + * response-time latency may not make it worth. A brief + discussion on the subject is on the httpwg ml + (https://lists.w3.org/Archives/Public/ietf-http- + wg/2019JulSep/0202.html) + + * almost all rate-limit headers implementations do not use it. + + 6. Shouldn't I limit concurrency instead of request rate? + + You can use this specification to limit concurrency at the HTTP + level (see {#use-for-limiting-concurrency}) and help clients to + shape their requests avoiding being throttled out. + + A problematic way to limit concurrency is connection dropping, + especially when connections are multiplexed (e.g. HTTP/2) + because this results in unserviced client requests, which is + something we want to avoid. + + A semantic way to limit concurrency is to return 503 + Retry- + After in case of resource saturation (e.g. thrashing, connection + queues too long, Service Level Objectives not meet, ..). + Saturation conditions can be either dynamic or static: all this + is out of the scope for the current document. + + 7. Do a positive value of remaining paramter imply any service + guarantee for my future requests to be served? + + No. FAQ integrated in Section 4.1.1. + + 8. Is the quota-policy definition Section 2.5 too complex? + + You can always return the simplest form + + RateLimit:default;r=50;t=60 + + The policy key clearly connects the current usage status of a policy + to the defined limits. So for the following field: + +RateLimit-Policy: sliding;l=100;w=60;burst=1000;comment="sliding window", fixed;l=5000;w=3600;burst=0;comment="fixed window" +RateLimit: sliding;r=50;t=44 + + the value "sliding" identifies the policy being reported. + + 1. Can intermediaries alter RateLimit header fields? + + Generally, they should not because it might result in unserviced + requests. There are reasonable use cases for intermediaries + mangling RateLimit header fields though, e.g. when they enforce + stricter quota-policies, or when they are an active component of + the service. In those case we will consider them as part of the + originating infrastructure. + + 2. Why the w parameter is just informative? Could it be used by a + client to determine the request rate? + + A non-informative w parameter might be fine in an environment + where clients and servers are tightly coupled. Conveying + policies with this detail on a large scale would be very complex + and implementations would be likely not interoperable. We thus + decided to leave w as an informational parameter and only rely on + the limit, remaining and reset keywords for defining the + throttling behavior. + + 3. Can I use RateLimit fields in trailers? Servers usually + establish whether the request is in-quota before creating a + response, so the RateLimit field values should be already + available in that moment. Supporting trailers has the only + advantage that allows to provide more up-to-date information to + the client in case of slow responses. However, this complicates + client implementations with respect to combining fields from + headers and accounting for intermediaries that drop trailers. + Since there are no current implementations that use trailers, we + decided to leave this as a future-work. + +RateLimit header fields currently used on the web + + This section is to be removed before publishing as an RFC. + + Commonly used header field names are: + + * X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset; + + There are variants too, where the window is specified in the header + field name, eg: + + * x-ratelimit-limit-minute, x-ratelimit-limit-hour, x-ratelimit- + limit-day + + * x-ratelimit-remaining-minute, x-ratelimit-remaining-hour, x- + ratelimit-remaining-day + + Here are some interoperability issues: + + * X-RateLimit-Remaining references different values, depending on + the implementation: + + - seconds remaining to the window expiration + + - milliseconds remaining to the window expiration + + - seconds since UTC, in UNIX Timestamp [UNIX] + + - a datetime, either IMF-fixdate [HTTP] or [RFC3339] + + * different headers, with the same semantic, are used by different + implementers: + + - X-RateLimit-Limit and X-Rate-Limit-Limit + + - X-RateLimit-Remaining and X-Rate-Limit-Remaining + + - X-RateLimit-Reset and X-Rate-Limit-Reset + + The semantic of RateLimit depends on the windowing algorithm. A + sliding window policy for example, may result in having a remaining + keyword value related to the ratio between the current and the + maximum throughput. e.g. + +RateLimit-Policy: sliding;l=12;w=1 +RateLimit: sliding;l=12;r=6;t=1 ; using 50% of throughput, that is 6 units/s + + If this is the case, the optimal solution is to achieve + +RateLimit-Policy: sliding;l=12;w=1 +RateLimit: sliding;l=12;r=1;t=1 ; using 100% of throughput, that is 12 units/s + + At this point you should stop increasing your request rate. + +Acknowledgements + + Thanks to Willi Schoenborn, Alejandro Martinez Ruiz, Alessandro + Ranellucci, Amos Jeffries, Martin Thomson, Erik Wilde and Mark + Nottingham for being the initial contributors of these + specifications. Kudos to the first community implementers: Aapo + Talvensaari, Nathan Friedly and Sanyam Dogra. + + In addition to the people above, this document owes a lot to the + extensive discussion in the HTTPAPI workgroup, including Rich Salz, + Darrel Miller and Julian Reschke. + +Changes + + This section is to be removed before publishing as an RFC. + +Since draft-ietf-httpapi-ratelimit-headers-07 + + This section is to be removed before publishing as an RFC. + + * Refactored both fields to lists of Items that identify policy and + use parameters + + * Added quota unit parameter + + * Added partition key parameter + +Since draft-ietf-httpapi-ratelimit-headers-03 + + This section is to be removed before publishing as an RFC. + + * Split policy informatiom in RateLimit-Policy #81 + +Since draft-ietf-httpapi-ratelimit-headers-02 + + This section is to be removed before publishing as an RFC. + + * Address throttling scope #83 + +Since draft-ietf-httpapi-ratelimit-headers-01 + + This section is to be removed before publishing as an RFC. + + * Update IANA considerations #60 + + * Use Structured fields #58 + + * Reorganize document #67 + +Since draft-ietf-httpapi-ratelimit-headers-00 + + This section is to be removed before publishing as an RFC. + + * Use I-D.httpbis-semantics, which includes referencing delay- + seconds instead of delta-seconds. #5 + +Authors' Addresses + + Roberto Polli + Team Digitale, Italian Government + Italy + Email: robipolli@gmail.com + + + Alejandro Martinez Ruiz + Red Hat + Email: alex@flawedcode.org + + + Darrel Miller + Microsoft + Email: darrel@tavis.ca From e29b364c985a4427c40b5ab5276cbb2403b9b217 Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Sun, 29 Sep 2024 14:46:04 -0400 Subject: [PATCH 25/28] Added linting fixes --- .gitignore | 1 - draft-ietf-httpapi-ratelimit-headers.html | 2948 --------------------- draft-ietf-httpapi-ratelimit-headers.md | 17 +- draft-ietf-httpapi-ratelimit-headers.md~ | 1169 -------- draft-ietf-httpapi-ratelimit-headers.txt | 1435 ---------- 5 files changed, 9 insertions(+), 5561 deletions(-) delete mode 100644 .gitignore delete mode 100644 draft-ietf-httpapi-ratelimit-headers.html delete mode 100644 draft-ietf-httpapi-ratelimit-headers.md~ delete mode 100644 draft-ietf-httpapi-ratelimit-headers.txt diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 7951405..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -lib \ No newline at end of file diff --git a/draft-ietf-httpapi-ratelimit-headers.html b/draft-ietf-httpapi-ratelimit-headers.html deleted file mode 100644 index 60ed7d9..0000000 --- a/draft-ietf-httpapi-ratelimit-headers.html +++ /dev/null @@ -1,2948 +0,0 @@ - - - - - - -RateLimit header fields for HTTP - - - - - - - - - - - - - - - - - - - - - - - - - -
Internet-DraftRateLimit header fields for HTTPSeptember 2024
Polli, et al.Expires 2 April 2025[Page]
-
-
-
-
Workgroup:
-
HTTPAPI
-
Internet-Draft:
-
draft-ietf-httpapi-ratelimit-headers-latest
-
Published:
-
- -
-
Intended Status:
-
Standards Track
-
Expires:
-
-
Authors:
-
-
-
R. Polli
-
Team Digitale, Italian Government
-
-
-
A. Martinez
-
Red Hat
-
-
-
D. Miller
-
Microsoft
-
-
-
-
-

RateLimit header fields for HTTP

-
-

Abstract

-

This document defines the RateLimit-Policy and RateLimit HTTP header fields for servers to advertise their service policy limits and the current limits, thereby allowing clients to avoid being throttled.¶

-
-
-

-About This Document -

-

This note is to be removed before publishing as an RFC.¶

-

- Status information for this document may be found at https://datatracker.ietf.org/doc/draft-ietf-httpapi-ratelimit-headers/.¶

-

- Discussion of this document takes place on the - HTTPAPI Working Group mailing list (mailto:httpapi@ietf.org), - which is archived at https://mailarchive.ietf.org/arch/browse/httpapi/. - Subscribe at https://www.ietf.org/mailman/listinfo/httpapi/. - Working Group information can be found at https://datatracker.ietf.org/wg/httpapi/about/.¶

-

Source for this draft and an issue tracker can be found at - https://github.com/ietf-wg-httpapi/ratelimit-headers.¶

-
-
-
-

-Status of This Memo -

-

- This Internet-Draft is submitted in full conformance with the - provisions of BCP 78 and BCP 79.¶

-

- Internet-Drafts are working documents of the Internet Engineering Task - Force (IETF). Note that other groups may also distribute working - documents as Internet-Drafts. The list of current Internet-Drafts is - at https://datatracker.ietf.org/drafts/current/.¶

-

- Internet-Drafts are draft documents valid for a maximum of six months - and may be updated, replaced, or obsoleted by other documents at any - time. It is inappropriate to use Internet-Drafts as reference - material or to cite them other than as "work in progress."¶

-

- This Internet-Draft will expire on 2 April 2025.¶

-
-
- -
-
- â–²

-Table of Contents -

- -
-
-
-
-

-1. Introduction -

-

Rate limiting of HTTP clients has become a widespread practice, especially for HTTP APIs. Typically, servers who do so limit the number of acceptable requests in a given time window (e.g. 10 requests per second). See Appendix A for further information on the current usage of rate limiting in HTTP.¶

-

Currently, there is no standard way for servers to communicate quotas so that clients can throttle their requests to prevent errors. This document defines a set of standard HTTP header fields to enable rate limiting:¶

-
    -
  • -

    RateLimit: to convey -the server's current limit of quota units available to the client in the policy time window, -the remaining quota units in the current window, -and the time remaining in the current window, specified in seconds, and¶

    -
  • -
  • -

    RateLimit-Policy: the service policy limits.¶

    -
  • -
-

These fields enable establishing complex rate limiting policies, including using multiple and variable time windows and dynamic quotas, and implementing concurrency limits.¶

-

The behavior of the RateLimit header field is compatible with the delay-seconds notation of Retry-After.¶

-
-
-

-1.1. Goals -

-

The goals of this document are:¶

-
-
Interoperability:
-
-

Standardize the names and semantics of rate-limit headers -to ease their enforcement and adoption;¶

-
-
-
Resiliency:
-
-

Improve resiliency of HTTP infrastructure by -providing clients with information useful -to throttle their requests and -prevent 4xx or 5xx responses;¶

-
-
-
Documentation:
-
-

Simplify API documentation by eliminating the need -to include detailed quota limits -and related fields in API documentation.¶

-
-
-
-

The following features are out of the scope of this document:¶

-
-
Authorization:
-
-

RateLimit header fields are not meant to support -authorization or other kinds of access controls.¶

-
-
-
Response status code:
-
-

RateLimit header fields may be returned in both -successful (see Section 15.3 of [HTTP]) and non-successful responses. -This specification does not cover whether non Successful -responses count on quota usage, -nor does it mandates any correlation between the RateLimit values -and the returned status code.¶

-
-
-
Throttling algorithm:
-
-

This specification does not mandate a specific throttling algorithm. -The values published in the fields, including the window size, -can be statically or dynamically evaluated.¶

-
-
-
Service Level Agreement:
-
-

Conveyed quota hints do not imply any service guarantee. -Server is free to throttle respectful clients under certain circumstances.¶

-
-
-
-
-
-
-
-

-1.2. Notational Conventions -

-

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL -NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", -"MAY", and "OPTIONAL" in this document are to be interpreted as -described in BCP 14 [RFC2119] [RFC8174] when, and only when, they -appear in all capitals, as shown here.¶

-

The term Origin is to be interpreted as described in Section 7 of [WEB-ORIGIN].¶

-

This document uses the terms List, Item and Integer from Section 3 of [STRUCTURED-FIELDS] to specify syntax and parsing, along with the concept of "bare item".¶

-
-
-
-
-
-
-

-2. Terminology -

-
-
-

-2.1. Quota -

-

A quota is an allocation of capacity to enable a server to limit client requests. That capacity is counted in quota units and may be reallocated at the end of a time window Section 2.4.¶

-
-
-
-
-

-2.2. Quota Unit -

-

A quota unit is the unit of measure used to count the activity of a client.¶

-
-
-
-
-

-2.3. Quota Partition -

-

A quota partition is a division of a server's capacity across different clients, users and owned resources.¶

-
-
-
-
-

-2.4. Time Window -

-

A time window indicates a period of time associated to the allocated quota.¶

-

The time window is a non-negative Integer value expressing an interval in seconds, similar to the "delay-seconds" rule defined in Section 10.2.3 of [HTTP]. Sub-second precision is not supported.¶

-
-
-
-
-

-2.5. Quota Policy -

-

A quota policy is maintained by a server to limit the activity (counted in quota units (Section 2.2)) of a given quota partition (Section 2.3) over a period of time (known as the time window (Section 2.4)) to a specified amount known as the Section 2.1.¶

-

Quota policies can be advertised by servers (see Section 3), but they are not required to be, and more than one quota policy can affect a given request from a client to a server.¶

-
-
-
-
-

-2.6. Service Limit -

-

A service limit is the current limit of the amount of activity that a server will allow based on the remaining quota for a particular quota partition within the time-window, if defined.¶

-
-
-
-
-
-
-

-3. RateLimit-Policy Field -

-

The "RateLimit-Policy" response header field is a non-empty List of Section 3.1. Its value is informative. The values are expected to remain consistent over a the lifetime of a connection. It is this characteristic that differentiates it from the RateLimit (Section 4) that contains values that may change on every request.¶

-
-
-   RateLimit-Policy: burst;q=100;w=60,daily;q=1000;w=86400
-
¶ -
-
-
-

-3.1. Quota Policy Item -

-

A quota policy Item contains information about a server's capacity allocation for a quota partition associated with the request.¶

-

The following parameters are defined in this specification:¶

-
-
q:
-
-

The REQUIRED "q" parameter indicates the quota allocated. (Section 3.1.1)¶

-
-
-
qu:
-
-

The OPTIONAL "qu" parameter value conveys the quota units associated to the "q" parameter. The default quota unit is "request". (Section 3.1.2)¶

-
-
-
w:
-
-

The OPTIONAL "w" parameter value conveys a time "window" (Section 2.4). (Section 3.1.3)¶

-
-
-
pk:
-
-

The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. Section 3.1.4¶

-
-
-
-

Other parameters are allowed and can be regarded as comments.¶

-

Implementation- or service-specific parameters SHOULD be prefixed parameters with a vendor identifier, e.g. acme-policy, acme-burst.¶

-
-
-

-3.1.1. Quota Parameter -

-

The "q" parameter uses a non-negative integer value to indicate the quota allocated for client activity (counted in quota units) for a given quota partition (Section 2.6).¶

-
-
-
-
-

-3.1.2. Quota Unit Parameter -

-

The "qu" parameter value conveys the quota units associated to the "q" parameter.¶

-
-
-
-
-

-3.1.3. Window Parameter -

-

The "w" parameter value conveys a time "window" in seconds. (Section 2.4).¶

-
-
-
-
-

-3.1.4. Partition Key Parameter -

-

The "pk" parameter value conveys the partition key associated to the request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key.¶

-
-
-
-
-
-
-

-3.2. RateLimit Policy Field Examples -

-

This field MAY convey the time window associated with the expiring-limit, as shown in this example:¶

-
-
-   RateLimit-Policy: default;l=100;w=10
-
¶ -
-

These examples show multiple policies being returned:¶

-
-
-   RateLimit-Policy: permin;l=50;w=60,perhr;l=1000;w=3600,perday;l=5000;w=86400
-
¶ -
-

The following example shows a policy with a partition key:¶

-
-
-   RateLimit-Policy: peruser;l=100;w=60;pk=user123
-
¶ -
-

The following example shows a policy with a partition key and a quota unit:¶

-
-
-   RateLimit-Policy: peruser;l=65535;w=10;pk=user123;qu=bytes
-
¶ -
-

This field cannot appear in a trailer section.¶

-
-
-
-
-
-
-

-4. RateLimit Field -

-

A server uses the "RateLimit" response header field to communicate the service limit for a quota policy for a particular partition key.¶

-

The field is expressed as List of Section 4.1.¶

-
-
-   RateLimit: default;r=50;t=30
-
¶ -
-
-
-

-4.1. Service Limit Item -

-

Each service limit item in identifies the quota policy associated with the request and¶

-

The following parameters are defined in this specification:¶

-
-
r:
-
-

This parameter value conveys the remaining quota units for the identified policy (Section 4.1.1).¶

-
-
-
t:
-
-

This OPTIONAL parameter value conveys the time window reset time for the identified policy (Section 4.1.2).¶

-
-
-
pk:
-
-

The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request.¶

-
-
-
-

This field cannot appear in a trailer section. Other parameters are allowed and can be regarded as comments.¶

-

Implementation- or service-specific parameters SHOULD be prefixed parameters with a vendor identifier, e.g. acme-policy, acme-burst.¶

-
-
-

-4.1.1. Remaining Parameter -

-

The "r" parameter indicates the remaining quota units for the identified policy (Section 4.1.1).¶

-

It is a non-negative Integer expressed in quota units (Section 2.2). -Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. -When remaining parameter value is low, it indicates that the server may soon throttle the client (see Section 5).¶

-
-
-
-
-

-4.1.2. Reset Parameter -

-

The "t" parameter indicates the number of seconds until the quota associated with the quota policy resets.¶

-

It is a non-negative Integer compatible with the delay-seconds rule, because:¶

-
    -
  • -

    it does not rely on clock synchronization and is resilient to clock adjustment -and clock skew between client and server (see Section 5.6.7 of [HTTP]);¶

    -
  • -
  • -

    it mitigates the risk related to thundering herd when too many clients are serviced with the same timestamp.¶

    -
  • -
-

The client MUST NOT assume that all its service limit will be reset at the moment indicated by the reset keyword. The server MAY arbitrarily alter the reset parameter value between subsequent requests; for example, in case of resource saturation or to implement sliding window policies.¶

-
-
-
-
-

-4.1.3. Partition Key Parameter -

-

The "pk" parameter value conveys the partition key associated to the request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key.¶

-
-
-
-
-
-
-

-4.2. RateLimit Field Examples -

-

This example shows a RateLimit field with a remaining quota of 50 units and a time window reset in 30 seconds:¶

-
-
-   RateLimit: default;r=50;t=30
-
¶ -
-

This example shows a remaining quota of 999 requests for a partition key that has no time window reset:¶

-
-
-   RateLimit: default;r=999;pk=trial-121323
-
¶ -
-

This example shows a 300MB remaining quota for an application in the next 60 seconds:¶

-
-
-   RateLimit: default;r=300000000;pk=App-999;t=60;qu=bytes
-
¶ -
-
-
-
-
-
-
-

-5. Server Behavior -

-

A server MAY return RateLimit header fields independently of the response status code. This includes on throttled responses. This document does not mandate any correlation between the RateLimit header field values and the returned status code.¶

-

Servers should be careful when returning RateLimit header fields in redirection responses (i.e., responses with 3xx status codes) because a low remaining keyword value could prevent the client from issuing requests. For example, given the RateLimit header fields below, a client could decide to wait 10 seconds before following the "Location" header field (see Section 10.2.2 of [HTTP]), because the remaining keyword value is 0.¶

-
-
-HTTP/1.1 301 Moved Permanently
-Location: /foo/123
-RateLimit: problemPolicy;r=0, t=10
-
-
¶ -
-

If a response contains both the Retry-After and the RateLimit header fields, the reset keyword value SHOULD reference the same point in time as the Retry-After field value.¶

-

A service using RateLimit header fields MUST NOT convey values exposing an unwanted volume of requests and SHOULD implement mechanisms to cap the ratio between the remaining and the reset keyword values (see Section 7.5); this is especially important when a quota policy uses a large time window.¶

-

Under certain conditions, a server MAY artificially lower RateLimit header field values between subsequent requests, e.g. to respond to Denial of Service attacks or in case of resource saturation.¶

-
-
-

-5.1. Performance Considerations -

-

Servers are not required to return RateLimit header fields in every response, and clients need to take this into account. For example, an implementer concerned with performance might provide RateLimit header fields only when a given quota is close to exhaustion.¶

-

Implementers concerned with response fields' size, might take into account their ratio with respect to the content length, or use header-compression HTTP features such as [HPACK].¶

-
-
-
-
-
-
-

-6. Client Behavior -

-

The RateLimit header fields can be used by clients to determine whether the associated request respected the server's quota policy, and as an indication of whether subsequent requests will. However, the server might apply other criteria when servicing future requests, and so the quota policy may not completely reflect whether requests will succeed.¶

-

For example, a successful response with the following fields:¶

-
-
-   RateLimit: default;r=1;t=7
-
¶ -
-

does not guarantee that the next request will be successful. Servers' behavior may be subject to other conditions.¶

-

A client is responsible for ensuring that RateLimit header field values returned -cause reasonable client behavior with respect to throughput and latency -(see Section 7.5 and Section 7.5.1).¶

-

A client receiving RateLimit header fields MUST NOT assume that future responses will contain the same RateLimit header fields, or any RateLimit header fields at all.¶

-

Malformed RateLimit header fields MUST be ignored.¶

-

A client SHOULD NOT exceed the quota units conveyed by the remaining keyword before the time window expressed in the reset keyword.¶

-

The value of the reset keyword is generated at response time: a client aware of a significant network latency MAY behave accordingly and use other information (e.g. the "Date" response header field, or otherwise gathered metrics) to better estimate the reset keyword moment intended by the server.¶

-

The details provided in the RateLimit-Policy header field are informative and MAY be ignored.¶

-

If a response contains both the RateLimit and Retry-After fields, the Retry-After field MUST take precedence and the reset keyword MAY be ignored.¶

-

This specification does not mandate a specific throttling behavior and implementers can adopt their preferred policies, including:¶

-
    -
  • -

    slowing down or pre-emptively back-off their request rate when -approaching quota limits;¶

    -
  • -
  • -

    consuming all the quota according to the exposed limits and then wait.¶

    -
  • -
-
-
-

-6.1. Intermediaries -

-

This section documents the considerations advised in Section 16.3.2 of [HTTP].¶

-

An intermediary that is not part of the originating service infrastructure and is not aware of the quota policy semantic used by the Origin Server SHOULD NOT alter the RateLimit header fields' values in such a way as to communicate a more permissive quota policy; this includes removing the RateLimit header fields.¶

-

An intermediary MAY alter the RateLimit header fields in such a way as to communicate a more restrictive quota policy when:¶

-
    -
  • -

    it is aware of the quota unit semantic used by the Origin Server;¶

    -
  • -
  • -

    it implements this specification and enforces a quota policy which -is more restrictive than the one conveyed in the fields.¶

    -
  • -
-

An intermediary SHOULD forward a request even when presuming that it might not be serviced; the service returning the RateLimit header fields is the sole responsible of enforcing the communicated quota policy, and it is always free to service incoming requests.¶

-

This specification does not mandate any behavior on intermediaries respect to retries, nor requires that intermediaries have any role in respecting quota policies. For example, it is legitimate for a proxy to retransmit a request without notifying the client, and thus consuming quota units.¶

-

Privacy considerations (Section 8) provide further guidance on intermediaries.¶

-
-
-
-
-

-6.2. Caching -

-

[HTTP-CACHING] defines how responses can be stored and reused for subsequent requests, -including those with RateLimit header fields. -Because the information in RateLimit header fields on a cached response may not be current, they SHOULD be ignored on responses that come from cache -(i.e., those with a positive current_age; see Section 4.2.3 of [HTTP-CACHING]).¶

-
-
-
-
-
-
-

-7. Security Considerations -

-
-
-

-7.1. Throttling does not prevent clients from issuing requests -

-

This specification does not prevent clients from making requests. -Servers should always implement mechanisms to prevent resource exhaustion.¶

-
-
-
-
-

-7.2. Information disclosure -

-

Servers should not disclose to untrusted parties operational capacity information -that can be used to saturate its infrastructural resources.¶

-

While this specification does not mandate whether non-successful responses consume quota, -if error responses (such as 401 (Unauthorized) and 403 (Forbidden)) count against quota, -a malicious client could probe the endpoint to get traffic information of another user.¶

-

As intermediaries might retransmit requests and consume -quota units without prior knowledge of the user agent, -RateLimit header fields might reveal the existence of an intermediary -to the user agent.¶

-

Where partition keys contain identifying information, either of the client application or the user, servers should be aware of the potential for impersonation and apply the appropriate security mechanisms.¶

-
-
-
-
-

-7.3. Remaining quota units are not granted requests -

-

RateLimit header fields convey hints from the server -to the clients in order to help them avoid being throttled out.¶

-

Clients MUST NOT consider the quota units (Section 2.6) returned in remaining keyword as a service level agreement.¶

-

In case of resource saturation, the server MAY artificially lower the returned values -or not serve the request regardless of the advertised quotas.¶

-
-
-
-
-

-7.4. Reliability of the reset keyword -

-

Consider that quota might not be restored after the moment referenced by the reset keyword (Section 4.1.2), -and the reset parameter value may not be constant.¶

-

Subsequent requests might return a higher reset parameter value -to limit concurrency or implement dynamic or adaptive throttling policies.¶

-
-
-
-
-

-7.5. Resource exhaustion -

-

When returning reset values, servers must be aware that -many throttled clients may come back at the very moment specified.¶

-

This is true for Retry-After too.¶

-

For example, if the quota resets every day at 18:00:00 -and your server returns the reset parameter accordingly¶

-
-
-   Date: Tue, 15 Nov 1994 18:00:00 GMT
-   RateLimit: daily;r=1;t=36400
-
¶ -
-

there's a high probability that all clients will show up at 18:00:00.¶

-

This could be mitigated by adding some jitter to the reset value.¶

-

Resource exhaustion issues can be associated with quota policies using a -large time window, because a user agent by chance or on purpose -might consume most of its quota units in a significantly shorter interval.¶

-

This behavior can be even triggered by the provided RateLimit header fields. -The following example describes a service -with an unconsumed quota policy of 10000 quota units per 1000 seconds.¶

-
-
-RateLimit-Policy: somepolicy;l=10000;w=1000
-RateLimit: somepolicy;r=10000;t=10
-
¶ -
-

A client implementing a simple ratio between remaining keyword and reset keyword could infer an average throughput of 1000 quota units per second, while the limit keyword conveys a quota-policy with an average of 10 quota units per second. -If the service cannot handle such load, it should return either a lower remaining keyword value or an higher reset keyword value. -Moreover, complementing large time window quota policies with a short time window one mitigates those risks.¶

-
-
-

-7.5.1. Denial of Service -

-

RateLimit header fields may contain unexpected values by chance or on purpose. -For example, an excessively high remaining keyword value may be:¶

-
    -
  • -

    used by a malicious intermediary to trigger a Denial of Service attack -or consume client resources boosting its requests;¶

    -
  • -
  • -

    passed by a misconfigured server;¶

    -
  • -
-

or a high reset keyword value could inhibit clients to contact the server (e.g. similarly to receiving "Retry-after: 1000000").¶

-

To mitigate this risk, clients can set thresholds that they consider reasonable in terms of quota units, time window, concurrent requests or throughput, and define a consistent behavior when the RateLimit exceed those thresholds. -For example this means capping the maximum number of request per second, or implementing retries when the reset keyword exceeds ten minutes.¶

-

The considerations above are not limited to RateLimit header fields, but apply to all fields affecting how clients behave in subsequent requests (e.g. Retry-After).¶

-
-
-
-
-
-
-
-
-

-8. Privacy Considerations -

-

Clients that act upon a request to rate limit -are potentially re-identifiable (see Section 5.2.1 of [PRIVACY]) -because they react to information that might only be given to them. -Note that this might apply to other fields too (e.g. Retry-After).¶

-

Since rate limiting is usually implemented in contexts where -clients are either identified or profiled -(e.g. assigning different quota units to different users), -this is rarely a concern.¶

-

Privacy enhancing infrastructures using RateLimit header fields -can define specific techniques to mitigate the risks of re-identification.¶

-
-
-
-
-

-9. IANA Considerations -

-

IANA is requested to update one registry and create one new registry.¶

-

Please add the following entries to the -"Hypertext Transfer Protocol (HTTP) Field Name Registry" registry ([HTTP]):¶

- - - - - - - - - - - - - - - - - - - - - -
Table 1
Field NameStatusSpecification
RateLimitpermanent - Section 4 of RFC nnnn
RateLimit-Policypermanent - Section 3 of RFC nnnn
-
-
-
-

-10. References -

-
-
-

-10.1. Normative References -

-
-
[HTTP]
-
-Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, Ed., "HTTP Semantics", STD 97, RFC 9110, DOI 10.17487/RFC9110, , <https://www.rfc-editor.org/rfc/rfc9110>.
-
-
[IANA]
-
-Cotton, M., Leiba, B., and T. Narten, "Guidelines for Writing an IANA Considerations Section in RFCs", BCP 26, RFC 8126, DOI 10.17487/RFC8126, , <https://www.rfc-editor.org/rfc/rfc8126>.
-
-
[RFC2119]
-
-Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, , <https://www.rfc-editor.org/rfc/rfc2119>.
-
-
[RFC8174]
-
-Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, , <https://www.rfc-editor.org/rfc/rfc8174>.
-
-
[STRUCTURED-FIELDS]
-
-Nottingham, M. and P. Kamp, "Structured Field Values for HTTP", RFC 8941, DOI 10.17487/RFC8941, , <https://www.rfc-editor.org/rfc/rfc8941>.
-
-
[WEB-ORIGIN]
-
-Barth, A., "The Web Origin Concept", RFC 6454, DOI 10.17487/RFC6454, , <https://www.rfc-editor.org/rfc/rfc6454>.
-
-
-
-
-
-
-

-10.2. Informative References -

-
-
[HPACK]
-
-Peon, R. and H. Ruellan, "HPACK: Header Compression for HTTP/2", RFC 7541, DOI 10.17487/RFC7541, , <https://www.rfc-editor.org/rfc/rfc7541>.
-
-
[HTTP-CACHING]
-
-Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, Ed., "HTTP Caching", STD 98, RFC 9111, DOI 10.17487/RFC9111, , <https://www.rfc-editor.org/rfc/rfc9111>.
-
-
[PRIVACY]
-
-Cooper, A., Tschofenig, H., Aboba, B., Peterson, J., Morris, J., Hansen, M., and R. Smith, "Privacy Considerations for Internet Protocols", RFC 6973, DOI 10.17487/RFC6973, , <https://www.rfc-editor.org/rfc/rfc6973>.
-
-
[RFC3339]
-
-Klyne, G. and C. Newman, "Date and Time on the Internet: Timestamps", RFC 3339, DOI 10.17487/RFC3339, , <https://www.rfc-editor.org/rfc/rfc3339>.
-
-
[RFC6585]
-
-Nottingham, M. and R. Fielding, "Additional HTTP Status Codes", RFC 6585, DOI 10.17487/RFC6585, , <https://www.rfc-editor.org/rfc/rfc6585>.
-
-
[UNIX]
-
-The Open Group, "The Single UNIX Specification, Version 2 - 6 Vol Set for UNIX 98", .
-
-
-
-
-
-
-
-

-Appendix A. Rate-limiting and quotas -

-

Servers use quota mechanisms to avoid systems overload, to ensure an equitable distribution of computational resources or to enforce other policies - e.g. monetization.¶

-

A basic quota mechanism limits the number of acceptable requests in a given time window, e.g. 10 requests per second.¶

-

When quota is exceeded, servers usually do not serve the request replying instead with a 4xx HTTP status code (e.g. 429 or 403) or adopt more aggressive policies like dropping connections.¶

-

Quotas may be enforced on different basis (e.g. per user, per IP, per geographic area, ..) and at different levels. For example, an user may be allowed to issue:¶

-
    -
  • -

    10 requests per second;¶

    -
  • -
  • -

    limited to 60 requests per minute;¶

    -
  • -
  • -

    limited to 1000 requests per hour.¶

    -
  • -
-

Moreover system metrics, statistics and heuristics can be used to implement more complex policies, -where the number of acceptable requests and the time window are computed dynamically.¶

-

To help clients throttling their requests, -servers may expose the counters used to evaluate quota policies via HTTP header fields.¶

-

Those response headers may be added by HTTP intermediaries such as API gateways and reverse proxies.¶

-

On the web we can find many different rate-limit headers, -usually containing the number of allowed requests in a given time window, and when the window is reset.¶

-

The common choice is to return three headers containing:¶

-
    -
  • -

    the maximum number of allowed requests in the time window;¶

    -
  • -
  • -

    the number of remaining requests in the current window;¶

    -
  • -
  • -

    the time remaining in the current window expressed in seconds or -as a timestamp;¶

    -
  • -
-
-
-

-A.1. Interoperability issues -

-

A major interoperability issue in throttling is the lack of standard headers, because:¶

-
    -
  • -

    each implementation associates different semantics to the -same header field names;¶

    -
  • -
  • -

    header field names proliferates.¶

    -
  • -
-

User agents interfacing with different servers may thus need to process different headers, -or the very same application interface that sits behind different reverse proxies -may reply with different throttling headers.¶

-
-
-
-
-
-
-

-Appendix B. Examples -

-
-
-

-B.1. Responses without defining policies -

-

Some servers may not expose the policy limits in the RateLimit-Policy header field. Clients can still use the RateLimit header field to throttle their requests.¶

-
-
-

-B.1.1. Throttling information in responses -

-

The client exhausted its quota for the next 50 seconds. -The limit and time-window is communicated out-of-band.¶

-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 200 Ok
-Content-Type: application/json
-RateLimit: default;r=0;t=50
-
-{"hello": "world"}
-
¶ -
-

Since the field values are not necessarily correlated with -the response status code, -a subsequent request is not required to fail. -The example below shows that the server decided to serve the request -even if remaining keyword value is 0. -Another server, or the same server under other load conditions, could have decided to throttle the request instead.¶

-

Request:¶

-
-
-GET /items/456 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 200 Ok
-Content-Type: application/json
-RateLimit: default;r=0;t=48
-
-{"still": "successful"}
-
¶ -
-
-
-
-
-

-B.1.2. Multiple policies in response -

-

The server uses two different policies to limit the client's requests:¶

-
    -
  • -

    5000 daily quota units;¶

    -
  • -
  • -

    1000 hourly quota units.¶

    -
  • -
-

The client consumed 4900 quota units in the first 14 hours.¶

-

Despite the next hourly limit of 1000 quota units, -the closest limit to reach is the daily one.¶

-

The server then exposes the RateLimit header fields to -inform the client that:¶

-
    -
  • -

    it has only 100 quota units left in the daily quota and the window will reset in 10 hours;¶

    -
  • -
-

The server MAY choose to omit returning the hourly policy as it uses the same quota units as the daily policy and the daily policy is the one that is closest to being exhausted.¶

-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 200 Ok
-Content-Type: application/json
-RateLimit: dayLimit;r=100;t=36000
-
-{"hello": "world"}
-
¶ -
-
-
-
-
-

-B.1.3. Use for limiting concurrency -

-

RateLimit header fields may be used to limit concurrency, -advertising limits that are lower than the usual ones -in case of saturation, thus increasing availability.¶

-

The server adopted a basic policy of 100 quota units per minute, -and in case of resource exhaustion adapts the returned values -reducing both limit and remaining keyword values.¶

-

After 2 seconds the client consumed 40 quota units¶

-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 200 Ok
-Content-Type: application/json
-RateLimit-Policy: basic;l=100;w=60
-RateLimit: basic;r=60;t=58
-
-{"elapsed": 2, "issued": 40}
-
¶ -
-

At the subsequent request - due to resource exhaustion - -the server advertises only r=20.¶

-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 200 Ok
-Content-Type: application/json
-RateLimit-Policy: basic;l=100;w=60
-RateLimit: basic;r=20;t=56
-
-{"elapsed": 4, "issued": 41}
-
¶ -
-
-
-
-
-

-B.1.4. Use in throttled responses -

-

A client exhausted its quota and the server throttles it -sending Retry-After.¶

-

In this example, the values of Retry-After and RateLimit header field reference the same moment, -but this is not a requirement.¶

-

The 429 (Too Many Request) HTTP status code is just used as an example.¶

-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 429 Too Many Requests
-Content-Type: application/json
-Date: Mon, 05 Aug 2019 09:27:00 GMT
-Retry-After: Mon, 05 Aug 2019 09:27:05 GMT
-RateLimit: default;r=0;t=5
-
-{
-"title": "Too Many Requests",
-"status": 429,
-"detail": "You have exceeded your quota"
-}
-
¶ -
-
-
-
-
-
-
-

-B.2. Responses with defined policies -

-
-
-

-B.2.1. Throttling window specified via parameter -

-

The client has 99 quota units left for the next 50 seconds. -The time window is communicated by the w parameter, so we know the throughput is 100 quota units per minute.¶

-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 200 Ok
-Content-Type: application/json
-RateLimit: fixedwindow;r=99;t=50
-RateLimit-Policy: fixedwindow;l=100;w=60
-{"hello": "world"}
-
¶ -
-
-
-
-
-

-B.2.2. Dynamic limits with parameterized windows -

-

The policy conveyed by the RateLimit header field states that -the server accepts 100 quota units per minute.¶

-

To avoid resource exhaustion, the server artificially lowers -the actual limits returned in the throttling headers.¶

-

The remaining keyword then advertises -only 9 quota units for the next 50 seconds to slow down the client.¶

-

Note that the server could have lowered even the other -values in the RateLimit header field: this specification -does not mandate any relation between the field values -contained in subsequent responses.¶

-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 200 Ok
-Content-Type: application/json
-RateLimit-Policy: dynamic;l=100;w=60
-RateLimit: dynamic;r=9;t=50
-
-
-{
-  "status": 200,
-  "detail": "Just slow down without waiting."
-}
-
¶ -
-
-
-
-
-

-B.2.3. Dynamic limits for pushing back and slowing down -

-

Continuing the previous example, let's say the client waits 10 seconds and -performs a new request which, due to resource exhaustion, the server rejects -and pushes back, advertising r=0 for the next 20 seconds.¶

-

The server advertises a smaller window with a lower limit to slow -down the client for the rest of its original window after the 20 seconds elapse.¶

-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 429 Too Many Requests
-Content-Type: application/json
-RateLimit-Policy: dynamic;l=15;w=20
-RateLimit: dynamic;r=0;t=20
-
-{
-  "status": 429,
-  "detail": "Wait 20 seconds, then slow down!"
-}
-
¶ -
-
-
-
-
-
-
-

-B.3. Dynamic limits for pushing back with Retry-After and slow down -

-

Alternatively, given the same context where the previous example starts, we -can convey the same information to the client via Retry-After, with -the advantage that the server can now specify the policy's nominal limit and -window that will apply after the reset, e.g. assuming the resource exhaustion -is likely to be gone by then, so the advertised policy does not need to be -adjusted, yet we managed to stop requests for a while and slow down the rest of -the current window.¶

-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 429 Too Many Requests
-Content-Type: application/json
-Retry-After: 20
-RateLimit-Policy: dynamic;l=100;w=60
-RateLimit: dynamic;r=15;t=40
-
-{
-  "status": 429,
-  "detail": "Wait 20 seconds, then slow down!"
-}
-
¶ -
-

Note that in this last response the client is expected to honor -Retry-After and perform no requests for the specified amount of -time, whereas the previous example would not force the client to stop -requests before the reset time is elapsed, as it would still be free to -query again the server even if it is likely to have the request rejected.¶

-
-
-

-B.3.1. Missing Remaining information -

-

The server does not expose remaining values -(for example, because the underlying counters are not available). -Instead, it resets the limit counter every second.¶

-

It communicates to the client the limit of 10 quota units per second -always returning the limit and reset keywords.¶

-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 200 Ok
-Content-Type: application/json
-RateLimit-Policy: quota;l=100;w=1
-RateLimit: quota;t=1
-
-{"first": "request"}
-
¶ -
-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 200 Ok
-Content-Type: application/json
-RateLimit-Policy: quota;l=10
-RateLimit: quota;t=1
-
-{"second": "request"}
-
¶ -
-
-
-
-
-

-B.3.2. Use with multiple windows -

-

This is a standardized way of describing the policy -detailed in Appendix B.1.2:¶

-
    -
  • -

    5000 daily quota units;¶

    -
  • -
  • -

    1000 hourly quota units.¶

    -
  • -
-

The client consumed 4900 quota units in the first 14 hours.¶

-

Despite the next hourly limit of 1000 quota units, the closest limit -to reach is the daily one.¶

-

The server then exposes the RateLimit header fields to inform the client that:¶

-
    -
  • -

    it has only 100 quota units left;¶

    -
  • -
  • -

    the window will reset in 10 hours;¶

    -
  • -
  • -

    the expiring-limit is 5000.¶

    -
  • -
-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 200 OK
-Content-Type: application/json
-RateLimit-Policy: hour;l=1000;w=3600, day;l=5000;w=86400
-RateLimit: day;r=100;t=36000
-
-{"hello": "world"}
-
¶ -
-
-
-
-
-
-
-
-
-

-FAQ -

-

This section is to be removed before publishing as an RFC.¶

-
    -
  1. -

    Why defining standard fields for throttling?¶

    -

    -To simplify enforcement of throttling policies and enable clients to constraint their requests to avoid being throttled.¶

    -
  2. -
  3. -

    Can I use RateLimit header fields in throttled responses (eg with status code 429)?¶

    -

    -Yes, you can.¶

    -
  4. -
  5. -

    Are those specs tied to RFC 6585?¶

    -

    -No. [RFC6585] defines the 429 status code and we use it just as an example of a throttled request, -that could instead use even 403 or whatever status code.¶

    -
  6. -
  7. -

    Why is the partition key necessary?¶

    -

    -Without a partition key, a server can only effectively only have one scope (aka partition), which is impractical for most services, or it needs to communicate the scopes out-of-band. -This prevents the development of generic connector code that can be used to prevent requests from being throttled. -Many APIs rely on API keys, user identity or client identity to allocate quota. -As soon as a single client processes requests for more than one partition, the client needs to know the corresponding partition key to properly track requests against allocated quota.¶

    -
  8. -
  9. -

    Why using delay-seconds instead of a UNIX Timestamp? -Why not using subsecond precision?¶

    -

    -Using delay-seconds aligns with Retry-After, which is returned in similar contexts, -eg on 429 responses.¶

    -

    -Timestamps require a clock synchronization protocol -(see Section 5.6.7 of [HTTP]). -This may be problematic (e.g. clock adjustment, clock skew, failure of hardcoded clock synchronization servers, -IoT devices, ..). -Moreover timestamps may not be monotonically increasing due to clock adjustment. -See Another NTP client failure story¶

    -

    -We did not use subsecond precision because:¶

    -
      -
    • -

      that is more subject to system clock correction -like the one implemented via the adjtimex() Linux system call;¶

      -
    • -
    • -

      response-time latency may not make it worth. A brief discussion on the subject is -on the httpwg ml¶

      -
    • -
    • -

      almost all rate-limit headers implementations do not use it.¶

      -
    • -
    -
  10. -
  11. -

    Shouldn't I limit concurrency instead of request rate?¶

    -

    -You can use this specification to limit concurrency -at the HTTP level (see {#use-for-limiting-concurrency}) -and help clients to shape their requests avoiding being throttled out.¶

    -

    -A problematic way to limit concurrency is connection dropping, -especially when connections are multiplexed (e.g. HTTP/2) -because this results in unserviced client requests, -which is something we want to avoid.¶

    -

    -A semantic way to limit concurrency is to return 503 + Retry-After -in case of resource saturation (e.g. thrashing, connection queues too long, -Service Level Objectives not meet, ..). -Saturation conditions can be either dynamic or static: all this is out of -the scope for the current document.¶

    -
  12. -
  13. -

    Do a positive value of remaining paramter imply any service guarantee for my -future requests to be served?¶

    -

    -No. FAQ integrated in Section 4.1.1.¶

    -
  14. -
  15. -

    Is the quota-policy definition Section 2.5 too complex?¶

    -

    -You can always return the simplest form¶

    -
  16. -
-
-
-RateLimit:default;r=50;t=60
-
¶ -
-

The policy key clearly connects the current usage status of a policy to the defined limits. - So for the following field:¶

-
-
-RateLimit-Policy: sliding;l=100;w=60;burst=1000;comment="sliding window", fixed;l=5000;w=3600;burst=0;comment="fixed window"
-RateLimit: sliding;r=50;t=44
-
¶ -
-

the value "sliding" identifies the policy being reported.¶

-
    -
  1. -

    Can intermediaries alter RateLimit header fields?¶

    -

    -Generally, they should not because it might result in unserviced requests. - There are reasonable use cases for intermediaries mangling RateLimit header fields though, - e.g. when they enforce stricter quota-policies, - or when they are an active component of the service. - In those case we will consider them as part of the originating infrastructure.¶

    -
  2. -
  3. -

    Why the w parameter is just informative? -Could it be used by a client to determine the request rate?¶

    -

    -A non-informative w parameter might be fine in an environment -where clients and servers are tightly coupled. Conveying policies -with this detail on a large scale would be very complex and implementations -would be likely not interoperable. We thus decided to leave w as -an informational parameter and only rely on the limit, remaining and reset keywords -for defining the throttling -behavior.¶

    -
  4. -
  5. -

    Can I use RateLimit fields in trailers? -Servers usually establish whether the request is in-quota before creating a response, so the RateLimit field values should be already available in that moment. -Supporting trailers has the only advantage that allows to provide more up-to-date information to the client in case of slow responses. -However, this complicates client implementations with respect to combining fields from headers and accounting for intermediaries that drop trailers. -Since there are no current implementations that use trailers, we decided to leave this as a future-work.¶

    -
  6. -
-
-
-
-
-

-RateLimit header fields currently used on the web -

-

This section is to be removed before publishing as an RFC.¶

-

Commonly used header field names are:¶

-
    -
  • -

    X-RateLimit-Limit, -X-RateLimit-Remaining, -X-RateLimit-Reset;¶

    -
  • -
-

There are variants too, where the window is specified -in the header field name, eg:¶

-
    -
  • -

    x-ratelimit-limit-minute, x-ratelimit-limit-hour, x-ratelimit-limit-day¶

    -
  • -
  • -

    x-ratelimit-remaining-minute, x-ratelimit-remaining-hour, x-ratelimit-remaining-day¶

    -
  • -
-

Here are some interoperability issues:¶

-
    -
  • -

    X-RateLimit-Remaining references different values, depending on the implementation:¶

    -
      -
    • -

      seconds remaining to the window expiration¶

      -
    • -
    • -

      milliseconds remaining to the window expiration¶

      -
    • -
    • -

      seconds since UTC, in UNIX Timestamp [UNIX]¶

      -
    • -
    • -

      a datetime, either IMF-fixdate [HTTP] or [RFC3339]¶

      -
    • -
    -
  • -
  • -

    different headers, with the same semantic, are used by different implementers:¶

    -
      -
    • -

      X-RateLimit-Limit and X-Rate-Limit-Limit¶

      -
    • -
    • -

      X-RateLimit-Remaining and X-Rate-Limit-Remaining¶

      -
    • -
    • -

      X-RateLimit-Reset and X-Rate-Limit-Reset¶

      -
    • -
    -
  • -
-

The semantic of RateLimit depends on the windowing algorithm. -A sliding window policy for example, may result in having a remaining keyword value related to the ratio between the current and the maximum throughput. -e.g.¶

-
-
-RateLimit-Policy: sliding;l=12;w=1
-RateLimit: sliding;l=12;r=6;t=1          ; using 50% of throughput, that is 6 units/s
-
-
¶ -
-

If this is the case, the optimal solution is to achieve¶

-
-
-RateLimit-Policy: sliding;l=12;w=1
-RateLimit: sliding;l=12;r=1;t=1          ; using 100% of throughput, that is 12 units/s
-
¶ -
-

At this point you should stop increasing your request rate.¶

-
-
-
-
-

-Acknowledgements -

-

Thanks to Willi Schoenborn, Alejandro Martinez Ruiz, Alessandro Ranellucci, -Amos Jeffries, -Martin Thomson, -Erik Wilde and Mark Nottingham for being the initial contributors -of these specifications. -Kudos to the first community implementers: -Aapo Talvensaari, -Nathan Friedly -and Sanyam Dogra.¶

-

In addition to the people above, this document owes a lot to the extensive discussion in the HTTPAPI workgroup, including -Rich Salz, -Darrel Miller -and Julian Reschke.¶

-
-
-
-
-

-Changes -

-

This section is to be removed before publishing as an RFC.¶

-
-
-

-Since draft-ietf-httpapi-ratelimit-headers-07 -

-

This section is to be removed before publishing as an RFC.¶

-
    -
  • -

    Refactored both fields to lists of Items that identify policy and use parameters¶

    -
  • -
  • -

    Added quota unit parameter¶

    -
  • -
  • -

    Added partition key parameter¶

    -
  • -
-
-
-
-
-

-Since draft-ietf-httpapi-ratelimit-headers-03 -

-

This section is to be removed before publishing as an RFC.¶

-
    -
  • -

    Split policy informatiom in RateLimit-Policy #81¶

    -
  • -
-
-
-
-
-

-Since draft-ietf-httpapi-ratelimit-headers-02 -

-

This section is to be removed before publishing as an RFC.¶

-
    -
  • -

    Address throttling scope #83¶

    -
  • -
-
-
-
-
-

-Since draft-ietf-httpapi-ratelimit-headers-01 -

-

This section is to be removed before publishing as an RFC.¶

-
    -
  • -

    Update IANA considerations #60¶

    -
  • -
  • -

    Use Structured fields #58¶

    -
  • -
  • -

    Reorganize document #67¶

    -
  • -
-
-
-
-
-

-Since draft-ietf-httpapi-ratelimit-headers-00 -

-

This section is to be removed before publishing as an RFC.¶

-
    -
  • -

    Use I-D.httpbis-semantics, which includes referencing delay-seconds -instead of delta-seconds. #5¶

    -
  • -
-
-
-
-
-
-
-

-Authors' Addresses -

-
-
Roberto Polli
-
Team Digitale, Italian Government
-
Italy
- -
-
-
Alejandro Martinez Ruiz
-
Red Hat
- -
-
-
Darrel Miller
-
Microsoft
- -
-
-
- - - diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index 2fcf76d..2294126 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -147,7 +147,7 @@ The time window is a non-negative Integer value expressing an interval in second ## Quota Policy {#quota-policy} -A quota policy is maintained by a server to limit the activity (counted in [quota units](#quota-unit)) of a given [quota partition](#quota-partition) over a period of time (known as the [time window](#time-window)) to a specified amount known as the [quota](#quota). +A quota policy is maintained by a server to limit the activity (counted in [quota units](#quota-units)) of a given [quota partition](#quota-partition) over a period of time (known as the [time window](#time-window)) to a specified amount known as the [quota](#quota). Quota policies can be advertised by servers (see {{ratelimit-policy-field}}), but they are not required to be, and more than one quota policy can affect a given request from a client to a server. @@ -211,7 +211,7 @@ This field MAY convey the time window associated with the expiring-limit, as sho These examples show multiple policies being returned: ~~~ - RateLimit-Policy: permin;l=50;w=60,perhr;l=1000;w=3600,perday;l=5000;w=86400 + RateLimit-Policy: permin;l=50;w=60, perhr;l=1000;w=3600, perday;l=5000;w=86400 ~~~ The following example shows a policy with a partition key: @@ -240,7 +240,7 @@ The field is expressed as List of {{servicelimit-item}}. ## Service Limit Item {#servicelimit-item} -Each service limit item in identifies the quota policy associated with the request and +Each service limit item in identifies the quota policy associated with the request and The following parameters are defined in this specification: @@ -251,7 +251,7 @@ The following parameters are defined in this specification: : This OPTIONAL parameter value conveys the time window reset time for the identified policy ({{ratelimit-reset-parameter}}). pk: - : The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. + : The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. This field cannot appear in a trailer section. Other parameters are allowed and can be regarded as comments. @@ -262,7 +262,7 @@ Implementation- or service-specific parameters SHOULD be prefixed parameters wit The "r" parameter indicates the remaining quota units for the identified policy ({{ratelimit-remaining-parameter}}). -It is a non-negative Integer expressed in [quota units](#quota-unit). +It is a non-negative Integer expressed in [quota units](#quota-units). Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When remaining parameter value is low, it indicates that the server may soon throttle the client (see {{providing-ratelimit-fields}}). @@ -329,6 +329,7 @@ Servers are not required to return RateLimit header fields in every response, an Implementers concerned with response fields' size, might take into account their ratio with respect to the content length, or use header-compression HTTP features such as {{?HPACK=RFC7541}}. + # Client Behavior {#receiving-fields} The RateLimit header fields can be used by clients to determine whether the associated request respected the server's quota policy, and as an indication of whether subsequent requests will. However, the server might apply other criteria when servicing future requests, and so the quota policy may not completely reflect whether requests will succeed. @@ -613,7 +614,7 @@ RateLimit: default;r=0;t=48 {"still": "successful"} ~~~ -### Multiple policies in response {#use-with-multiple-policies} +### Multiple policies in response The server uses two different policies to limit the client's requests: @@ -922,7 +923,7 @@ RateLimit: quota;t=1 ### Use with multiple windows This is a standardized way of describing the policy -detailed in {{use-with-multiple-policies}}: +detailed in {{use-with-custom-fields}}: - 5000 daily quota units; - 1000 hourly quota units. @@ -972,7 +973,7 @@ RateLimit: day;r=100;t=36000 No. {{?RFC6585}} defines the `429` status code and we use it just as an example of a throttled request, that could instead use even `403` or whatever status code. - + 4. Why is the partition key necessary? Without a partition key, a server can only effectively only have one scope (aka partition), which is impractical for most services, or it needs to communicate the scopes out-of-band. diff --git a/draft-ietf-httpapi-ratelimit-headers.md~ b/draft-ietf-httpapi-ratelimit-headers.md~ deleted file mode 100644 index 2fcf76d..0000000 --- a/draft-ietf-httpapi-ratelimit-headers.md~ +++ /dev/null @@ -1,1169 +0,0 @@ ---- -title: RateLimit header fields for HTTP -abbrev: -docname: draft-ietf-httpapi-ratelimit-headers-latest -category: std - -ipr: trust200902 -area: Applications and Real-Time -workgroup: HTTPAPI -keyword: Internet-Draft - -stand_alone: yes -pi: [toc, tocindent, sortrefs, symrefs, strict, compact, comments, inline, docmapping] - -venue: - group: HTTPAPI - type: Working Group - home: https://datatracker.ietf.org/wg/httpapi/about/ - mail: httpapi@ietf.org - arch: https://mailarchive.ietf.org/arch/browse/httpapi/ - repo: https://github.com/ietf-wg-httpapi/ratelimit-headers - -author: - - - ins: R. Polli - name: Roberto Polli - org: Team Digitale, Italian Government - email: robipolli@gmail.com - country: Italy - - - ins: A. Martinez - name: Alejandro Martinez Ruiz - org: Red Hat - email: alex@flawedcode.org - - - ins: D. Miller - name: Darrel Miller - org: Microsoft - email: darrel@tavis.ca - -entity: - SELF: "RFC nnnn" - -normative: - IANA: RFC8126 - HTTP: RFC9110 - -informative: - PRIVACY: RFC6973 - UNIX: - title: The Single UNIX Specification, Version 2 - 6 Vol Set for UNIX 98 - author: - name: The Open Group - ins: The Open Group - date: 1997-02 ---- abstract - -This document defines the RateLimit-Policy and RateLimit HTTP header fields for servers to advertise their service policy limits and the current limits, thereby allowing clients to avoid being throttled. - ---- middle - -# Introduction - -Rate limiting of HTTP clients has become a widespread practice, especially for HTTP APIs. Typically, servers who do so limit the number of acceptable requests in a given time window (e.g. 10 requests per second). See {{rate-limiting}} for further information on the current usage of rate limiting in HTTP. - -Currently, there is no standard way for servers to communicate quotas so that clients can throttle their requests to prevent errors. This document defines a set of standard HTTP header fields to enable rate limiting: - -- RateLimit: to convey - the server's current limit of quota units available to the client in the policy time window, - the remaining quota units in the current window, - and the time remaining in the current window, specified in seconds, and -- RateLimit-Policy: the service policy limits. - -These fields enable establishing complex rate limiting policies, including using multiple and variable time windows and dynamic quotas, and implementing concurrency limits. - -The behavior of the RateLimit header field is compatible with the delay-seconds notation of Retry-After. - -## Goals {#goals} - -The goals of this document are: - - Interoperability: - : Standardize the names and semantics of rate-limit headers - to ease their enforcement and adoption; - - Resiliency: - : Improve resiliency of HTTP infrastructure by - providing clients with information useful - to throttle their requests and - prevent 4xx or 5xx responses; - - Documentation: - : Simplify API documentation by eliminating the need - to include detailed quota limits - and related fields in API documentation. - -The following features are out of the scope of this document: - - Authorization: - : RateLimit header fields are not meant to support - authorization or other kinds of access controls. - - Response status code: - : RateLimit header fields may be returned in both - successful (see {{Section 15.3 of HTTP}}) and non-successful responses. - This specification does not cover whether non Successful - responses count on quota usage, - nor does it mandates any correlation between the RateLimit values - and the returned status code. - - Throttling algorithm: - : This specification does not mandate a specific throttling algorithm. - The values published in the fields, including the window size, - can be statically or dynamically evaluated. - - Service Level Agreement: - : Conveyed quota hints do not imply any service guarantee. - Server is free to throttle respectful clients under certain circumstances. - -## Notational Conventions - -{::boilerplate bcp14} - -The term Origin is to be interpreted as described in Section 7 of {{!WEB-ORIGIN=RFC6454}}. - -This document uses the terms List, Item and Integer from {{Section 3 of !STRUCTURED-FIELDS=RFC8941}} to specify syntax and parsing, along with the concept of "bare item". - -# Terminology - -## Quota {#quota} - -A quota is an allocation of capacity to enable a server to limit client requests. That capacity is counted in quota units and may be reallocated at the end of a time window {{time-window}}. - -## Quota Unit {#quota-unit} - -A quota unit is the unit of measure used to count the activity of a client. - -## Quota Partition {#quota-partition} - -A quota partition is a division of a server's capacity across different clients, users and owned resources. - -## Time Window {#time-window} - -A time window indicates a period of time associated to the allocated quota. - -The time window is a non-negative Integer value expressing an interval in seconds, similar to the "delay-seconds" rule defined in {{Section 10.2.3 of HTTP}}. Sub-second precision is not supported. - -## Quota Policy {#quota-policy} - -A quota policy is maintained by a server to limit the activity (counted in [quota units](#quota-unit)) of a given [quota partition](#quota-partition) over a period of time (known as the [time window](#time-window)) to a specified amount known as the [quota](#quota). - -Quota policies can be advertised by servers (see {{ratelimit-policy-field}}), but they are not required to be, and more than one quota policy can affect a given request from a client to a server. - -## Service Limit {#service-limit} - -A service limit is the current limit of the amount of activity that a server will allow based on the remaining quota for a particular quota partition within the time-window, if defined. - -# RateLimit-Policy Field {#ratelimit-policy-field} - -The "RateLimit-Policy" response header field is a non-empty List of {{quotapolicy-item}}. Its value is informative. The values are expected to remain consistent over a the lifetime of a connection. It is this characteristic that differentiates it from the [RateLimit](#ratelimit-field) that contains values that may change on every request. - -~~~ - RateLimit-Policy: burst;q=100;w=60,daily;q=1000;w=86400 -~~~ - -## Quota Policy Item {#quotapolicy-item} -A quota policy Item contains information about a server's capacity allocation for a quota partition associated with the request. - -The following parameters are defined in this specification: - - q: - : The REQUIRED "q" parameter indicates the quota allocated. ({{ratelimitpolicy-quota}}) - - qu: - : The OPTIONAL "qu" parameter value conveys the quota units associated to the "q" parameter. The default quota unit is "request". ({{ratelimitpolicy-quotaunit}}) - - w: - : The OPTIONAL "w" parameter value conveys a time "window" ({{time-window}}). ({{ratelimitpolicy-window}}) - - pk: - : The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. {{ratelimitpolicy-partitionkey}} - -Other parameters are allowed and can be regarded as comments. - -Implementation- or service-specific parameters SHOULD be prefixed parameters with a vendor identifier, e.g. `acme-policy`, `acme-burst`. - -### Quota Parameter {#ratelimitpolicy-quota} - - The "q" parameter uses a non-negative integer value to indicate the quota allocated for client activity (counted in quota units) for a given quota partition ({{service-limit}}). - -### Quota Unit Parameter {#ratelimitpolicy-quotaunit} - -The "qu" parameter value conveys the quota units associated to the "q" parameter. - -### Window Parameter {#ratelimitpolicy-window} - -The "w" parameter value conveys a time "window" in seconds. ({{time-window}}). - -### Partition Key Parameter {#ratelimitpolicy-partitionkey} - -The "pk" parameter value conveys the partition key associated to the request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key. - -## RateLimit Policy Field Examples - -This field MAY convey the time window associated with the expiring-limit, as shown in this example: - -~~~ - RateLimit-Policy: default;l=100;w=10 -~~~ - -These examples show multiple policies being returned: - -~~~ - RateLimit-Policy: permin;l=50;w=60,perhr;l=1000;w=3600,perday;l=5000;w=86400 -~~~ - -The following example shows a policy with a partition key: - -~~~ - RateLimit-Policy: peruser;l=100;w=60;pk=user123 -~~~ - -The following example shows a policy with a partition key and a quota unit: - -~~~ - RateLimit-Policy: peruser;l=65535;w=10;pk=user123;qu=bytes -~~~ - -This field cannot appear in a trailer section. - -# RateLimit Field {#ratelimit-field} - -A server uses the "RateLimit" response header field to communicate the service limit for a quota policy for a particular partition key. - -The field is expressed as List of {{servicelimit-item}}. - -~~~ - RateLimit: default;r=50;t=30 -~~~ - -## Service Limit Item {#servicelimit-item} - -Each service limit item in identifies the quota policy associated with the request and - -The following parameters are defined in this specification: - - r: - : This parameter value conveys the remaining quota units for the identified policy ({{ratelimit-remaining-parameter}}). - - t: - : This OPTIONAL parameter value conveys the time window reset time for the identified policy ({{ratelimit-reset-parameter}}). - - pk: - : The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. - -This field cannot appear in a trailer section. Other parameters are allowed and can be regarded as comments. - -Implementation- or service-specific parameters SHOULD be prefixed parameters with a vendor identifier, e.g. `acme-policy`, `acme-burst`. - - -### Remaining Parameter {#ratelimit-remaining-parameter} - -The "r" parameter indicates the remaining quota units for the identified policy ({{ratelimit-remaining-parameter}}). - -It is a non-negative Integer expressed in [quota units](#quota-unit). -Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. -When remaining parameter value is low, it indicates that the server may soon throttle the client (see {{providing-ratelimit-fields}}). - -### Reset Parameter {#ratelimit-reset-parameter} - -The "t" parameter indicates the number of seconds until the quota associated with the quota policy resets. - -It is a non-negative Integer compatible with the delay-seconds rule, because: - -- it does not rely on clock synchronization and is resilient to clock adjustment - and clock skew between client and server (see {{Section 5.6.7 of HTTP}}); -- it mitigates the risk related to thundering herd when too many clients are serviced with the same timestamp. - -The client MUST NOT assume that all its service limit will be reset at the moment indicated by the reset keyword. The server MAY arbitrarily alter the reset parameter value between subsequent requests; for example, in case of resource saturation or to implement sliding window policies. - -### Partition Key Parameter {#ratelimit-partitionkey} - -The "pk" parameter value conveys the partition key associated to the request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key. - - -## RateLimit Field Examples - -This example shows a RateLimit field with a remaining quota of 50 units and a time window reset in 30 seconds: - -~~~ - RateLimit: default;r=50;t=30 -~~~ - -This example shows a remaining quota of 999 requests for a partition key that has no time window reset: - -~~~ - RateLimit: default;r=999;pk=trial-121323 -~~~ - -This example shows a 300MB remaining quota for an application in the next 60 seconds: - -~~~ - RateLimit: default;r=300000000;pk=App-999;t=60;qu=bytes -~~~ - - -# Server Behavior {#providing-ratelimit-fields} - -A server MAY return RateLimit header fields independently of the response status code. This includes on throttled responses. This document does not mandate any correlation between the RateLimit header field values and the returned status code. - -Servers should be careful when returning RateLimit header fields in redirection responses (i.e., responses with 3xx status codes) because a low remaining keyword value could prevent the client from issuing requests. For example, given the RateLimit header fields below, a client could decide to wait 10 seconds before following the "Location" header field (see {{Section 10.2.2 of HTTP}}), because the remaining keyword value is 0. - -~~~ http-message -HTTP/1.1 301 Moved Permanently -Location: /foo/123 -RateLimit: problemPolicy;r=0, t=10 - -~~~ - -If a response contains both the Retry-After and the RateLimit header fields, the reset keyword value SHOULD reference the same point in time as the Retry-After field value. - -A service using RateLimit header fields MUST NOT convey values exposing an unwanted volume of requests and SHOULD implement mechanisms to cap the ratio between the remaining and the reset keyword values (see {{sec-resource-exhaustion}}); this is especially important when a quota policy uses a large time window. - -Under certain conditions, a server MAY artificially lower RateLimit header field values between subsequent requests, e.g. to respond to Denial of Service attacks or in case of resource saturation. - -## Performance Considerations - -Servers are not required to return RateLimit header fields in every response, and clients need to take this into account. For example, an implementer concerned with performance might provide RateLimit header fields only when a given quota is close to exhaustion. - -Implementers concerned with response fields' size, might take into account their ratio with respect to the content length, or use header-compression HTTP features such as {{?HPACK=RFC7541}}. - -# Client Behavior {#receiving-fields} - -The RateLimit header fields can be used by clients to determine whether the associated request respected the server's quota policy, and as an indication of whether subsequent requests will. However, the server might apply other criteria when servicing future requests, and so the quota policy may not completely reflect whether requests will succeed. - -For example, a successful response with the following fields: - -~~~ - RateLimit: default;r=1;t=7 -~~~ - -does not guarantee that the next request will be successful. Servers' behavior may be subject to other conditions. - -A client is responsible for ensuring that RateLimit header field values returned -cause reasonable client behavior with respect to throughput and latency -(see {{sec-resource-exhaustion}} and {{sec-dos}}). - -A client receiving RateLimit header fields MUST NOT assume that future responses will contain the same RateLimit header fields, or any RateLimit header fields at all. - -Malformed RateLimit header fields MUST be ignored. - -A client SHOULD NOT exceed the quota units conveyed by the remaining keyword before the time window expressed in the reset keyword. - -The value of the reset keyword is generated at response time: a client aware of a significant network latency MAY behave accordingly and use other information (e.g. the "Date" response header field, or otherwise gathered metrics) to better estimate the reset keyword moment intended by the server. - -The details provided in the RateLimit-Policy header field are informative and MAY be ignored. - -If a response contains both the RateLimit and Retry-After fields, the Retry-After field MUST take precedence and the reset keyword MAY be ignored. - -This specification does not mandate a specific throttling behavior and implementers can adopt their preferred policies, including: - -- slowing down or pre-emptively back-off their request rate when - approaching quota limits; -- consuming all the quota according to the exposed limits and then wait. - -## Intermediaries {#intermediaries} - -This section documents the considerations advised in {{Section 16.3.2 of HTTP}}. - -An intermediary that is not part of the originating service infrastructure and is not aware of the quota policy semantic used by the Origin Server SHOULD NOT alter the RateLimit header fields' values in such a way as to communicate a more permissive quota policy; this includes removing the RateLimit header fields. - -An intermediary MAY alter the RateLimit header fields in such a way as to communicate a more restrictive quota policy when: - -- it is aware of the quota unit semantic used by the Origin Server; -- it implements this specification and enforces a quota policy which - is more restrictive than the one conveyed in the fields. - -An intermediary SHOULD forward a request even when presuming that it might not be serviced; the service returning the RateLimit header fields is the sole responsible of enforcing the communicated quota policy, and it is always free to service incoming requests. - -This specification does not mandate any behavior on intermediaries respect to retries, nor requires that intermediaries have any role in respecting quota policies. For example, it is legitimate for a proxy to retransmit a request without notifying the client, and thus consuming quota units. - -[Privacy considerations](#privacy) provide further guidance on intermediaries. - -## Caching - -{{?HTTP-CACHING=RFC9111}} defines how responses can be stored and reused for subsequent requests, -including those with RateLimit header fields. -Because the information in RateLimit header fields on a cached response may not be current, they SHOULD be ignored on responses that come from cache -(i.e., those with a positive current_age; see {{Section 4.2.3 of HTTP-CACHING}}). - -# Security Considerations - -## Throttling does not prevent clients from issuing requests {#sec-throttling-does-not-prevent} - -This specification does not prevent clients from making requests. -Servers should always implement mechanisms to prevent resource exhaustion. - -## Information disclosure {#sec-information-disclosure} - -Servers should not disclose to untrusted parties operational capacity information -that can be used to saturate its infrastructural resources. - -While this specification does not mandate whether non-successful responses consume quota, -if error responses (such as 401 (Unauthorized) and 403 (Forbidden)) count against quota, -a malicious client could probe the endpoint to get traffic information of another user. - -As intermediaries might retransmit requests and consume -quota units without prior knowledge of the user agent, -RateLimit header fields might reveal the existence of an intermediary -to the user agent. - -Where partition keys contain identifying information, either of the client application or the user, servers should be aware of the potential for impersonation and apply the appropriate security mechanisms. - -## Remaining quota units are not granted requests {#sec-remaining-not-granted} - -RateLimit header fields convey hints from the server -to the clients in order to help them avoid being throttled out. - -Clients MUST NOT consider the [quota units](#service-limit) returned in remaining keyword as a service level agreement. - -In case of resource saturation, the server MAY artificially lower the returned values -or not serve the request regardless of the advertised quotas. - -## Reliability of the reset keyword {#sec-reset-reliability} - -Consider that quota might not be restored after the moment referenced by the [reset keyword](#ratelimit-reset-parameter), -and the reset parameter value may not be constant. - -Subsequent requests might return a higher reset parameter value -to limit concurrency or implement dynamic or adaptive throttling policies. - -## Resource exhaustion {#sec-resource-exhaustion} - -When returning reset values, servers must be aware that -many throttled clients may come back at the very moment specified. - -This is true for Retry-After too. - -For example, if the quota resets every day at `18:00:00` -and your server returns the reset parameter accordingly - -~~~ - Date: Tue, 15 Nov 1994 18:00:00 GMT - RateLimit: daily;r=1;t=36400 -~~~ - -there's a high probability that all clients will show up at `18:00:00`. - -This could be mitigated by adding some jitter to the reset value. - -Resource exhaustion issues can be associated with quota policies using a -large time window, because a user agent by chance or on purpose -might consume most of its quota units in a significantly shorter interval. - -This behavior can be even triggered by the provided RateLimit header fields. -The following example describes a service -with an unconsumed quota policy of 10000 quota units per 1000 seconds. - -~~~ -RateLimit-Policy: somepolicy;l=10000;w=1000 -RateLimit: somepolicy;r=10000;t=10 -~~~ - -A client implementing a simple ratio between remaining keyword and reset keyword could infer an average throughput of 1000 quota units per second, while the limit keyword conveys a quota-policy with an average of 10 quota units per second. -If the service cannot handle such load, it should return either a lower remaining keyword value or an higher reset keyword value. -Moreover, complementing large time window quota policies with a short time window one mitigates those risks. - - -### Denial of Service {#sec-dos} - -RateLimit header fields may contain unexpected values by chance or on purpose. -For example, an excessively high remaining keyword value may be: - -- used by a malicious intermediary to trigger a Denial of Service attack - or consume client resources boosting its requests; -- passed by a misconfigured server; - -or a high reset keyword value could inhibit clients to contact the server (e.g. similarly to receiving "Retry-after: 1000000"). - -To mitigate this risk, clients can set thresholds that they consider reasonable in terms of quota units, time window, concurrent requests or throughput, and define a consistent behavior when the RateLimit exceed those thresholds. -For example this means capping the maximum number of request per second, or implementing retries when the reset keyword exceeds ten minutes. - -The considerations above are not limited to RateLimit header fields, but apply to all fields affecting how clients behave in subsequent requests (e.g. Retry-After). - - -# Privacy Considerations {#privacy} - -Clients that act upon a request to rate limit -are potentially re-identifiable (see {{Section 5.2.1 of PRIVACY}}) -because they react to information that might only be given to them. -Note that this might apply to other fields too (e.g. Retry-After). - -Since rate limiting is usually implemented in contexts where -clients are either identified or profiled -(e.g. assigning different quota units to different users), -this is rarely a concern. - -Privacy enhancing infrastructures using RateLimit header fields -can define specific techniques to mitigate the risks of re-identification. - -# IANA Considerations - -IANA is requested to update one registry and create one new registry. - -Please add the following entries to the -"Hypertext Transfer Protocol (HTTP) Field Name Registry" registry ({{HTTP}}): - -|---------------------|-----------|---------------| -| Field Name | Status | Specification | -|---------------------|-----------|---------------| -| RateLimit | permanent | {{ratelimit-field}} of {{&SELF}} | -| RateLimit-Policy | permanent | {{ratelimit-policy-field}} of {{&SELF}} | -|---------------------|-----------|---------------| - - ---- back - -# Rate-limiting and quotas {#rate-limiting} - -Servers use quota mechanisms to avoid systems overload, to ensure an equitable distribution of computational resources or to enforce other policies - e.g. monetization. - -A basic quota mechanism limits the number of acceptable requests in a given time window, e.g. 10 requests per second. - -When quota is exceeded, servers usually do not serve the request replying instead with a 4xx HTTP status code (e.g. 429 or 403) or adopt more aggressive policies like dropping connections. - -Quotas may be enforced on different basis (e.g. per user, per IP, per geographic area, ..) and at different levels. For example, an user may be allowed to issue: - -- 10 requests per second; -- limited to 60 requests per minute; -- limited to 1000 requests per hour. - -Moreover system metrics, statistics and heuristics can be used to implement more complex policies, -where the number of acceptable requests and the time window are computed dynamically. - -To help clients throttling their requests, -servers may expose the counters used to evaluate quota policies via HTTP header fields. - -Those response headers may be added by HTTP intermediaries such as API gateways and reverse proxies. - -On the web we can find many different rate-limit headers, -usually containing the number of allowed requests in a given time window, and when the window is reset. - -The common choice is to return three headers containing: - -- the maximum number of allowed requests in the time window; -- the number of remaining requests in the current window; -- the time remaining in the current window expressed in seconds or - as a timestamp; - -## Interoperability issues - -A major interoperability issue in throttling is the lack of standard headers, because: - -- each implementation associates different semantics to the - same header field names; -- header field names proliferates. - -User agents interfacing with different servers may thus need to process different headers, -or the very same application interface that sits behind different reverse proxies -may reply with different throttling headers. - -# Examples - -## Responses without defining policies - -Some servers may not expose the policy limits in the RateLimit-Policy header field. Clients can still use the RateLimit header field to throttle their requests. - -### Throttling information in responses - -The client exhausted its quota for the next 50 seconds. -The limit and time-window is communicated out-of-band. - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 200 Ok -Content-Type: application/json -RateLimit: default;r=0;t=50 - -{"hello": "world"} -~~~ - -Since the field values are not necessarily correlated with -the response status code, -a subsequent request is not required to fail. -The example below shows that the server decided to serve the request -even if remaining keyword value is 0. -Another server, or the same server under other load conditions, could have decided to throttle the request instead. - -Request: - -~~~ http-message -GET /items/456 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 200 Ok -Content-Type: application/json -RateLimit: default;r=0;t=48 - -{"still": "successful"} -~~~ - -### Multiple policies in response {#use-with-multiple-policies} - -The server uses two different policies to limit the client's requests: - -- 5000 daily quota units; -- 1000 hourly quota units. - -The client consumed 4900 quota units in the first 14 hours. - -Despite the next hourly limit of 1000 quota units, -the closest limit to reach is the daily one. - -The server then exposes the RateLimit header fields to -inform the client that: - -- it has only 100 quota units left in the daily quota and the window will reset in 10 hours; - -The server MAY choose to omit returning the hourly policy as it uses the same quota units as the daily policy and the daily policy is the one that is closest to being exhausted. - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 200 Ok -Content-Type: application/json -RateLimit: dayLimit;r=100;t=36000 - -{"hello": "world"} -~~~ - -### Use for limiting concurrency {#use-for-limiting-concurrency} - -RateLimit header fields may be used to limit concurrency, -advertising limits that are lower than the usual ones -in case of saturation, thus increasing availability. - -The server adopted a basic policy of 100 quota units per minute, -and in case of resource exhaustion adapts the returned values -reducing both limit and remaining keyword values. - -After 2 seconds the client consumed 40 quota units - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 200 Ok -Content-Type: application/json -RateLimit-Policy: basic;l=100;w=60 -RateLimit: basic;r=60;t=58 - -{"elapsed": 2, "issued": 40} -~~~ - -At the subsequent request - due to resource exhaustion - -the server advertises only `r=20`. - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 200 Ok -Content-Type: application/json -RateLimit-Policy: basic;l=100;w=60 -RateLimit: basic;r=20;t=56 - -{"elapsed": 4, "issued": 41} -~~~ - -### Use in throttled responses - -A client exhausted its quota and the server throttles it -sending Retry-After. - -In this example, the values of Retry-After and RateLimit header field reference the same moment, -but this is not a requirement. - -The 429 (Too Many Request) HTTP status code is just used as an example. - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 429 Too Many Requests -Content-Type: application/json -Date: Mon, 05 Aug 2019 09:27:00 GMT -Retry-After: Mon, 05 Aug 2019 09:27:05 GMT -RateLimit: default;r=0;t=5 - -{ -"title": "Too Many Requests", -"status": 429, -"detail": "You have exceeded your quota" -} -~~~ - -## Responses with defined policies - -### Throttling window specified via parameter - -The client has 99 quota units left for the next 50 seconds. -The time window is communicated by the `w` parameter, so we know the throughput is 100 quota units per minute. - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 200 Ok -Content-Type: application/json -RateLimit: fixedwindow;r=99;t=50 -RateLimit-Policy: fixedwindow;l=100;w=60 -{"hello": "world"} -~~~ - - -### Dynamic limits with parameterized windows - -The policy conveyed by the RateLimit header field states that -the server accepts 100 quota units per minute. - -To avoid resource exhaustion, the server artificially lowers -the actual limits returned in the throttling headers. - -The remaining keyword then advertises -only 9 quota units for the next 50 seconds to slow down the client. - -Note that the server could have lowered even the other -values in the RateLimit header field: this specification -does not mandate any relation between the field values -contained in subsequent responses. - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 200 Ok -Content-Type: application/json -RateLimit-Policy: dynamic;l=100;w=60 -RateLimit: dynamic;r=9;t=50 - - -{ - "status": 200, - "detail": "Just slow down without waiting." -} -~~~ - -### Dynamic limits for pushing back and slowing down - -Continuing the previous example, let's say the client waits 10 seconds and -performs a new request which, due to resource exhaustion, the server rejects -and pushes back, advertising `r=0` for the next 20 seconds. - -The server advertises a smaller window with a lower limit to slow -down the client for the rest of its original window after the 20 seconds elapse. - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 429 Too Many Requests -Content-Type: application/json -RateLimit-Policy: dynamic;l=15;w=20 -RateLimit: dynamic;r=0;t=20 - -{ - "status": 429, - "detail": "Wait 20 seconds, then slow down!" -} -~~~ - -## Dynamic limits for pushing back with Retry-After and slow down - -Alternatively, given the same context where the previous example starts, we -can convey the same information to the client via Retry-After, with -the advantage that the server can now specify the policy's nominal limit and -window that will apply after the reset, e.g. assuming the resource exhaustion -is likely to be gone by then, so the advertised policy does not need to be -adjusted, yet we managed to stop requests for a while and slow down the rest of -the current window. - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 429 Too Many Requests -Content-Type: application/json -Retry-After: 20 -RateLimit-Policy: dynamic;l=100;w=60 -RateLimit: dynamic;r=15;t=40 - -{ - "status": 429, - "detail": "Wait 20 seconds, then slow down!" -} -~~~ - -Note that in this last response the client is expected to honor -Retry-After and perform no requests for the specified amount of -time, whereas the previous example would not force the client to stop -requests before the reset time is elapsed, as it would still be free to -query again the server even if it is likely to have the request rejected. - -### Missing Remaining information - -The server does not expose remaining values -(for example, because the underlying counters are not available). -Instead, it resets the limit counter every second. - -It communicates to the client the limit of 10 quota units per second -always returning the limit and reset keywords. - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 200 Ok -Content-Type: application/json -RateLimit-Policy: quota;l=100;w=1 -RateLimit: quota;t=1 - -{"first": "request"} -~~~ - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 200 Ok -Content-Type: application/json -RateLimit-Policy: quota;l=10 -RateLimit: quota;t=1 - -{"second": "request"} -~~~ - -### Use with multiple windows - -This is a standardized way of describing the policy -detailed in {{use-with-multiple-policies}}: - -- 5000 daily quota units; -- 1000 hourly quota units. - -The client consumed 4900 quota units in the first 14 hours. - -Despite the next hourly limit of 1000 quota units, the closest limit -to reach is the daily one. - -The server then exposes the RateLimit header fields to inform the client that: - -- it has only 100 quota units left; -- the window will reset in 10 hours; -- the expiring-limit is 5000. - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 200 OK -Content-Type: application/json -RateLimit-Policy: hour;l=1000;w=3600, day;l=5000;w=86400 -RateLimit: day;r=100;t=36000 - -{"hello": "world"} -~~~ - -# FAQ -{:numbered="false" removeinrfc="true"} - -1. Why defining standard fields for throttling? - - To simplify enforcement of throttling policies and enable clients to constraint their requests to avoid being throttled. - -2. Can I use RateLimit header fields in throttled responses (eg with status code 429)? - - Yes, you can. - -3. Are those specs tied to RFC 6585? - - No. {{?RFC6585}} defines the `429` status code and we use it just as an example of a throttled request, - that could instead use even `403` or whatever status code. - -4. Why is the partition key necessary? - - Without a partition key, a server can only effectively only have one scope (aka partition), which is impractical for most services, or it needs to communicate the scopes out-of-band. - This prevents the development of generic connector code that can be used to prevent requests from being throttled. - Many APIs rely on API keys, user identity or client identity to allocate quota. - As soon as a single client processes requests for more than one partition, the client needs to know the corresponding partition key to properly track requests against allocated quota. - -5. Why using delay-seconds instead of a UNIX Timestamp? - Why not using subsecond precision? - - Using delay-seconds aligns with Retry-After, which is returned in similar contexts, - eg on 429 responses. - - Timestamps require a clock synchronization protocol - (see {{Section 5.6.7 of HTTP}}). - This may be problematic (e.g. clock adjustment, clock skew, failure of hardcoded clock synchronization servers, - IoT devices, ..). - Moreover timestamps may not be monotonically increasing due to clock adjustment. - See [Another NTP client failure story](https://community.ntppool.org/t/another-ntp-client-failure-story/1014/) - - We did not use subsecond precision because: - - - that is more subject to system clock correction - like the one implemented via the adjtimex() Linux system call; - - response-time latency may not make it worth. A brief discussion on the subject is - on the [httpwg ml](https://lists.w3.org/Archives/Public/ietf-http-wg/2019JulSep/0202.html) - - almost all rate-limit headers implementations do not use it. - -6. Shouldn't I limit concurrency instead of request rate? - - You can use this specification to limit concurrency - at the HTTP level (see {#use-for-limiting-concurrency}) - and help clients to shape their requests avoiding being throttled out. - - A problematic way to limit concurrency is connection dropping, - especially when connections are multiplexed (e.g. HTTP/2) - because this results in unserviced client requests, - which is something we want to avoid. - - A semantic way to limit concurrency is to return 503 + Retry-After - in case of resource saturation (e.g. thrashing, connection queues too long, - Service Level Objectives not meet, ..). - Saturation conditions can be either dynamic or static: all this is out of - the scope for the current document. - -7. Do a positive value of remaining paramter imply any service guarantee for my - future requests to be served? - - No. FAQ integrated in {{ratelimit-remaining-parameter}}. - -8. Is the quota-policy definition {{quota-policy}} too complex? - - You can always return the simplest form - -~~~ -RateLimit:default;r=50;t=60 -~~~ - - The policy key clearly connects the current usage status of a policy to the defined limits. - So for the following field: - -~~~ -RateLimit-Policy: sliding;l=100;w=60;burst=1000;comment="sliding window", fixed;l=5000;w=3600;burst=0;comment="fixed window" -RateLimit: sliding;r=50;t=44 -~~~ - - the value "sliding" identifies the policy being reported. - -9. Can intermediaries alter RateLimit header fields? - - Generally, they should not because it might result in unserviced requests. - There are reasonable use cases for intermediaries mangling RateLimit header fields though, - e.g. when they enforce stricter quota-policies, - or when they are an active component of the service. - In those case we will consider them as part of the originating infrastructure. - -10. Why the `w` parameter is just informative? - Could it be used by a client to determine the request rate? - - A non-informative `w` parameter might be fine in an environment - where clients and servers are tightly coupled. Conveying policies - with this detail on a large scale would be very complex and implementations - would be likely not interoperable. We thus decided to leave `w` as - an informational parameter and only rely on the limit, remaining and reset keywords - for defining the throttling - behavior. - -11. Can I use RateLimit fields in trailers? - Servers usually establish whether the request is in-quota before creating a response, so the RateLimit field values should be already available in that moment. - Supporting trailers has the only advantage that allows to provide more up-to-date information to the client in case of slow responses. - However, this complicates client implementations with respect to combining fields from headers and accounting for intermediaries that drop trailers. - Since there are no current implementations that use trailers, we decided to leave this as a future-work. - -# RateLimit header fields currently used on the web -{:numbered="false" removeinrfc="true"} - -Commonly used header field names are: - -- `X-RateLimit-Limit`, - `X-RateLimit-Remaining`, - `X-RateLimit-Reset`; - -There are variants too, where the window is specified -in the header field name, eg: - -- `x-ratelimit-limit-minute`, `x-ratelimit-limit-hour`, `x-ratelimit-limit-day` -- `x-ratelimit-remaining-minute`, `x-ratelimit-remaining-hour`, `x-ratelimit-remaining-day` - -Here are some interoperability issues: - -- `X-RateLimit-Remaining` references different values, depending on the implementation: - - * seconds remaining to the window expiration - * milliseconds remaining to the window expiration - * seconds since UTC, in UNIX Timestamp [UNIX] - * a datetime, either `IMF-fixdate` {{HTTP}} or {{?RFC3339}} - -- different headers, with the same semantic, are used by different implementers: - - * X-RateLimit-Limit and X-Rate-Limit-Limit - * X-RateLimit-Remaining and X-Rate-Limit-Remaining - * X-RateLimit-Reset and X-Rate-Limit-Reset - -The semantic of RateLimit depends on the windowing algorithm. -A sliding window policy for example, may result in having a remaining keyword value related to the ratio between the current and the maximum throughput. -e.g. - -~~~ -RateLimit-Policy: sliding;l=12;w=1 -RateLimit: sliding;l=12;r=6;t=1 ; using 50% of throughput, that is 6 units/s - -~~~ - -If this is the case, the optimal solution is to achieve - -~~~ -RateLimit-Policy: sliding;l=12;w=1 -RateLimit: sliding;l=12;r=1;t=1 ; using 100% of throughput, that is 12 units/s -~~~ - -At this point you should stop increasing your request rate. - -# Acknowledgements -{:numbered="false"} - -Thanks to Willi Schoenborn, Alejandro Martinez Ruiz, Alessandro Ranellucci, -Amos Jeffries, -Martin Thomson, -Erik Wilde and Mark Nottingham for being the initial contributors -of these specifications. -Kudos to the first community implementers: -Aapo Talvensaari, -Nathan Friedly -and Sanyam Dogra. - -In addition to the people above, this document owes a lot to the extensive discussion in the HTTPAPI workgroup, including -Rich Salz, -Darrel Miller -and Julian Reschke. - -# Changes -{:numbered="false" removeinrfc="true"} - -## Since draft-ietf-httpapi-ratelimit-headers-07 -{:numbered="false" removeinrfc="true"} - -* Refactored both fields to lists of Items that identify policy and use parameters -* Added quota unit parameter -* Added partition key parameter - - -## Since draft-ietf-httpapi-ratelimit-headers-03 -{:numbered="false" removeinrfc="true"} - -* Split policy informatiom in RateLimit-Policy #81 - - -## Since draft-ietf-httpapi-ratelimit-headers-02 -{:numbered="false" removeinrfc="true"} - -* Address throttling scope #83 - -## Since draft-ietf-httpapi-ratelimit-headers-01 -{:numbered="false" removeinrfc="true"} - -* Update IANA considerations #60 -* Use Structured fields #58 -* Reorganize document #67 - -## Since draft-ietf-httpapi-ratelimit-headers-00 -{:numbered="false" removeinrfc="true"} - -* Use I-D.httpbis-semantics, which includes referencing delay-seconds - instead of delta-seconds. #5 diff --git a/draft-ietf-httpapi-ratelimit-headers.txt b/draft-ietf-httpapi-ratelimit-headers.txt deleted file mode 100644 index 1deaa44..0000000 --- a/draft-ietf-httpapi-ratelimit-headers.txt +++ /dev/null @@ -1,1435 +0,0 @@ - - - - -HTTPAPI R. Polli -Internet-Draft Team Digitale, Italian Government -Intended status: Standards Track A. Martinez -Expires: 2 April 2025 Red Hat - D. Miller - Microsoft - 29 September 2024 - - - RateLimit header fields for HTTP - draft-ietf-httpapi-ratelimit-headers-latest - -Abstract - - This document defines the RateLimit-Policy and RateLimit HTTP header - fields for servers to advertise their service policy limits and the - current limits, thereby allowing clients to avoid being throttled. - -About This Document - - This note is to be removed before publishing as an RFC. - - Status information for this document may be found at - https://datatracker.ietf.org/doc/draft-ietf-httpapi-ratelimit- - headers/. - - Discussion of this document takes place on the HTTPAPI Working Group - mailing list (mailto:httpapi@ietf.org), which is archived at - https://mailarchive.ietf.org/arch/browse/httpapi/. Subscribe at - https://www.ietf.org/mailman/listinfo/httpapi/. Working Group - information can be found at https://datatracker.ietf.org/wg/httpapi/ - about/. - - Source for this draft and an issue tracker can be found at - https://github.com/ietf-wg-httpapi/ratelimit-headers. - -Status of This Memo - - This Internet-Draft is submitted in full conformance with the - provisions of BCP 78 and BCP 79. - - Internet-Drafts are working documents of the Internet Engineering - Task Force (IETF). Note that other groups may also distribute - working documents as Internet-Drafts. The list of current Internet- - Drafts is at https://datatracker.ietf.org/drafts/current/. - - Internet-Drafts are draft documents valid for a maximum of six months - and may be updated, replaced, or obsoleted by other documents at any - time. It is inappropriate to use Internet-Drafts as reference - material or to cite them other than as "work in progress." - - This Internet-Draft will expire on 2 April 2025. - -Copyright Notice - - Copyright (c) 2024 IETF Trust and the persons identified as the - document authors. All rights reserved. - - This document is subject to BCP 78 and the IETF Trust's Legal - Provisions Relating to IETF Documents (https://trustee.ietf.org/ - license-info) in effect on the date of publication of this document. - Please review these documents carefully, as they describe your rights - and restrictions with respect to this document. Code Components - extracted from this document must include Revised BSD License text as - described in Section 4.e of the Trust Legal Provisions and are - provided without warranty as described in the Revised BSD License. - -Table of Contents - - 1. Introduction - 1.1. Goals - 1.2. Notational Conventions - 2. Terminology - 2.1. Quota - 2.2. Quota Unit - 2.3. Quota Partition - 2.4. Time Window - 2.5. Quota Policy - 2.6. Service Limit - 3. RateLimit-Policy Field - 3.1. Quota Policy Item - 3.1.1. Quota Parameter - 3.1.2. Quota Unit Parameter - 3.1.3. Window Parameter - 3.1.4. Partition Key Parameter - 3.2. RateLimit Policy Field Examples - 4. RateLimit Field - 4.1. Service Limit Item - 4.1.1. Remaining Parameter - 4.1.2. Reset Parameter - 4.1.3. Partition Key Parameter - 4.2. RateLimit Field Examples - 5. Server Behavior - 5.1. Performance Considerations - 6. Client Behavior - 6.1. Intermediaries - 6.2. Caching - 7. Security Considerations - 7.1. Throttling does not prevent clients from issuing requests - 7.2. Information disclosure - 7.3. Remaining quota units are not granted requests - 7.4. Reliability of the reset keyword - 7.5. Resource exhaustion - 7.5.1. Denial of Service - 8. Privacy Considerations - 9. IANA Considerations - 10. References - 10.1. Normative References - 10.2. Informative References - Appendix A. Rate-limiting and quotas - A.1. Interoperability issues - Appendix B. Examples - B.1. Responses without defining policies - B.1.1. Throttling information in responses - B.1.2. Multiple policies in response - B.1.3. Use for limiting concurrency - B.1.4. Use in throttled responses - B.2. Responses with defined policies - B.2.1. Throttling window specified via parameter - B.2.2. Dynamic limits with parameterized windows - B.2.3. Dynamic limits for pushing back and slowing down - B.3. Dynamic limits for pushing back with Retry-After and slow - down - B.3.1. Missing Remaining information - B.3.2. Use with multiple windows - FAQ - RateLimit header fields currently used on the web - Acknowledgements - Changes - Since draft-ietf-httpapi-ratelimit-headers-07 - Since draft-ietf-httpapi-ratelimit-headers-03 - Since draft-ietf-httpapi-ratelimit-headers-02 - Since draft-ietf-httpapi-ratelimit-headers-01 - Since draft-ietf-httpapi-ratelimit-headers-00 - Authors' Addresses - -1. Introduction - - Rate limiting of HTTP clients has become a widespread practice, - especially for HTTP APIs. Typically, servers who do so limit the - number of acceptable requests in a given time window (e.g. 10 - requests per second). See Appendix A for further information on the - current usage of rate limiting in HTTP. - - Currently, there is no standard way for servers to communicate quotas - so that clients can throttle their requests to prevent errors. This - document defines a set of standard HTTP header fields to enable rate - limiting: - - * RateLimit: to convey the server's current limit of quota units - available to the client in the policy time window, the remaining - quota units in the current window, and the time remaining in the - current window, specified in seconds, and - - * RateLimit-Policy: the service policy limits. - - These fields enable establishing complex rate limiting policies, - including using multiple and variable time windows and dynamic - quotas, and implementing concurrency limits. - - The behavior of the RateLimit header field is compatible with the - delay-seconds notation of Retry-After. - -1.1. Goals - - The goals of this document are: - - Interoperability: Standardize the names and semantics of rate-limit - headers to ease their enforcement and adoption; - - Resiliency: Improve resiliency of HTTP infrastructure by providing - clients with information useful to throttle their requests and - prevent 4xx or 5xx responses; - - Documentation: Simplify API documentation by eliminating the need to - include detailed quota limits and related fields in API - documentation. - - The following features are out of the scope of this document: - - Authorization: RateLimit header fields are not meant to support - authorization or other kinds of access controls. - - Response status code: RateLimit header fields may be returned in - both successful (see Section 15.3 of [HTTP]) and non-successful - responses. This specification does not cover whether non - Successful responses count on quota usage, nor does it mandates - any correlation between the RateLimit values and the returned - status code. - - Throttling algorithm: This specification does not mandate a specific - throttling algorithm. The values published in the fields, - including the window size, can be statically or dynamically - evaluated. - - Service Level Agreement: Conveyed quota hints do not imply any - service guarantee. Server is free to throttle respectful clients - under certain circumstances. - -1.2. Notational Conventions - - The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", - "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and - "OPTIONAL" in this document are to be interpreted as described in - BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all - capitals, as shown here. - - The term Origin is to be interpreted as described in Section 7 of - [WEB-ORIGIN]. - - This document uses the terms List, Item and Integer from Section 3 of - [STRUCTURED-FIELDS] to specify syntax and parsing, along with the - concept of "bare item". - -2. Terminology - -2.1. Quota - - A quota is an allocation of capacity to enable a server to limit - client requests. That capacity is counted in quota units and may be - reallocated at the end of a time window Section 2.4. - -2.2. Quota Unit - - A quota unit is the unit of measure used to count the activity of a - client. - -2.3. Quota Partition - - A quota partition is a division of a server's capacity across - different clients, users and owned resources. - -2.4. Time Window - - A time window indicates a period of time associated to the allocated - quota. - - The time window is a non-negative Integer value expressing an - interval in seconds, similar to the "delay-seconds" rule defined in - Section 10.2.3 of [HTTP]. Sub-second precision is not supported. - -2.5. Quota Policy - - A quota policy is maintained by a server to limit the activity - (counted in quota units (Section 2.2)) of a given quota partition - (Section 2.3) over a period of time (known as the time window - (Section 2.4)) to a specified amount known as the Section 2.1. - - Quota policies can be advertised by servers (see Section 3), but they - are not required to be, and more than one quota policy can affect a - given request from a client to a server. - -2.6. Service Limit - - A service limit is the current limit of the amount of activity that a - server will allow based on the remaining quota for a particular quota - partition within the time-window, if defined. - -3. RateLimit-Policy Field - - The "RateLimit-Policy" response header field is a non-empty List of - Section 3.1. Its value is informative. The values are expected to - remain consistent over a the lifetime of a connection. It is this - characteristic that differentiates it from the RateLimit (Section 4) - that contains values that may change on every request. - - RateLimit-Policy: burst;q=100;w=60,daily;q=1000;w=86400 - -3.1. Quota Policy Item - - A quota policy Item contains information about a server's capacity - allocation for a quota partition associated with the request. - - The following parameters are defined in this specification: - - q: The REQUIRED "q" parameter indicates the quota allocated. - (Section 3.1.1) - - qu: The OPTIONAL "qu" parameter value conveys the quota units - associated to the "q" parameter. The default quota unit is - "request". (Section 3.1.2) - - w: The OPTIONAL "w" parameter value conveys a time "window" - (Section 2.4). (Section 3.1.3) - - pk: The OPTIONAL "pk" parameter value conveys the partition key - associated to the corresponding request. Section 3.1.4 - - Other parameters are allowed and can be regarded as comments. - - Implementation- or service-specific parameters SHOULD be prefixed - parameters with a vendor identifier, e.g. acme-policy, acme-burst. - -3.1.1. Quota Parameter - - The "q" parameter uses a non-negative integer value to indicate the - quota allocated for client activity (counted in quota units) for a - given quota partition (Section 2.6). - -3.1.2. Quota Unit Parameter - - The "qu" parameter value conveys the quota units associated to the - "q" parameter. - -3.1.3. Window Parameter - - The "w" parameter value conveys a time "window" in seconds. - (Section 2.4). - -3.1.4. Partition Key Parameter - - The "pk" parameter value conveys the partition key associated to the - request. Servers MAY use the partition key to divide server capacity - across different clients and resources. Quotas are allocated per - partition key. - -3.2. RateLimit Policy Field Examples - - This field MAY convey the time window associated with the expiring- - limit, as shown in this example: - - RateLimit-Policy: default;l=100;w=10 - - These examples show multiple policies being returned: - - RateLimit-Policy: permin;l=50;w=60,perhr;l=1000;w=3600,perday;l=5000;w=86400 - - The following example shows a policy with a partition key: - - RateLimit-Policy: peruser;l=100;w=60;pk=user123 - - The following example shows a policy with a partition key and a quota - unit: - - RateLimit-Policy: peruser;l=65535;w=10;pk=user123;qu=bytes - - This field cannot appear in a trailer section. - -4. RateLimit Field - - A server uses the "RateLimit" response header field to communicate - the service limit for a quota policy for a particular partition key. - - The field is expressed as List of Section 4.1. - - RateLimit: default;r=50;t=30 - -4.1. Service Limit Item - - Each service limit item in identifies the quota policy associated - with the request and - - The following parameters are defined in this specification: - - r: This parameter value conveys the remaining quota units for the - identified policy (Section 4.1.1). - - t: This OPTIONAL parameter value conveys the time window reset time - for the identified policy (Section 4.1.2). - - pk: The OPTIONAL "pk" parameter value conveys the partition key - associated to the corresponding request. - - This field cannot appear in a trailer section. Other parameters are - allowed and can be regarded as comments. - - Implementation- or service-specific parameters SHOULD be prefixed - parameters with a vendor identifier, e.g. acme-policy, acme-burst. - -4.1.1. Remaining Parameter - - The "r" parameter indicates the remaining quota units for the - identified policy (Section 4.1.1). - - It is a non-negative Integer expressed in quota units (Section 2.2). - Clients MUST NOT assume that a positive remaining value is a - guarantee that further requests will be served. When remaining - parameter value is low, it indicates that the server may soon - throttle the client (see Section 5). - -4.1.2. Reset Parameter - - The "t" parameter indicates the number of seconds until the quota - associated with the quota policy resets. - - It is a non-negative Integer compatible with the delay-seconds rule, - because: - - * it does not rely on clock synchronization and is resilient to - clock adjustment and clock skew between client and server (see - Section 5.6.7 of [HTTP]); - - * it mitigates the risk related to thundering herd when too many - clients are serviced with the same timestamp. - - The client MUST NOT assume that all its service limit will be reset - at the moment indicated by the reset keyword. The server MAY - arbitrarily alter the reset parameter value between subsequent - requests; for example, in case of resource saturation or to implement - sliding window policies. - -4.1.3. Partition Key Parameter - - The "pk" parameter value conveys the partition key associated to the - request. Servers MAY use the partition key to divide server capacity - across different clients and resources. Quotas are allocated per - partition key. - -4.2. RateLimit Field Examples - - This example shows a RateLimit field with a remaining quota of 50 - units and a time window reset in 30 seconds: - - RateLimit: default;r=50;t=30 - - This example shows a remaining quota of 999 requests for a partition - key that has no time window reset: - - RateLimit: default;r=999;pk=trial-121323 - - This example shows a 300MB remaining quota for an application in the - next 60 seconds: - - RateLimit: default;r=300000000;pk=App-999;t=60;qu=bytes - -5. Server Behavior - - A server MAY return RateLimit header fields independently of the - response status code. This includes on throttled responses. This - document does not mandate any correlation between the RateLimit - header field values and the returned status code. - - Servers should be careful when returning RateLimit header fields in - redirection responses (i.e., responses with 3xx status codes) because - a low remaining keyword value could prevent the client from issuing - requests. For example, given the RateLimit header fields below, a - client could decide to wait 10 seconds before following the - "Location" header field (see Section 10.2.2 of [HTTP]), because the - remaining keyword value is 0. - - HTTP/1.1 301 Moved Permanently - Location: /foo/123 - RateLimit: problemPolicy;r=0, t=10 - - If a response contains both the Retry-After and the RateLimit header - fields, the reset keyword value SHOULD reference the same point in - time as the Retry-After field value. - - A service using RateLimit header fields MUST NOT convey values - exposing an unwanted volume of requests and SHOULD implement - mechanisms to cap the ratio between the remaining and the reset - keyword values (see Section 7.5); this is especially important when a - quota policy uses a large time window. - - Under certain conditions, a server MAY artificially lower RateLimit - header field values between subsequent requests, e.g. to respond to - Denial of Service attacks or in case of resource saturation. - -5.1. Performance Considerations - - Servers are not required to return RateLimit header fields in every - response, and clients need to take this into account. For example, - an implementer concerned with performance might provide RateLimit - header fields only when a given quota is close to exhaustion. - - Implementers concerned with response fields' size, might take into - account their ratio with respect to the content length, or use - header-compression HTTP features such as [HPACK]. - -6. Client Behavior - - The RateLimit header fields can be used by clients to determine - whether the associated request respected the server's quota policy, - and as an indication of whether subsequent requests will. However, - the server might apply other criteria when servicing future requests, - and so the quota policy may not completely reflect whether requests - will succeed. - - For example, a successful response with the following fields: - - RateLimit: default;r=1;t=7 - - does not guarantee that the next request will be successful. - Servers' behavior may be subject to other conditions. - - A client is responsible for ensuring that RateLimit header field - values returned cause reasonable client behavior with respect to - throughput and latency (see Section 7.5 and Section 7.5.1). - - A client receiving RateLimit header fields MUST NOT assume that - future responses will contain the same RateLimit header fields, or - any RateLimit header fields at all. - - Malformed RateLimit header fields MUST be ignored. - - A client SHOULD NOT exceed the quota units conveyed by the remaining - keyword before the time window expressed in the reset keyword. - - The value of the reset keyword is generated at response time: a - client aware of a significant network latency MAY behave accordingly - and use other information (e.g. the "Date" response header field, or - otherwise gathered metrics) to better estimate the reset keyword - moment intended by the server. - - The details provided in the RateLimit-Policy header field are - informative and MAY be ignored. - - If a response contains both the RateLimit and Retry-After fields, the - Retry-After field MUST take precedence and the reset keyword MAY be - ignored. - - This specification does not mandate a specific throttling behavior - and implementers can adopt their preferred policies, including: - - * slowing down or pre-emptively back-off their request rate when - approaching quota limits; - - * consuming all the quota according to the exposed limits and then - wait. - -6.1. Intermediaries - - This section documents the considerations advised in Section 16.3.2 - of [HTTP]. - - An intermediary that is not part of the originating service - infrastructure and is not aware of the quota policy semantic used by - the Origin Server SHOULD NOT alter the RateLimit header fields' - values in such a way as to communicate a more permissive quota - policy; this includes removing the RateLimit header fields. - - An intermediary MAY alter the RateLimit header fields in such a way - as to communicate a more restrictive quota policy when: - - * it is aware of the quota unit semantic used by the Origin Server; - - * it implements this specification and enforces a quota policy which - is more restrictive than the one conveyed in the fields. - - An intermediary SHOULD forward a request even when presuming that it - might not be serviced; the service returning the RateLimit header - fields is the sole responsible of enforcing the communicated quota - policy, and it is always free to service incoming requests. - - This specification does not mandate any behavior on intermediaries - respect to retries, nor requires that intermediaries have any role in - respecting quota policies. For example, it is legitimate for a proxy - to retransmit a request without notifying the client, and thus - consuming quota units. - - Privacy considerations (Section 8) provide further guidance on - intermediaries. - -6.2. Caching - - [HTTP-CACHING] defines how responses can be stored and reused for - subsequent requests, including those with RateLimit header fields. - Because the information in RateLimit header fields on a cached - response may not be current, they SHOULD be ignored on responses that - come from cache (i.e., those with a positive current_age; see - Section 4.2.3 of [HTTP-CACHING]). - -7. Security Considerations - -7.1. Throttling does not prevent clients from issuing requests - - This specification does not prevent clients from making requests. - Servers should always implement mechanisms to prevent resource - exhaustion. - -7.2. Information disclosure - - Servers should not disclose to untrusted parties operational capacity - information that can be used to saturate its infrastructural - resources. - - While this specification does not mandate whether non-successful - responses consume quota, if error responses (such as 401 - (Unauthorized) and 403 (Forbidden)) count against quota, a malicious - client could probe the endpoint to get traffic information of another - user. - - As intermediaries might retransmit requests and consume quota units - without prior knowledge of the user agent, RateLimit header fields - might reveal the existence of an intermediary to the user agent. - - Where partition keys contain identifying information, either of the - client application or the user, servers should be aware of the - potential for impersonation and apply the appropriate security - mechanisms. - -7.3. Remaining quota units are not granted requests - - RateLimit header fields convey hints from the server to the clients - in order to help them avoid being throttled out. - - Clients MUST NOT consider the quota units (Section 2.6) returned in - remaining keyword as a service level agreement. - - In case of resource saturation, the server MAY artificially lower the - returned values or not serve the request regardless of the advertised - quotas. - -7.4. Reliability of the reset keyword - - Consider that quota might not be restored after the moment referenced - by the reset keyword (Section 4.1.2), and the reset parameter value - may not be constant. - - Subsequent requests might return a higher reset parameter value to - limit concurrency or implement dynamic or adaptive throttling - policies. - -7.5. Resource exhaustion - - When returning reset values, servers must be aware that many - throttled clients may come back at the very moment specified. - - This is true for Retry-After too. - - For example, if the quota resets every day at 18:00:00 and your - server returns the reset parameter accordingly - - Date: Tue, 15 Nov 1994 18:00:00 GMT - RateLimit: daily;r=1;t=36400 - - there's a high probability that all clients will show up at 18:00:00. - - This could be mitigated by adding some jitter to the reset value. - - Resource exhaustion issues can be associated with quota policies - using a large time window, because a user agent by chance or on - purpose might consume most of its quota units in a significantly - shorter interval. - - This behavior can be even triggered by the provided RateLimit header - fields. The following example describes a service with an unconsumed - quota policy of 10000 quota units per 1000 seconds. - - RateLimit-Policy: somepolicy;l=10000;w=1000 - RateLimit: somepolicy;r=10000;t=10 - - A client implementing a simple ratio between remaining keyword and - reset keyword could infer an average throughput of 1000 quota units - per second, while the limit keyword conveys a quota-policy with an - average of 10 quota units per second. If the service cannot handle - such load, it should return either a lower remaining keyword value or - an higher reset keyword value. Moreover, complementing large time - window quota policies with a short time window one mitigates those - risks. - -7.5.1. Denial of Service - - RateLimit header fields may contain unexpected values by chance or on - purpose. For example, an excessively high remaining keyword value - may be: - - * used by a malicious intermediary to trigger a Denial of Service - attack or consume client resources boosting its requests; - - * passed by a misconfigured server; - - or a high reset keyword value could inhibit clients to contact the - server (e.g. similarly to receiving "Retry-after: 1000000"). - - To mitigate this risk, clients can set thresholds that they consider - reasonable in terms of quota units, time window, concurrent requests - or throughput, and define a consistent behavior when the RateLimit - exceed those thresholds. For example this means capping the maximum - number of request per second, or implementing retries when the reset - keyword exceeds ten minutes. - - The considerations above are not limited to RateLimit header fields, - but apply to all fields affecting how clients behave in subsequent - requests (e.g. Retry-After). - -8. Privacy Considerations - - Clients that act upon a request to rate limit are potentially re- - identifiable (see Section 5.2.1 of [PRIVACY]) because they react to - information that might only be given to them. Note that this might - apply to other fields too (e.g. Retry-After). - - Since rate limiting is usually implemented in contexts where clients - are either identified or profiled (e.g. assigning different quota - units to different users), this is rarely a concern. - - Privacy enhancing infrastructures using RateLimit header fields can - define specific techniques to mitigate the risks of re- - identification. - -9. IANA Considerations - - IANA is requested to update one registry and create one new registry. - - Please add the following entries to the "Hypertext Transfer Protocol - (HTTP) Field Name Registry" registry ([HTTP]): - - +==================+===========+=======================+ - | Field Name | Status | Specification | - +==================+===========+=======================+ - | RateLimit | permanent | Section 4 of RFC nnnn | - +------------------+-----------+-----------------------+ - | RateLimit-Policy | permanent | Section 3 of RFC nnnn | - +------------------+-----------+-----------------------+ - - Table 1 - -10. References - -10.1. Normative References - - [HTTP] Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, - Ed., "HTTP Semantics", STD 97, RFC 9110, - DOI 10.17487/RFC9110, June 2022, - . - - [IANA] Cotton, M., Leiba, B., and T. Narten, "Guidelines for - Writing an IANA Considerations Section in RFCs", BCP 26, - RFC 8126, DOI 10.17487/RFC8126, June 2017, - . - - [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate - Requirement Levels", BCP 14, RFC 2119, - DOI 10.17487/RFC2119, March 1997, - . - - [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC - 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, - May 2017, . - - [STRUCTURED-FIELDS] - Nottingham, M. and P. Kamp, "Structured Field Values for - HTTP", RFC 8941, DOI 10.17487/RFC8941, February 2021, - . - - [WEB-ORIGIN] - Barth, A., "The Web Origin Concept", RFC 6454, - DOI 10.17487/RFC6454, December 2011, - . - -10.2. Informative References - - [HPACK] Peon, R. and H. Ruellan, "HPACK: Header Compression for - HTTP/2", RFC 7541, DOI 10.17487/RFC7541, May 2015, - . - - [HTTP-CACHING] - Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, - Ed., "HTTP Caching", STD 98, RFC 9111, - DOI 10.17487/RFC9111, June 2022, - . - - [PRIVACY] Cooper, A., Tschofenig, H., Aboba, B., Peterson, J., - Morris, J., Hansen, M., and R. Smith, "Privacy - Considerations for Internet Protocols", RFC 6973, - DOI 10.17487/RFC6973, July 2013, - . - - [RFC3339] Klyne, G. and C. Newman, "Date and Time on the Internet: - Timestamps", RFC 3339, DOI 10.17487/RFC3339, July 2002, - . - - [RFC6585] Nottingham, M. and R. Fielding, "Additional HTTP Status - Codes", RFC 6585, DOI 10.17487/RFC6585, April 2012, - . - - [UNIX] The Open Group, "The Single UNIX Specification, Version 2 - - 6 Vol Set for UNIX 98", February 1997. - -Appendix A. Rate-limiting and quotas - - Servers use quota mechanisms to avoid systems overload, to ensure an - equitable distribution of computational resources or to enforce other - policies - e.g. monetization. - - A basic quota mechanism limits the number of acceptable requests in a - given time window, e.g. 10 requests per second. - - When quota is exceeded, servers usually do not serve the request - replying instead with a 4xx HTTP status code (e.g. 429 or 403) or - adopt more aggressive policies like dropping connections. - - Quotas may be enforced on different basis (e.g. per user, per IP, per - geographic area, ..) and at different levels. For example, an user - may be allowed to issue: - - * 10 requests per second; - - * limited to 60 requests per minute; - - * limited to 1000 requests per hour. - - Moreover system metrics, statistics and heuristics can be used to - implement more complex policies, where the number of acceptable - requests and the time window are computed dynamically. - - To help clients throttling their requests, servers may expose the - counters used to evaluate quota policies via HTTP header fields. - - Those response headers may be added by HTTP intermediaries such as - API gateways and reverse proxies. - - On the web we can find many different rate-limit headers, usually - containing the number of allowed requests in a given time window, and - when the window is reset. - - The common choice is to return three headers containing: - - * the maximum number of allowed requests in the time window; - - * the number of remaining requests in the current window; - - * the time remaining in the current window expressed in seconds or - as a timestamp; - -A.1. Interoperability issues - - A major interoperability issue in throttling is the lack of standard - headers, because: - - * each implementation associates different semantics to the same - header field names; - - * header field names proliferates. - - User agents interfacing with different servers may thus need to - process different headers, or the very same application interface - that sits behind different reverse proxies may reply with different - throttling headers. - -Appendix B. Examples - -B.1. Responses without defining policies - - Some servers may not expose the policy limits in the RateLimit-Policy - header field. Clients can still use the RateLimit header field to - throttle their requests. - -B.1.1. Throttling information in responses - - The client exhausted its quota for the next 50 seconds. The limit - and time-window is communicated out-of-band. - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 200 Ok - Content-Type: application/json - RateLimit: default;r=0;t=50 - - {"hello": "world"} - - Since the field values are not necessarily correlated with the - response status code, a subsequent request is not required to fail. - The example below shows that the server decided to serve the request - even if remaining keyword value is 0. Another server, or the same - server under other load conditions, could have decided to throttle - the request instead. - - Request: - - GET /items/456 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 200 Ok - Content-Type: application/json - RateLimit: default;r=0;t=48 - - {"still": "successful"} - -B.1.2. Multiple policies in response - - The server uses two different policies to limit the client's - requests: - - * 5000 daily quota units; - - * 1000 hourly quota units. - - The client consumed 4900 quota units in the first 14 hours. - - Despite the next hourly limit of 1000 quota units, the closest limit - to reach is the daily one. - - The server then exposes the RateLimit header fields to inform the - client that: - - * it has only 100 quota units left in the daily quota and the window - will reset in 10 hours; - - The server MAY choose to omit returning the hourly policy as it uses - the same quota units as the daily policy and the daily policy is the - one that is closest to being exhausted. - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 200 Ok - Content-Type: application/json - RateLimit: dayLimit;r=100;t=36000 - - {"hello": "world"} - -B.1.3. Use for limiting concurrency - - RateLimit header fields may be used to limit concurrency, advertising - limits that are lower than the usual ones in case of saturation, thus - increasing availability. - - The server adopted a basic policy of 100 quota units per minute, and - in case of resource exhaustion adapts the returned values reducing - both limit and remaining keyword values. - - After 2 seconds the client consumed 40 quota units - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 200 Ok - Content-Type: application/json - RateLimit-Policy: basic;l=100;w=60 - RateLimit: basic;r=60;t=58 - - {"elapsed": 2, "issued": 40} - - At the subsequent request - due to resource exhaustion - the server - advertises only r=20. - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 200 Ok - Content-Type: application/json - RateLimit-Policy: basic;l=100;w=60 - RateLimit: basic;r=20;t=56 - - {"elapsed": 4, "issued": 41} - -B.1.4. Use in throttled responses - - A client exhausted its quota and the server throttles it sending - Retry-After. - - In this example, the values of Retry-After and RateLimit header field - reference the same moment, but this is not a requirement. - - The 429 (Too Many Request) HTTP status code is just used as an - example. - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 429 Too Many Requests - Content-Type: application/json - Date: Mon, 05 Aug 2019 09:27:00 GMT - Retry-After: Mon, 05 Aug 2019 09:27:05 GMT - RateLimit: default;r=0;t=5 - - { - "title": "Too Many Requests", - "status": 429, - "detail": "You have exceeded your quota" - } - -B.2. Responses with defined policies - -B.2.1. Throttling window specified via parameter - - The client has 99 quota units left for the next 50 seconds. The time - window is communicated by the w parameter, so we know the throughput - is 100 quota units per minute. - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 200 Ok - Content-Type: application/json - RateLimit: fixedwindow;r=99;t=50 - RateLimit-Policy: fixedwindow;l=100;w=60 - {"hello": "world"} - -B.2.2. Dynamic limits with parameterized windows - - The policy conveyed by the RateLimit header field states that the - server accepts 100 quota units per minute. - - To avoid resource exhaustion, the server artificially lowers the - actual limits returned in the throttling headers. - - The remaining keyword then advertises only 9 quota units for the next - 50 seconds to slow down the client. - - Note that the server could have lowered even the other values in the - RateLimit header field: this specification does not mandate any - relation between the field values contained in subsequent responses. - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 200 Ok - Content-Type: application/json - RateLimit-Policy: dynamic;l=100;w=60 - RateLimit: dynamic;r=9;t=50 - - - { - "status": 200, - "detail": "Just slow down without waiting." - } - -B.2.3. Dynamic limits for pushing back and slowing down - - Continuing the previous example, let's say the client waits 10 - seconds and performs a new request which, due to resource exhaustion, - the server rejects and pushes back, advertising r=0 for the next 20 - seconds. - - The server advertises a smaller window with a lower limit to slow - down the client for the rest of its original window after the 20 - seconds elapse. - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 429 Too Many Requests - Content-Type: application/json - RateLimit-Policy: dynamic;l=15;w=20 - RateLimit: dynamic;r=0;t=20 - - { - "status": 429, - "detail": "Wait 20 seconds, then slow down!" - } - -B.3. Dynamic limits for pushing back with Retry-After and slow down - - Alternatively, given the same context where the previous example - starts, we can convey the same information to the client via Retry- - After, with the advantage that the server can now specify the - policy's nominal limit and window that will apply after the reset, - e.g. assuming the resource exhaustion is likely to be gone by then, - so the advertised policy does not need to be adjusted, yet we managed - to stop requests for a while and slow down the rest of the current - window. - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 429 Too Many Requests - Content-Type: application/json - Retry-After: 20 - RateLimit-Policy: dynamic;l=100;w=60 - RateLimit: dynamic;r=15;t=40 - - { - "status": 429, - "detail": "Wait 20 seconds, then slow down!" - } - - Note that in this last response the client is expected to honor - Retry-After and perform no requests for the specified amount of time, - whereas the previous example would not force the client to stop - requests before the reset time is elapsed, as it would still be free - to query again the server even if it is likely to have the request - rejected. - -B.3.1. Missing Remaining information - - The server does not expose remaining values (for example, because the - underlying counters are not available). Instead, it resets the limit - counter every second. - - It communicates to the client the limit of 10 quota units per second - always returning the limit and reset keywords. - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 200 Ok - Content-Type: application/json - RateLimit-Policy: quota;l=100;w=1 - RateLimit: quota;t=1 - - {"first": "request"} - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 200 Ok - Content-Type: application/json - RateLimit-Policy: quota;l=10 - RateLimit: quota;t=1 - - {"second": "request"} - -B.3.2. Use with multiple windows - - This is a standardized way of describing the policy detailed in - Appendix B.1.2: - - * 5000 daily quota units; - - * 1000 hourly quota units. - - The client consumed 4900 quota units in the first 14 hours. - - Despite the next hourly limit of 1000 quota units, the closest limit - to reach is the daily one. - - The server then exposes the RateLimit header fields to inform the - client that: - - * it has only 100 quota units left; - - * the window will reset in 10 hours; - - * the expiring-limit is 5000. - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 200 OK - Content-Type: application/json - RateLimit-Policy: hour;l=1000;w=3600, day;l=5000;w=86400 - RateLimit: day;r=100;t=36000 - - {"hello": "world"} - -FAQ - - This section is to be removed before publishing as an RFC. - - 1. Why defining standard fields for throttling? - - To simplify enforcement of throttling policies and enable clients - to constraint their requests to avoid being throttled. - - 2. Can I use RateLimit header fields in throttled responses (eg with - status code 429)? - - Yes, you can. - - 3. Are those specs tied to RFC 6585? - - No. [RFC6585] defines the 429 status code and we use it just as - an example of a throttled request, that could instead use even - 403 or whatever status code. - - 4. Why is the partition key necessary? - - Without a partition key, a server can only effectively only have - one scope (aka partition), which is impractical for most - services, or it needs to communicate the scopes out-of-band. - This prevents the development of generic connector code that can - be used to prevent requests from being throttled. Many APIs rely - on API keys, user identity or client identity to allocate quota. - As soon as a single client processes requests for more than one - partition, the client needs to know the corresponding partition - key to properly track requests against allocated quota. - - 5. Why using delay-seconds instead of a UNIX Timestamp? Why not - using subsecond precision? - - Using delay-seconds aligns with Retry-After, which is returned in - similar contexts, eg on 429 responses. - - Timestamps require a clock synchronization protocol (see - Section 5.6.7 of [HTTP]). This may be problematic (e.g. clock - adjustment, clock skew, failure of hardcoded clock - synchronization servers, IoT devices, ..). Moreover timestamps - may not be monotonically increasing due to clock adjustment. See - Another NTP client failure story - (https://community.ntppool.org/t/another-ntp-client-failure- - story/1014/) - - We did not use subsecond precision because: - - * that is more subject to system clock correction like the one - implemented via the adjtimex() Linux system call; - - * response-time latency may not make it worth. A brief - discussion on the subject is on the httpwg ml - (https://lists.w3.org/Archives/Public/ietf-http- - wg/2019JulSep/0202.html) - - * almost all rate-limit headers implementations do not use it. - - 6. Shouldn't I limit concurrency instead of request rate? - - You can use this specification to limit concurrency at the HTTP - level (see {#use-for-limiting-concurrency}) and help clients to - shape their requests avoiding being throttled out. - - A problematic way to limit concurrency is connection dropping, - especially when connections are multiplexed (e.g. HTTP/2) - because this results in unserviced client requests, which is - something we want to avoid. - - A semantic way to limit concurrency is to return 503 + Retry- - After in case of resource saturation (e.g. thrashing, connection - queues too long, Service Level Objectives not meet, ..). - Saturation conditions can be either dynamic or static: all this - is out of the scope for the current document. - - 7. Do a positive value of remaining paramter imply any service - guarantee for my future requests to be served? - - No. FAQ integrated in Section 4.1.1. - - 8. Is the quota-policy definition Section 2.5 too complex? - - You can always return the simplest form - - RateLimit:default;r=50;t=60 - - The policy key clearly connects the current usage status of a policy - to the defined limits. So for the following field: - -RateLimit-Policy: sliding;l=100;w=60;burst=1000;comment="sliding window", fixed;l=5000;w=3600;burst=0;comment="fixed window" -RateLimit: sliding;r=50;t=44 - - the value "sliding" identifies the policy being reported. - - 1. Can intermediaries alter RateLimit header fields? - - Generally, they should not because it might result in unserviced - requests. There are reasonable use cases for intermediaries - mangling RateLimit header fields though, e.g. when they enforce - stricter quota-policies, or when they are an active component of - the service. In those case we will consider them as part of the - originating infrastructure. - - 2. Why the w parameter is just informative? Could it be used by a - client to determine the request rate? - - A non-informative w parameter might be fine in an environment - where clients and servers are tightly coupled. Conveying - policies with this detail on a large scale would be very complex - and implementations would be likely not interoperable. We thus - decided to leave w as an informational parameter and only rely on - the limit, remaining and reset keywords for defining the - throttling behavior. - - 3. Can I use RateLimit fields in trailers? Servers usually - establish whether the request is in-quota before creating a - response, so the RateLimit field values should be already - available in that moment. Supporting trailers has the only - advantage that allows to provide more up-to-date information to - the client in case of slow responses. However, this complicates - client implementations with respect to combining fields from - headers and accounting for intermediaries that drop trailers. - Since there are no current implementations that use trailers, we - decided to leave this as a future-work. - -RateLimit header fields currently used on the web - - This section is to be removed before publishing as an RFC. - - Commonly used header field names are: - - * X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset; - - There are variants too, where the window is specified in the header - field name, eg: - - * x-ratelimit-limit-minute, x-ratelimit-limit-hour, x-ratelimit- - limit-day - - * x-ratelimit-remaining-minute, x-ratelimit-remaining-hour, x- - ratelimit-remaining-day - - Here are some interoperability issues: - - * X-RateLimit-Remaining references different values, depending on - the implementation: - - - seconds remaining to the window expiration - - - milliseconds remaining to the window expiration - - - seconds since UTC, in UNIX Timestamp [UNIX] - - - a datetime, either IMF-fixdate [HTTP] or [RFC3339] - - * different headers, with the same semantic, are used by different - implementers: - - - X-RateLimit-Limit and X-Rate-Limit-Limit - - - X-RateLimit-Remaining and X-Rate-Limit-Remaining - - - X-RateLimit-Reset and X-Rate-Limit-Reset - - The semantic of RateLimit depends on the windowing algorithm. A - sliding window policy for example, may result in having a remaining - keyword value related to the ratio between the current and the - maximum throughput. e.g. - -RateLimit-Policy: sliding;l=12;w=1 -RateLimit: sliding;l=12;r=6;t=1 ; using 50% of throughput, that is 6 units/s - - If this is the case, the optimal solution is to achieve - -RateLimit-Policy: sliding;l=12;w=1 -RateLimit: sliding;l=12;r=1;t=1 ; using 100% of throughput, that is 12 units/s - - At this point you should stop increasing your request rate. - -Acknowledgements - - Thanks to Willi Schoenborn, Alejandro Martinez Ruiz, Alessandro - Ranellucci, Amos Jeffries, Martin Thomson, Erik Wilde and Mark - Nottingham for being the initial contributors of these - specifications. Kudos to the first community implementers: Aapo - Talvensaari, Nathan Friedly and Sanyam Dogra. - - In addition to the people above, this document owes a lot to the - extensive discussion in the HTTPAPI workgroup, including Rich Salz, - Darrel Miller and Julian Reschke. - -Changes - - This section is to be removed before publishing as an RFC. - -Since draft-ietf-httpapi-ratelimit-headers-07 - - This section is to be removed before publishing as an RFC. - - * Refactored both fields to lists of Items that identify policy and - use parameters - - * Added quota unit parameter - - * Added partition key parameter - -Since draft-ietf-httpapi-ratelimit-headers-03 - - This section is to be removed before publishing as an RFC. - - * Split policy informatiom in RateLimit-Policy #81 - -Since draft-ietf-httpapi-ratelimit-headers-02 - - This section is to be removed before publishing as an RFC. - - * Address throttling scope #83 - -Since draft-ietf-httpapi-ratelimit-headers-01 - - This section is to be removed before publishing as an RFC. - - * Update IANA considerations #60 - - * Use Structured fields #58 - - * Reorganize document #67 - -Since draft-ietf-httpapi-ratelimit-headers-00 - - This section is to be removed before publishing as an RFC. - - * Use I-D.httpbis-semantics, which includes referencing delay- - seconds instead of delta-seconds. #5 - -Authors' Addresses - - Roberto Polli - Team Digitale, Italian Government - Italy - Email: robipolli@gmail.com - - - Alejandro Martinez Ruiz - Red Hat - Email: alex@flawedcode.org - - - Darrel Miller - Microsoft - Email: darrel@tavis.ca From 10657fe1107f382abb4c47cb24657a36a5b8aa1f Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Sun, 29 Sep 2024 15:45:17 -0400 Subject: [PATCH 26/28] Revert "Added linting fixes" This reverts commit e29b364c985a4427c40b5ab5276cbb2403b9b217. --- .gitignore | 1 + draft-ietf-httpapi-ratelimit-headers.html | 2948 +++++++++++++++++++++ draft-ietf-httpapi-ratelimit-headers.md | 17 +- draft-ietf-httpapi-ratelimit-headers.md~ | 1169 ++++++++ draft-ietf-httpapi-ratelimit-headers.txt | 1435 ++++++++++ 5 files changed, 5561 insertions(+), 9 deletions(-) create mode 100644 .gitignore create mode 100644 draft-ietf-httpapi-ratelimit-headers.html create mode 100644 draft-ietf-httpapi-ratelimit-headers.md~ create mode 100644 draft-ietf-httpapi-ratelimit-headers.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7951405 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +lib \ No newline at end of file diff --git a/draft-ietf-httpapi-ratelimit-headers.html b/draft-ietf-httpapi-ratelimit-headers.html new file mode 100644 index 0000000..60ed7d9 --- /dev/null +++ b/draft-ietf-httpapi-ratelimit-headers.html @@ -0,0 +1,2948 @@ + + + + + + +RateLimit header fields for HTTP + + + + + + + + + + + + + + + + + + + + + + + + + +
Internet-DraftRateLimit header fields for HTTPSeptember 2024
Polli, et al.Expires 2 April 2025[Page]
+
+
+
+
Workgroup:
+
HTTPAPI
+
Internet-Draft:
+
draft-ietf-httpapi-ratelimit-headers-latest
+
Published:
+
+ +
+
Intended Status:
+
Standards Track
+
Expires:
+
+
Authors:
+
+
+
R. Polli
+
Team Digitale, Italian Government
+
+
+
A. Martinez
+
Red Hat
+
+
+
D. Miller
+
Microsoft
+
+
+
+
+

RateLimit header fields for HTTP

+
+

Abstract

+

This document defines the RateLimit-Policy and RateLimit HTTP header fields for servers to advertise their service policy limits and the current limits, thereby allowing clients to avoid being throttled.¶

+
+
+

+About This Document +

+

This note is to be removed before publishing as an RFC.¶

+

+ Status information for this document may be found at https://datatracker.ietf.org/doc/draft-ietf-httpapi-ratelimit-headers/.¶

+

+ Discussion of this document takes place on the + HTTPAPI Working Group mailing list (mailto:httpapi@ietf.org), + which is archived at https://mailarchive.ietf.org/arch/browse/httpapi/. + Subscribe at https://www.ietf.org/mailman/listinfo/httpapi/. + Working Group information can be found at https://datatracker.ietf.org/wg/httpapi/about/.¶

+

Source for this draft and an issue tracker can be found at + https://github.com/ietf-wg-httpapi/ratelimit-headers.¶

+
+
+
+

+Status of This Memo +

+

+ This Internet-Draft is submitted in full conformance with the + provisions of BCP 78 and BCP 79.¶

+

+ Internet-Drafts are working documents of the Internet Engineering Task + Force (IETF). Note that other groups may also distribute working + documents as Internet-Drafts. The list of current Internet-Drafts is + at https://datatracker.ietf.org/drafts/current/.¶

+

+ Internet-Drafts are draft documents valid for a maximum of six months + and may be updated, replaced, or obsoleted by other documents at any + time. It is inappropriate to use Internet-Drafts as reference + material or to cite them other than as "work in progress."¶

+

+ This Internet-Draft will expire on 2 April 2025.¶

+
+
+ +
+
+ â–²

+Table of Contents +

+ +
+
+
+
+

+1. Introduction +

+

Rate limiting of HTTP clients has become a widespread practice, especially for HTTP APIs. Typically, servers who do so limit the number of acceptable requests in a given time window (e.g. 10 requests per second). See Appendix A for further information on the current usage of rate limiting in HTTP.¶

+

Currently, there is no standard way for servers to communicate quotas so that clients can throttle their requests to prevent errors. This document defines a set of standard HTTP header fields to enable rate limiting:¶

+
    +
  • +

    RateLimit: to convey +the server's current limit of quota units available to the client in the policy time window, +the remaining quota units in the current window, +and the time remaining in the current window, specified in seconds, and¶

    +
  • +
  • +

    RateLimit-Policy: the service policy limits.¶

    +
  • +
+

These fields enable establishing complex rate limiting policies, including using multiple and variable time windows and dynamic quotas, and implementing concurrency limits.¶

+

The behavior of the RateLimit header field is compatible with the delay-seconds notation of Retry-After.¶

+
+
+

+1.1. Goals +

+

The goals of this document are:¶

+
+
Interoperability:
+
+

Standardize the names and semantics of rate-limit headers +to ease their enforcement and adoption;¶

+
+
+
Resiliency:
+
+

Improve resiliency of HTTP infrastructure by +providing clients with information useful +to throttle their requests and +prevent 4xx or 5xx responses;¶

+
+
+
Documentation:
+
+

Simplify API documentation by eliminating the need +to include detailed quota limits +and related fields in API documentation.¶

+
+
+
+

The following features are out of the scope of this document:¶

+
+
Authorization:
+
+

RateLimit header fields are not meant to support +authorization or other kinds of access controls.¶

+
+
+
Response status code:
+
+

RateLimit header fields may be returned in both +successful (see Section 15.3 of [HTTP]) and non-successful responses. +This specification does not cover whether non Successful +responses count on quota usage, +nor does it mandates any correlation between the RateLimit values +and the returned status code.¶

+
+
+
Throttling algorithm:
+
+

This specification does not mandate a specific throttling algorithm. +The values published in the fields, including the window size, +can be statically or dynamically evaluated.¶

+
+
+
Service Level Agreement:
+
+

Conveyed quota hints do not imply any service guarantee. +Server is free to throttle respectful clients under certain circumstances.¶

+
+
+
+
+
+
+
+

+1.2. Notational Conventions +

+

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL +NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", +"MAY", and "OPTIONAL" in this document are to be interpreted as +described in BCP 14 [RFC2119] [RFC8174] when, and only when, they +appear in all capitals, as shown here.¶

+

The term Origin is to be interpreted as described in Section 7 of [WEB-ORIGIN].¶

+

This document uses the terms List, Item and Integer from Section 3 of [STRUCTURED-FIELDS] to specify syntax and parsing, along with the concept of "bare item".¶

+
+
+
+
+
+
+

+2. Terminology +

+
+
+

+2.1. Quota +

+

A quota is an allocation of capacity to enable a server to limit client requests. That capacity is counted in quota units and may be reallocated at the end of a time window Section 2.4.¶

+
+
+
+
+

+2.2. Quota Unit +

+

A quota unit is the unit of measure used to count the activity of a client.¶

+
+
+
+
+

+2.3. Quota Partition +

+

A quota partition is a division of a server's capacity across different clients, users and owned resources.¶

+
+
+
+
+

+2.4. Time Window +

+

A time window indicates a period of time associated to the allocated quota.¶

+

The time window is a non-negative Integer value expressing an interval in seconds, similar to the "delay-seconds" rule defined in Section 10.2.3 of [HTTP]. Sub-second precision is not supported.¶

+
+
+
+
+

+2.5. Quota Policy +

+

A quota policy is maintained by a server to limit the activity (counted in quota units (Section 2.2)) of a given quota partition (Section 2.3) over a period of time (known as the time window (Section 2.4)) to a specified amount known as the Section 2.1.¶

+

Quota policies can be advertised by servers (see Section 3), but they are not required to be, and more than one quota policy can affect a given request from a client to a server.¶

+
+
+
+
+

+2.6. Service Limit +

+

A service limit is the current limit of the amount of activity that a server will allow based on the remaining quota for a particular quota partition within the time-window, if defined.¶

+
+
+
+
+
+
+

+3. RateLimit-Policy Field +

+

The "RateLimit-Policy" response header field is a non-empty List of Section 3.1. Its value is informative. The values are expected to remain consistent over a the lifetime of a connection. It is this characteristic that differentiates it from the RateLimit (Section 4) that contains values that may change on every request.¶

+
+
+   RateLimit-Policy: burst;q=100;w=60,daily;q=1000;w=86400
+
¶ +
+
+
+

+3.1. Quota Policy Item +

+

A quota policy Item contains information about a server's capacity allocation for a quota partition associated with the request.¶

+

The following parameters are defined in this specification:¶

+
+
q:
+
+

The REQUIRED "q" parameter indicates the quota allocated. (Section 3.1.1)¶

+
+
+
qu:
+
+

The OPTIONAL "qu" parameter value conveys the quota units associated to the "q" parameter. The default quota unit is "request". (Section 3.1.2)¶

+
+
+
w:
+
+

The OPTIONAL "w" parameter value conveys a time "window" (Section 2.4). (Section 3.1.3)¶

+
+
+
pk:
+
+

The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. Section 3.1.4¶

+
+
+
+

Other parameters are allowed and can be regarded as comments.¶

+

Implementation- or service-specific parameters SHOULD be prefixed parameters with a vendor identifier, e.g. acme-policy, acme-burst.¶

+
+
+

+3.1.1. Quota Parameter +

+

The "q" parameter uses a non-negative integer value to indicate the quota allocated for client activity (counted in quota units) for a given quota partition (Section 2.6).¶

+
+
+
+
+

+3.1.2. Quota Unit Parameter +

+

The "qu" parameter value conveys the quota units associated to the "q" parameter.¶

+
+
+
+
+

+3.1.3. Window Parameter +

+

The "w" parameter value conveys a time "window" in seconds. (Section 2.4).¶

+
+
+
+
+

+3.1.4. Partition Key Parameter +

+

The "pk" parameter value conveys the partition key associated to the request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key.¶

+
+
+
+
+
+
+

+3.2. RateLimit Policy Field Examples +

+

This field MAY convey the time window associated with the expiring-limit, as shown in this example:¶

+
+
+   RateLimit-Policy: default;l=100;w=10
+
¶ +
+

These examples show multiple policies being returned:¶

+
+
+   RateLimit-Policy: permin;l=50;w=60,perhr;l=1000;w=3600,perday;l=5000;w=86400
+
¶ +
+

The following example shows a policy with a partition key:¶

+
+
+   RateLimit-Policy: peruser;l=100;w=60;pk=user123
+
¶ +
+

The following example shows a policy with a partition key and a quota unit:¶

+
+
+   RateLimit-Policy: peruser;l=65535;w=10;pk=user123;qu=bytes
+
¶ +
+

This field cannot appear in a trailer section.¶

+
+
+
+
+
+
+

+4. RateLimit Field +

+

A server uses the "RateLimit" response header field to communicate the service limit for a quota policy for a particular partition key.¶

+

The field is expressed as List of Section 4.1.¶

+
+
+   RateLimit: default;r=50;t=30
+
¶ +
+
+
+

+4.1. Service Limit Item +

+

Each service limit item in identifies the quota policy associated with the request and¶

+

The following parameters are defined in this specification:¶

+
+
r:
+
+

This parameter value conveys the remaining quota units for the identified policy (Section 4.1.1).¶

+
+
+
t:
+
+

This OPTIONAL parameter value conveys the time window reset time for the identified policy (Section 4.1.2).¶

+
+
+
pk:
+
+

The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request.¶

+
+
+
+

This field cannot appear in a trailer section. Other parameters are allowed and can be regarded as comments.¶

+

Implementation- or service-specific parameters SHOULD be prefixed parameters with a vendor identifier, e.g. acme-policy, acme-burst.¶

+
+
+

+4.1.1. Remaining Parameter +

+

The "r" parameter indicates the remaining quota units for the identified policy (Section 4.1.1).¶

+

It is a non-negative Integer expressed in quota units (Section 2.2). +Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. +When remaining parameter value is low, it indicates that the server may soon throttle the client (see Section 5).¶

+
+
+
+
+

+4.1.2. Reset Parameter +

+

The "t" parameter indicates the number of seconds until the quota associated with the quota policy resets.¶

+

It is a non-negative Integer compatible with the delay-seconds rule, because:¶

+
    +
  • +

    it does not rely on clock synchronization and is resilient to clock adjustment +and clock skew between client and server (see Section 5.6.7 of [HTTP]);¶

    +
  • +
  • +

    it mitigates the risk related to thundering herd when too many clients are serviced with the same timestamp.¶

    +
  • +
+

The client MUST NOT assume that all its service limit will be reset at the moment indicated by the reset keyword. The server MAY arbitrarily alter the reset parameter value between subsequent requests; for example, in case of resource saturation or to implement sliding window policies.¶

+
+
+
+
+

+4.1.3. Partition Key Parameter +

+

The "pk" parameter value conveys the partition key associated to the request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key.¶

+
+
+
+
+
+
+

+4.2. RateLimit Field Examples +

+

This example shows a RateLimit field with a remaining quota of 50 units and a time window reset in 30 seconds:¶

+
+
+   RateLimit: default;r=50;t=30
+
¶ +
+

This example shows a remaining quota of 999 requests for a partition key that has no time window reset:¶

+
+
+   RateLimit: default;r=999;pk=trial-121323
+
¶ +
+

This example shows a 300MB remaining quota for an application in the next 60 seconds:¶

+
+
+   RateLimit: default;r=300000000;pk=App-999;t=60;qu=bytes
+
¶ +
+
+
+
+
+
+
+

+5. Server Behavior +

+

A server MAY return RateLimit header fields independently of the response status code. This includes on throttled responses. This document does not mandate any correlation between the RateLimit header field values and the returned status code.¶

+

Servers should be careful when returning RateLimit header fields in redirection responses (i.e., responses with 3xx status codes) because a low remaining keyword value could prevent the client from issuing requests. For example, given the RateLimit header fields below, a client could decide to wait 10 seconds before following the "Location" header field (see Section 10.2.2 of [HTTP]), because the remaining keyword value is 0.¶

+
+
+HTTP/1.1 301 Moved Permanently
+Location: /foo/123
+RateLimit: problemPolicy;r=0, t=10
+
+
¶ +
+

If a response contains both the Retry-After and the RateLimit header fields, the reset keyword value SHOULD reference the same point in time as the Retry-After field value.¶

+

A service using RateLimit header fields MUST NOT convey values exposing an unwanted volume of requests and SHOULD implement mechanisms to cap the ratio between the remaining and the reset keyword values (see Section 7.5); this is especially important when a quota policy uses a large time window.¶

+

Under certain conditions, a server MAY artificially lower RateLimit header field values between subsequent requests, e.g. to respond to Denial of Service attacks or in case of resource saturation.¶

+
+
+

+5.1. Performance Considerations +

+

Servers are not required to return RateLimit header fields in every response, and clients need to take this into account. For example, an implementer concerned with performance might provide RateLimit header fields only when a given quota is close to exhaustion.¶

+

Implementers concerned with response fields' size, might take into account their ratio with respect to the content length, or use header-compression HTTP features such as [HPACK].¶

+
+
+
+
+
+
+

+6. Client Behavior +

+

The RateLimit header fields can be used by clients to determine whether the associated request respected the server's quota policy, and as an indication of whether subsequent requests will. However, the server might apply other criteria when servicing future requests, and so the quota policy may not completely reflect whether requests will succeed.¶

+

For example, a successful response with the following fields:¶

+
+
+   RateLimit: default;r=1;t=7
+
¶ +
+

does not guarantee that the next request will be successful. Servers' behavior may be subject to other conditions.¶

+

A client is responsible for ensuring that RateLimit header field values returned +cause reasonable client behavior with respect to throughput and latency +(see Section 7.5 and Section 7.5.1).¶

+

A client receiving RateLimit header fields MUST NOT assume that future responses will contain the same RateLimit header fields, or any RateLimit header fields at all.¶

+

Malformed RateLimit header fields MUST be ignored.¶

+

A client SHOULD NOT exceed the quota units conveyed by the remaining keyword before the time window expressed in the reset keyword.¶

+

The value of the reset keyword is generated at response time: a client aware of a significant network latency MAY behave accordingly and use other information (e.g. the "Date" response header field, or otherwise gathered metrics) to better estimate the reset keyword moment intended by the server.¶

+

The details provided in the RateLimit-Policy header field are informative and MAY be ignored.¶

+

If a response contains both the RateLimit and Retry-After fields, the Retry-After field MUST take precedence and the reset keyword MAY be ignored.¶

+

This specification does not mandate a specific throttling behavior and implementers can adopt their preferred policies, including:¶

+
    +
  • +

    slowing down or pre-emptively back-off their request rate when +approaching quota limits;¶

    +
  • +
  • +

    consuming all the quota according to the exposed limits and then wait.¶

    +
  • +
+
+
+

+6.1. Intermediaries +

+

This section documents the considerations advised in Section 16.3.2 of [HTTP].¶

+

An intermediary that is not part of the originating service infrastructure and is not aware of the quota policy semantic used by the Origin Server SHOULD NOT alter the RateLimit header fields' values in such a way as to communicate a more permissive quota policy; this includes removing the RateLimit header fields.¶

+

An intermediary MAY alter the RateLimit header fields in such a way as to communicate a more restrictive quota policy when:¶

+
    +
  • +

    it is aware of the quota unit semantic used by the Origin Server;¶

    +
  • +
  • +

    it implements this specification and enforces a quota policy which +is more restrictive than the one conveyed in the fields.¶

    +
  • +
+

An intermediary SHOULD forward a request even when presuming that it might not be serviced; the service returning the RateLimit header fields is the sole responsible of enforcing the communicated quota policy, and it is always free to service incoming requests.¶

+

This specification does not mandate any behavior on intermediaries respect to retries, nor requires that intermediaries have any role in respecting quota policies. For example, it is legitimate for a proxy to retransmit a request without notifying the client, and thus consuming quota units.¶

+

Privacy considerations (Section 8) provide further guidance on intermediaries.¶

+
+
+
+
+

+6.2. Caching +

+

[HTTP-CACHING] defines how responses can be stored and reused for subsequent requests, +including those with RateLimit header fields. +Because the information in RateLimit header fields on a cached response may not be current, they SHOULD be ignored on responses that come from cache +(i.e., those with a positive current_age; see Section 4.2.3 of [HTTP-CACHING]).¶

+
+
+
+
+
+
+

+7. Security Considerations +

+
+
+

+7.1. Throttling does not prevent clients from issuing requests +

+

This specification does not prevent clients from making requests. +Servers should always implement mechanisms to prevent resource exhaustion.¶

+
+
+
+
+

+7.2. Information disclosure +

+

Servers should not disclose to untrusted parties operational capacity information +that can be used to saturate its infrastructural resources.¶

+

While this specification does not mandate whether non-successful responses consume quota, +if error responses (such as 401 (Unauthorized) and 403 (Forbidden)) count against quota, +a malicious client could probe the endpoint to get traffic information of another user.¶

+

As intermediaries might retransmit requests and consume +quota units without prior knowledge of the user agent, +RateLimit header fields might reveal the existence of an intermediary +to the user agent.¶

+

Where partition keys contain identifying information, either of the client application or the user, servers should be aware of the potential for impersonation and apply the appropriate security mechanisms.¶

+
+
+
+
+

+7.3. Remaining quota units are not granted requests +

+

RateLimit header fields convey hints from the server +to the clients in order to help them avoid being throttled out.¶

+

Clients MUST NOT consider the quota units (Section 2.6) returned in remaining keyword as a service level agreement.¶

+

In case of resource saturation, the server MAY artificially lower the returned values +or not serve the request regardless of the advertised quotas.¶

+
+
+
+
+

+7.4. Reliability of the reset keyword +

+

Consider that quota might not be restored after the moment referenced by the reset keyword (Section 4.1.2), +and the reset parameter value may not be constant.¶

+

Subsequent requests might return a higher reset parameter value +to limit concurrency or implement dynamic or adaptive throttling policies.¶

+
+
+
+
+

+7.5. Resource exhaustion +

+

When returning reset values, servers must be aware that +many throttled clients may come back at the very moment specified.¶

+

This is true for Retry-After too.¶

+

For example, if the quota resets every day at 18:00:00 +and your server returns the reset parameter accordingly¶

+
+
+   Date: Tue, 15 Nov 1994 18:00:00 GMT
+   RateLimit: daily;r=1;t=36400
+
¶ +
+

there's a high probability that all clients will show up at 18:00:00.¶

+

This could be mitigated by adding some jitter to the reset value.¶

+

Resource exhaustion issues can be associated with quota policies using a +large time window, because a user agent by chance or on purpose +might consume most of its quota units in a significantly shorter interval.¶

+

This behavior can be even triggered by the provided RateLimit header fields. +The following example describes a service +with an unconsumed quota policy of 10000 quota units per 1000 seconds.¶

+
+
+RateLimit-Policy: somepolicy;l=10000;w=1000
+RateLimit: somepolicy;r=10000;t=10
+
¶ +
+

A client implementing a simple ratio between remaining keyword and reset keyword could infer an average throughput of 1000 quota units per second, while the limit keyword conveys a quota-policy with an average of 10 quota units per second. +If the service cannot handle such load, it should return either a lower remaining keyword value or an higher reset keyword value. +Moreover, complementing large time window quota policies with a short time window one mitigates those risks.¶

+
+
+

+7.5.1. Denial of Service +

+

RateLimit header fields may contain unexpected values by chance or on purpose. +For example, an excessively high remaining keyword value may be:¶

+
    +
  • +

    used by a malicious intermediary to trigger a Denial of Service attack +or consume client resources boosting its requests;¶

    +
  • +
  • +

    passed by a misconfigured server;¶

    +
  • +
+

or a high reset keyword value could inhibit clients to contact the server (e.g. similarly to receiving "Retry-after: 1000000").¶

+

To mitigate this risk, clients can set thresholds that they consider reasonable in terms of quota units, time window, concurrent requests or throughput, and define a consistent behavior when the RateLimit exceed those thresholds. +For example this means capping the maximum number of request per second, or implementing retries when the reset keyword exceeds ten minutes.¶

+

The considerations above are not limited to RateLimit header fields, but apply to all fields affecting how clients behave in subsequent requests (e.g. Retry-After).¶

+
+
+
+
+
+
+
+
+

+8. Privacy Considerations +

+

Clients that act upon a request to rate limit +are potentially re-identifiable (see Section 5.2.1 of [PRIVACY]) +because they react to information that might only be given to them. +Note that this might apply to other fields too (e.g. Retry-After).¶

+

Since rate limiting is usually implemented in contexts where +clients are either identified or profiled +(e.g. assigning different quota units to different users), +this is rarely a concern.¶

+

Privacy enhancing infrastructures using RateLimit header fields +can define specific techniques to mitigate the risks of re-identification.¶

+
+
+
+
+

+9. IANA Considerations +

+

IANA is requested to update one registry and create one new registry.¶

+

Please add the following entries to the +"Hypertext Transfer Protocol (HTTP) Field Name Registry" registry ([HTTP]):¶

+ + + + + + + + + + + + + + + + + + + + + +
Table 1
Field NameStatusSpecification
RateLimitpermanent + Section 4 of RFC nnnn
RateLimit-Policypermanent + Section 3 of RFC nnnn
+
+
+
+

+10. References +

+
+
+

+10.1. Normative References +

+
+
[HTTP]
+
+Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, Ed., "HTTP Semantics", STD 97, RFC 9110, DOI 10.17487/RFC9110, , <https://www.rfc-editor.org/rfc/rfc9110>.
+
+
[IANA]
+
+Cotton, M., Leiba, B., and T. Narten, "Guidelines for Writing an IANA Considerations Section in RFCs", BCP 26, RFC 8126, DOI 10.17487/RFC8126, , <https://www.rfc-editor.org/rfc/rfc8126>.
+
+
[RFC2119]
+
+Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, , <https://www.rfc-editor.org/rfc/rfc2119>.
+
+
[RFC8174]
+
+Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, , <https://www.rfc-editor.org/rfc/rfc8174>.
+
+
[STRUCTURED-FIELDS]
+
+Nottingham, M. and P. Kamp, "Structured Field Values for HTTP", RFC 8941, DOI 10.17487/RFC8941, , <https://www.rfc-editor.org/rfc/rfc8941>.
+
+
[WEB-ORIGIN]
+
+Barth, A., "The Web Origin Concept", RFC 6454, DOI 10.17487/RFC6454, , <https://www.rfc-editor.org/rfc/rfc6454>.
+
+
+
+
+
+
+

+10.2. Informative References +

+
+
[HPACK]
+
+Peon, R. and H. Ruellan, "HPACK: Header Compression for HTTP/2", RFC 7541, DOI 10.17487/RFC7541, , <https://www.rfc-editor.org/rfc/rfc7541>.
+
+
[HTTP-CACHING]
+
+Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, Ed., "HTTP Caching", STD 98, RFC 9111, DOI 10.17487/RFC9111, , <https://www.rfc-editor.org/rfc/rfc9111>.
+
+
[PRIVACY]
+
+Cooper, A., Tschofenig, H., Aboba, B., Peterson, J., Morris, J., Hansen, M., and R. Smith, "Privacy Considerations for Internet Protocols", RFC 6973, DOI 10.17487/RFC6973, , <https://www.rfc-editor.org/rfc/rfc6973>.
+
+
[RFC3339]
+
+Klyne, G. and C. Newman, "Date and Time on the Internet: Timestamps", RFC 3339, DOI 10.17487/RFC3339, , <https://www.rfc-editor.org/rfc/rfc3339>.
+
+
[RFC6585]
+
+Nottingham, M. and R. Fielding, "Additional HTTP Status Codes", RFC 6585, DOI 10.17487/RFC6585, , <https://www.rfc-editor.org/rfc/rfc6585>.
+
+
[UNIX]
+
+The Open Group, "The Single UNIX Specification, Version 2 - 6 Vol Set for UNIX 98", .
+
+
+
+
+
+
+
+

+Appendix A. Rate-limiting and quotas +

+

Servers use quota mechanisms to avoid systems overload, to ensure an equitable distribution of computational resources or to enforce other policies - e.g. monetization.¶

+

A basic quota mechanism limits the number of acceptable requests in a given time window, e.g. 10 requests per second.¶

+

When quota is exceeded, servers usually do not serve the request replying instead with a 4xx HTTP status code (e.g. 429 or 403) or adopt more aggressive policies like dropping connections.¶

+

Quotas may be enforced on different basis (e.g. per user, per IP, per geographic area, ..) and at different levels. For example, an user may be allowed to issue:¶

+
    +
  • +

    10 requests per second;¶

    +
  • +
  • +

    limited to 60 requests per minute;¶

    +
  • +
  • +

    limited to 1000 requests per hour.¶

    +
  • +
+

Moreover system metrics, statistics and heuristics can be used to implement more complex policies, +where the number of acceptable requests and the time window are computed dynamically.¶

+

To help clients throttling their requests, +servers may expose the counters used to evaluate quota policies via HTTP header fields.¶

+

Those response headers may be added by HTTP intermediaries such as API gateways and reverse proxies.¶

+

On the web we can find many different rate-limit headers, +usually containing the number of allowed requests in a given time window, and when the window is reset.¶

+

The common choice is to return three headers containing:¶

+
    +
  • +

    the maximum number of allowed requests in the time window;¶

    +
  • +
  • +

    the number of remaining requests in the current window;¶

    +
  • +
  • +

    the time remaining in the current window expressed in seconds or +as a timestamp;¶

    +
  • +
+
+
+

+A.1. Interoperability issues +

+

A major interoperability issue in throttling is the lack of standard headers, because:¶

+
    +
  • +

    each implementation associates different semantics to the +same header field names;¶

    +
  • +
  • +

    header field names proliferates.¶

    +
  • +
+

User agents interfacing with different servers may thus need to process different headers, +or the very same application interface that sits behind different reverse proxies +may reply with different throttling headers.¶

+
+
+
+
+
+
+

+Appendix B. Examples +

+
+
+

+B.1. Responses without defining policies +

+

Some servers may not expose the policy limits in the RateLimit-Policy header field. Clients can still use the RateLimit header field to throttle their requests.¶

+
+
+

+B.1.1. Throttling information in responses +

+

The client exhausted its quota for the next 50 seconds. +The limit and time-window is communicated out-of-band.¶

+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 200 Ok
+Content-Type: application/json
+RateLimit: default;r=0;t=50
+
+{"hello": "world"}
+
¶ +
+

Since the field values are not necessarily correlated with +the response status code, +a subsequent request is not required to fail. +The example below shows that the server decided to serve the request +even if remaining keyword value is 0. +Another server, or the same server under other load conditions, could have decided to throttle the request instead.¶

+

Request:¶

+
+
+GET /items/456 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 200 Ok
+Content-Type: application/json
+RateLimit: default;r=0;t=48
+
+{"still": "successful"}
+
¶ +
+
+
+
+
+

+B.1.2. Multiple policies in response +

+

The server uses two different policies to limit the client's requests:¶

+
    +
  • +

    5000 daily quota units;¶

    +
  • +
  • +

    1000 hourly quota units.¶

    +
  • +
+

The client consumed 4900 quota units in the first 14 hours.¶

+

Despite the next hourly limit of 1000 quota units, +the closest limit to reach is the daily one.¶

+

The server then exposes the RateLimit header fields to +inform the client that:¶

+
    +
  • +

    it has only 100 quota units left in the daily quota and the window will reset in 10 hours;¶

    +
  • +
+

The server MAY choose to omit returning the hourly policy as it uses the same quota units as the daily policy and the daily policy is the one that is closest to being exhausted.¶

+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 200 Ok
+Content-Type: application/json
+RateLimit: dayLimit;r=100;t=36000
+
+{"hello": "world"}
+
¶ +
+
+
+
+
+

+B.1.3. Use for limiting concurrency +

+

RateLimit header fields may be used to limit concurrency, +advertising limits that are lower than the usual ones +in case of saturation, thus increasing availability.¶

+

The server adopted a basic policy of 100 quota units per minute, +and in case of resource exhaustion adapts the returned values +reducing both limit and remaining keyword values.¶

+

After 2 seconds the client consumed 40 quota units¶

+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 200 Ok
+Content-Type: application/json
+RateLimit-Policy: basic;l=100;w=60
+RateLimit: basic;r=60;t=58
+
+{"elapsed": 2, "issued": 40}
+
¶ +
+

At the subsequent request - due to resource exhaustion - +the server advertises only r=20.¶

+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 200 Ok
+Content-Type: application/json
+RateLimit-Policy: basic;l=100;w=60
+RateLimit: basic;r=20;t=56
+
+{"elapsed": 4, "issued": 41}
+
¶ +
+
+
+
+
+

+B.1.4. Use in throttled responses +

+

A client exhausted its quota and the server throttles it +sending Retry-After.¶

+

In this example, the values of Retry-After and RateLimit header field reference the same moment, +but this is not a requirement.¶

+

The 429 (Too Many Request) HTTP status code is just used as an example.¶

+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 429 Too Many Requests
+Content-Type: application/json
+Date: Mon, 05 Aug 2019 09:27:00 GMT
+Retry-After: Mon, 05 Aug 2019 09:27:05 GMT
+RateLimit: default;r=0;t=5
+
+{
+"title": "Too Many Requests",
+"status": 429,
+"detail": "You have exceeded your quota"
+}
+
¶ +
+
+
+
+
+
+
+

+B.2. Responses with defined policies +

+
+
+

+B.2.1. Throttling window specified via parameter +

+

The client has 99 quota units left for the next 50 seconds. +The time window is communicated by the w parameter, so we know the throughput is 100 quota units per minute.¶

+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 200 Ok
+Content-Type: application/json
+RateLimit: fixedwindow;r=99;t=50
+RateLimit-Policy: fixedwindow;l=100;w=60
+{"hello": "world"}
+
¶ +
+
+
+
+
+

+B.2.2. Dynamic limits with parameterized windows +

+

The policy conveyed by the RateLimit header field states that +the server accepts 100 quota units per minute.¶

+

To avoid resource exhaustion, the server artificially lowers +the actual limits returned in the throttling headers.¶

+

The remaining keyword then advertises +only 9 quota units for the next 50 seconds to slow down the client.¶

+

Note that the server could have lowered even the other +values in the RateLimit header field: this specification +does not mandate any relation between the field values +contained in subsequent responses.¶

+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 200 Ok
+Content-Type: application/json
+RateLimit-Policy: dynamic;l=100;w=60
+RateLimit: dynamic;r=9;t=50
+
+
+{
+  "status": 200,
+  "detail": "Just slow down without waiting."
+}
+
¶ +
+
+
+
+
+

+B.2.3. Dynamic limits for pushing back and slowing down +

+

Continuing the previous example, let's say the client waits 10 seconds and +performs a new request which, due to resource exhaustion, the server rejects +and pushes back, advertising r=0 for the next 20 seconds.¶

+

The server advertises a smaller window with a lower limit to slow +down the client for the rest of its original window after the 20 seconds elapse.¶

+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 429 Too Many Requests
+Content-Type: application/json
+RateLimit-Policy: dynamic;l=15;w=20
+RateLimit: dynamic;r=0;t=20
+
+{
+  "status": 429,
+  "detail": "Wait 20 seconds, then slow down!"
+}
+
¶ +
+
+
+
+
+
+
+

+B.3. Dynamic limits for pushing back with Retry-After and slow down +

+

Alternatively, given the same context where the previous example starts, we +can convey the same information to the client via Retry-After, with +the advantage that the server can now specify the policy's nominal limit and +window that will apply after the reset, e.g. assuming the resource exhaustion +is likely to be gone by then, so the advertised policy does not need to be +adjusted, yet we managed to stop requests for a while and slow down the rest of +the current window.¶

+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 429 Too Many Requests
+Content-Type: application/json
+Retry-After: 20
+RateLimit-Policy: dynamic;l=100;w=60
+RateLimit: dynamic;r=15;t=40
+
+{
+  "status": 429,
+  "detail": "Wait 20 seconds, then slow down!"
+}
+
¶ +
+

Note that in this last response the client is expected to honor +Retry-After and perform no requests for the specified amount of +time, whereas the previous example would not force the client to stop +requests before the reset time is elapsed, as it would still be free to +query again the server even if it is likely to have the request rejected.¶

+
+
+

+B.3.1. Missing Remaining information +

+

The server does not expose remaining values +(for example, because the underlying counters are not available). +Instead, it resets the limit counter every second.¶

+

It communicates to the client the limit of 10 quota units per second +always returning the limit and reset keywords.¶

+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 200 Ok
+Content-Type: application/json
+RateLimit-Policy: quota;l=100;w=1
+RateLimit: quota;t=1
+
+{"first": "request"}
+
¶ +
+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 200 Ok
+Content-Type: application/json
+RateLimit-Policy: quota;l=10
+RateLimit: quota;t=1
+
+{"second": "request"}
+
¶ +
+
+
+
+
+

+B.3.2. Use with multiple windows +

+

This is a standardized way of describing the policy +detailed in Appendix B.1.2:¶

+
    +
  • +

    5000 daily quota units;¶

    +
  • +
  • +

    1000 hourly quota units.¶

    +
  • +
+

The client consumed 4900 quota units in the first 14 hours.¶

+

Despite the next hourly limit of 1000 quota units, the closest limit +to reach is the daily one.¶

+

The server then exposes the RateLimit header fields to inform the client that:¶

+
    +
  • +

    it has only 100 quota units left;¶

    +
  • +
  • +

    the window will reset in 10 hours;¶

    +
  • +
  • +

    the expiring-limit is 5000.¶

    +
  • +
+

Request:¶

+
+
+GET /items/123 HTTP/1.1
+Host: api.example
+
+
¶ +
+

Response:¶

+
+
+HTTP/1.1 200 OK
+Content-Type: application/json
+RateLimit-Policy: hour;l=1000;w=3600, day;l=5000;w=86400
+RateLimit: day;r=100;t=36000
+
+{"hello": "world"}
+
¶ +
+
+
+
+
+
+
+
+
+

+FAQ +

+

This section is to be removed before publishing as an RFC.¶

+
    +
  1. +

    Why defining standard fields for throttling?¶

    +

    +To simplify enforcement of throttling policies and enable clients to constraint their requests to avoid being throttled.¶

    +
  2. +
  3. +

    Can I use RateLimit header fields in throttled responses (eg with status code 429)?¶

    +

    +Yes, you can.¶

    +
  4. +
  5. +

    Are those specs tied to RFC 6585?¶

    +

    +No. [RFC6585] defines the 429 status code and we use it just as an example of a throttled request, +that could instead use even 403 or whatever status code.¶

    +
  6. +
  7. +

    Why is the partition key necessary?¶

    +

    +Without a partition key, a server can only effectively only have one scope (aka partition), which is impractical for most services, or it needs to communicate the scopes out-of-band. +This prevents the development of generic connector code that can be used to prevent requests from being throttled. +Many APIs rely on API keys, user identity or client identity to allocate quota. +As soon as a single client processes requests for more than one partition, the client needs to know the corresponding partition key to properly track requests against allocated quota.¶

    +
  8. +
  9. +

    Why using delay-seconds instead of a UNIX Timestamp? +Why not using subsecond precision?¶

    +

    +Using delay-seconds aligns with Retry-After, which is returned in similar contexts, +eg on 429 responses.¶

    +

    +Timestamps require a clock synchronization protocol +(see Section 5.6.7 of [HTTP]). +This may be problematic (e.g. clock adjustment, clock skew, failure of hardcoded clock synchronization servers, +IoT devices, ..). +Moreover timestamps may not be monotonically increasing due to clock adjustment. +See Another NTP client failure story¶

    +

    +We did not use subsecond precision because:¶

    +
      +
    • +

      that is more subject to system clock correction +like the one implemented via the adjtimex() Linux system call;¶

      +
    • +
    • +

      response-time latency may not make it worth. A brief discussion on the subject is +on the httpwg ml¶

      +
    • +
    • +

      almost all rate-limit headers implementations do not use it.¶

      +
    • +
    +
  10. +
  11. +

    Shouldn't I limit concurrency instead of request rate?¶

    +

    +You can use this specification to limit concurrency +at the HTTP level (see {#use-for-limiting-concurrency}) +and help clients to shape their requests avoiding being throttled out.¶

    +

    +A problematic way to limit concurrency is connection dropping, +especially when connections are multiplexed (e.g. HTTP/2) +because this results in unserviced client requests, +which is something we want to avoid.¶

    +

    +A semantic way to limit concurrency is to return 503 + Retry-After +in case of resource saturation (e.g. thrashing, connection queues too long, +Service Level Objectives not meet, ..). +Saturation conditions can be either dynamic or static: all this is out of +the scope for the current document.¶

    +
  12. +
  13. +

    Do a positive value of remaining paramter imply any service guarantee for my +future requests to be served?¶

    +

    +No. FAQ integrated in Section 4.1.1.¶

    +
  14. +
  15. +

    Is the quota-policy definition Section 2.5 too complex?¶

    +

    +You can always return the simplest form¶

    +
  16. +
+
+
+RateLimit:default;r=50;t=60
+
¶ +
+

The policy key clearly connects the current usage status of a policy to the defined limits. + So for the following field:¶

+
+
+RateLimit-Policy: sliding;l=100;w=60;burst=1000;comment="sliding window", fixed;l=5000;w=3600;burst=0;comment="fixed window"
+RateLimit: sliding;r=50;t=44
+
¶ +
+

the value "sliding" identifies the policy being reported.¶

+
    +
  1. +

    Can intermediaries alter RateLimit header fields?¶

    +

    +Generally, they should not because it might result in unserviced requests. + There are reasonable use cases for intermediaries mangling RateLimit header fields though, + e.g. when they enforce stricter quota-policies, + or when they are an active component of the service. + In those case we will consider them as part of the originating infrastructure.¶

    +
  2. +
  3. +

    Why the w parameter is just informative? +Could it be used by a client to determine the request rate?¶

    +

    +A non-informative w parameter might be fine in an environment +where clients and servers are tightly coupled. Conveying policies +with this detail on a large scale would be very complex and implementations +would be likely not interoperable. We thus decided to leave w as +an informational parameter and only rely on the limit, remaining and reset keywords +for defining the throttling +behavior.¶

    +
  4. +
  5. +

    Can I use RateLimit fields in trailers? +Servers usually establish whether the request is in-quota before creating a response, so the RateLimit field values should be already available in that moment. +Supporting trailers has the only advantage that allows to provide more up-to-date information to the client in case of slow responses. +However, this complicates client implementations with respect to combining fields from headers and accounting for intermediaries that drop trailers. +Since there are no current implementations that use trailers, we decided to leave this as a future-work.¶

    +
  6. +
+
+
+
+
+

+RateLimit header fields currently used on the web +

+

This section is to be removed before publishing as an RFC.¶

+

Commonly used header field names are:¶

+
    +
  • +

    X-RateLimit-Limit, +X-RateLimit-Remaining, +X-RateLimit-Reset;¶

    +
  • +
+

There are variants too, where the window is specified +in the header field name, eg:¶

+
    +
  • +

    x-ratelimit-limit-minute, x-ratelimit-limit-hour, x-ratelimit-limit-day¶

    +
  • +
  • +

    x-ratelimit-remaining-minute, x-ratelimit-remaining-hour, x-ratelimit-remaining-day¶

    +
  • +
+

Here are some interoperability issues:¶

+
    +
  • +

    X-RateLimit-Remaining references different values, depending on the implementation:¶

    +
      +
    • +

      seconds remaining to the window expiration¶

      +
    • +
    • +

      milliseconds remaining to the window expiration¶

      +
    • +
    • +

      seconds since UTC, in UNIX Timestamp [UNIX]¶

      +
    • +
    • +

      a datetime, either IMF-fixdate [HTTP] or [RFC3339]¶

      +
    • +
    +
  • +
  • +

    different headers, with the same semantic, are used by different implementers:¶

    +
      +
    • +

      X-RateLimit-Limit and X-Rate-Limit-Limit¶

      +
    • +
    • +

      X-RateLimit-Remaining and X-Rate-Limit-Remaining¶

      +
    • +
    • +

      X-RateLimit-Reset and X-Rate-Limit-Reset¶

      +
    • +
    +
  • +
+

The semantic of RateLimit depends on the windowing algorithm. +A sliding window policy for example, may result in having a remaining keyword value related to the ratio between the current and the maximum throughput. +e.g.¶

+
+
+RateLimit-Policy: sliding;l=12;w=1
+RateLimit: sliding;l=12;r=6;t=1          ; using 50% of throughput, that is 6 units/s
+
+
¶ +
+

If this is the case, the optimal solution is to achieve¶

+
+
+RateLimit-Policy: sliding;l=12;w=1
+RateLimit: sliding;l=12;r=1;t=1          ; using 100% of throughput, that is 12 units/s
+
¶ +
+

At this point you should stop increasing your request rate.¶

+
+
+
+
+

+Acknowledgements +

+

Thanks to Willi Schoenborn, Alejandro Martinez Ruiz, Alessandro Ranellucci, +Amos Jeffries, +Martin Thomson, +Erik Wilde and Mark Nottingham for being the initial contributors +of these specifications. +Kudos to the first community implementers: +Aapo Talvensaari, +Nathan Friedly +and Sanyam Dogra.¶

+

In addition to the people above, this document owes a lot to the extensive discussion in the HTTPAPI workgroup, including +Rich Salz, +Darrel Miller +and Julian Reschke.¶

+
+
+
+
+

+Changes +

+

This section is to be removed before publishing as an RFC.¶

+
+
+

+Since draft-ietf-httpapi-ratelimit-headers-07 +

+

This section is to be removed before publishing as an RFC.¶

+
    +
  • +

    Refactored both fields to lists of Items that identify policy and use parameters¶

    +
  • +
  • +

    Added quota unit parameter¶

    +
  • +
  • +

    Added partition key parameter¶

    +
  • +
+
+
+
+
+

+Since draft-ietf-httpapi-ratelimit-headers-03 +

+

This section is to be removed before publishing as an RFC.¶

+
    +
  • +

    Split policy informatiom in RateLimit-Policy #81¶

    +
  • +
+
+
+
+
+

+Since draft-ietf-httpapi-ratelimit-headers-02 +

+

This section is to be removed before publishing as an RFC.¶

+
    +
  • +

    Address throttling scope #83¶

    +
  • +
+
+
+
+
+

+Since draft-ietf-httpapi-ratelimit-headers-01 +

+

This section is to be removed before publishing as an RFC.¶

+
    +
  • +

    Update IANA considerations #60¶

    +
  • +
  • +

    Use Structured fields #58¶

    +
  • +
  • +

    Reorganize document #67¶

    +
  • +
+
+
+
+
+

+Since draft-ietf-httpapi-ratelimit-headers-00 +

+

This section is to be removed before publishing as an RFC.¶

+
    +
  • +

    Use I-D.httpbis-semantics, which includes referencing delay-seconds +instead of delta-seconds. #5¶

    +
  • +
+
+
+
+
+
+
+

+Authors' Addresses +

+
+
Roberto Polli
+
Team Digitale, Italian Government
+
Italy
+ +
+
+
Alejandro Martinez Ruiz
+
Red Hat
+ +
+
+
Darrel Miller
+
Microsoft
+ +
+
+
+ + + diff --git a/draft-ietf-httpapi-ratelimit-headers.md b/draft-ietf-httpapi-ratelimit-headers.md index 2294126..2fcf76d 100644 --- a/draft-ietf-httpapi-ratelimit-headers.md +++ b/draft-ietf-httpapi-ratelimit-headers.md @@ -147,7 +147,7 @@ The time window is a non-negative Integer value expressing an interval in second ## Quota Policy {#quota-policy} -A quota policy is maintained by a server to limit the activity (counted in [quota units](#quota-units)) of a given [quota partition](#quota-partition) over a period of time (known as the [time window](#time-window)) to a specified amount known as the [quota](#quota). +A quota policy is maintained by a server to limit the activity (counted in [quota units](#quota-unit)) of a given [quota partition](#quota-partition) over a period of time (known as the [time window](#time-window)) to a specified amount known as the [quota](#quota). Quota policies can be advertised by servers (see {{ratelimit-policy-field}}), but they are not required to be, and more than one quota policy can affect a given request from a client to a server. @@ -211,7 +211,7 @@ This field MAY convey the time window associated with the expiring-limit, as sho These examples show multiple policies being returned: ~~~ - RateLimit-Policy: permin;l=50;w=60, perhr;l=1000;w=3600, perday;l=5000;w=86400 + RateLimit-Policy: permin;l=50;w=60,perhr;l=1000;w=3600,perday;l=5000;w=86400 ~~~ The following example shows a policy with a partition key: @@ -240,7 +240,7 @@ The field is expressed as List of {{servicelimit-item}}. ## Service Limit Item {#servicelimit-item} -Each service limit item in identifies the quota policy associated with the request and +Each service limit item in identifies the quota policy associated with the request and The following parameters are defined in this specification: @@ -251,7 +251,7 @@ The following parameters are defined in this specification: : This OPTIONAL parameter value conveys the time window reset time for the identified policy ({{ratelimit-reset-parameter}}). pk: - : The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. + : The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. This field cannot appear in a trailer section. Other parameters are allowed and can be regarded as comments. @@ -262,7 +262,7 @@ Implementation- or service-specific parameters SHOULD be prefixed parameters wit The "r" parameter indicates the remaining quota units for the identified policy ({{ratelimit-remaining-parameter}}). -It is a non-negative Integer expressed in [quota units](#quota-units). +It is a non-negative Integer expressed in [quota units](#quota-unit). Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. When remaining parameter value is low, it indicates that the server may soon throttle the client (see {{providing-ratelimit-fields}}). @@ -329,7 +329,6 @@ Servers are not required to return RateLimit header fields in every response, an Implementers concerned with response fields' size, might take into account their ratio with respect to the content length, or use header-compression HTTP features such as {{?HPACK=RFC7541}}. - # Client Behavior {#receiving-fields} The RateLimit header fields can be used by clients to determine whether the associated request respected the server's quota policy, and as an indication of whether subsequent requests will. However, the server might apply other criteria when servicing future requests, and so the quota policy may not completely reflect whether requests will succeed. @@ -614,7 +613,7 @@ RateLimit: default;r=0;t=48 {"still": "successful"} ~~~ -### Multiple policies in response +### Multiple policies in response {#use-with-multiple-policies} The server uses two different policies to limit the client's requests: @@ -923,7 +922,7 @@ RateLimit: quota;t=1 ### Use with multiple windows This is a standardized way of describing the policy -detailed in {{use-with-custom-fields}}: +detailed in {{use-with-multiple-policies}}: - 5000 daily quota units; - 1000 hourly quota units. @@ -973,7 +972,7 @@ RateLimit: day;r=100;t=36000 No. {{?RFC6585}} defines the `429` status code and we use it just as an example of a throttled request, that could instead use even `403` or whatever status code. - + 4. Why is the partition key necessary? Without a partition key, a server can only effectively only have one scope (aka partition), which is impractical for most services, or it needs to communicate the scopes out-of-band. diff --git a/draft-ietf-httpapi-ratelimit-headers.md~ b/draft-ietf-httpapi-ratelimit-headers.md~ new file mode 100644 index 0000000..2fcf76d --- /dev/null +++ b/draft-ietf-httpapi-ratelimit-headers.md~ @@ -0,0 +1,1169 @@ +--- +title: RateLimit header fields for HTTP +abbrev: +docname: draft-ietf-httpapi-ratelimit-headers-latest +category: std + +ipr: trust200902 +area: Applications and Real-Time +workgroup: HTTPAPI +keyword: Internet-Draft + +stand_alone: yes +pi: [toc, tocindent, sortrefs, symrefs, strict, compact, comments, inline, docmapping] + +venue: + group: HTTPAPI + type: Working Group + home: https://datatracker.ietf.org/wg/httpapi/about/ + mail: httpapi@ietf.org + arch: https://mailarchive.ietf.org/arch/browse/httpapi/ + repo: https://github.com/ietf-wg-httpapi/ratelimit-headers + +author: + - + ins: R. Polli + name: Roberto Polli + org: Team Digitale, Italian Government + email: robipolli@gmail.com + country: Italy + - + ins: A. Martinez + name: Alejandro Martinez Ruiz + org: Red Hat + email: alex@flawedcode.org + - + ins: D. Miller + name: Darrel Miller + org: Microsoft + email: darrel@tavis.ca + +entity: + SELF: "RFC nnnn" + +normative: + IANA: RFC8126 + HTTP: RFC9110 + +informative: + PRIVACY: RFC6973 + UNIX: + title: The Single UNIX Specification, Version 2 - 6 Vol Set for UNIX 98 + author: + name: The Open Group + ins: The Open Group + date: 1997-02 +--- abstract + +This document defines the RateLimit-Policy and RateLimit HTTP header fields for servers to advertise their service policy limits and the current limits, thereby allowing clients to avoid being throttled. + +--- middle + +# Introduction + +Rate limiting of HTTP clients has become a widespread practice, especially for HTTP APIs. Typically, servers who do so limit the number of acceptable requests in a given time window (e.g. 10 requests per second). See {{rate-limiting}} for further information on the current usage of rate limiting in HTTP. + +Currently, there is no standard way for servers to communicate quotas so that clients can throttle their requests to prevent errors. This document defines a set of standard HTTP header fields to enable rate limiting: + +- RateLimit: to convey + the server's current limit of quota units available to the client in the policy time window, + the remaining quota units in the current window, + and the time remaining in the current window, specified in seconds, and +- RateLimit-Policy: the service policy limits. + +These fields enable establishing complex rate limiting policies, including using multiple and variable time windows and dynamic quotas, and implementing concurrency limits. + +The behavior of the RateLimit header field is compatible with the delay-seconds notation of Retry-After. + +## Goals {#goals} + +The goals of this document are: + + Interoperability: + : Standardize the names and semantics of rate-limit headers + to ease their enforcement and adoption; + + Resiliency: + : Improve resiliency of HTTP infrastructure by + providing clients with information useful + to throttle their requests and + prevent 4xx or 5xx responses; + + Documentation: + : Simplify API documentation by eliminating the need + to include detailed quota limits + and related fields in API documentation. + +The following features are out of the scope of this document: + + Authorization: + : RateLimit header fields are not meant to support + authorization or other kinds of access controls. + + Response status code: + : RateLimit header fields may be returned in both + successful (see {{Section 15.3 of HTTP}}) and non-successful responses. + This specification does not cover whether non Successful + responses count on quota usage, + nor does it mandates any correlation between the RateLimit values + and the returned status code. + + Throttling algorithm: + : This specification does not mandate a specific throttling algorithm. + The values published in the fields, including the window size, + can be statically or dynamically evaluated. + + Service Level Agreement: + : Conveyed quota hints do not imply any service guarantee. + Server is free to throttle respectful clients under certain circumstances. + +## Notational Conventions + +{::boilerplate bcp14} + +The term Origin is to be interpreted as described in Section 7 of {{!WEB-ORIGIN=RFC6454}}. + +This document uses the terms List, Item and Integer from {{Section 3 of !STRUCTURED-FIELDS=RFC8941}} to specify syntax and parsing, along with the concept of "bare item". + +# Terminology + +## Quota {#quota} + +A quota is an allocation of capacity to enable a server to limit client requests. That capacity is counted in quota units and may be reallocated at the end of a time window {{time-window}}. + +## Quota Unit {#quota-unit} + +A quota unit is the unit of measure used to count the activity of a client. + +## Quota Partition {#quota-partition} + +A quota partition is a division of a server's capacity across different clients, users and owned resources. + +## Time Window {#time-window} + +A time window indicates a period of time associated to the allocated quota. + +The time window is a non-negative Integer value expressing an interval in seconds, similar to the "delay-seconds" rule defined in {{Section 10.2.3 of HTTP}}. Sub-second precision is not supported. + +## Quota Policy {#quota-policy} + +A quota policy is maintained by a server to limit the activity (counted in [quota units](#quota-unit)) of a given [quota partition](#quota-partition) over a period of time (known as the [time window](#time-window)) to a specified amount known as the [quota](#quota). + +Quota policies can be advertised by servers (see {{ratelimit-policy-field}}), but they are not required to be, and more than one quota policy can affect a given request from a client to a server. + +## Service Limit {#service-limit} + +A service limit is the current limit of the amount of activity that a server will allow based on the remaining quota for a particular quota partition within the time-window, if defined. + +# RateLimit-Policy Field {#ratelimit-policy-field} + +The "RateLimit-Policy" response header field is a non-empty List of {{quotapolicy-item}}. Its value is informative. The values are expected to remain consistent over a the lifetime of a connection. It is this characteristic that differentiates it from the [RateLimit](#ratelimit-field) that contains values that may change on every request. + +~~~ + RateLimit-Policy: burst;q=100;w=60,daily;q=1000;w=86400 +~~~ + +## Quota Policy Item {#quotapolicy-item} +A quota policy Item contains information about a server's capacity allocation for a quota partition associated with the request. + +The following parameters are defined in this specification: + + q: + : The REQUIRED "q" parameter indicates the quota allocated. ({{ratelimitpolicy-quota}}) + + qu: + : The OPTIONAL "qu" parameter value conveys the quota units associated to the "q" parameter. The default quota unit is "request". ({{ratelimitpolicy-quotaunit}}) + + w: + : The OPTIONAL "w" parameter value conveys a time "window" ({{time-window}}). ({{ratelimitpolicy-window}}) + + pk: + : The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. {{ratelimitpolicy-partitionkey}} + +Other parameters are allowed and can be regarded as comments. + +Implementation- or service-specific parameters SHOULD be prefixed parameters with a vendor identifier, e.g. `acme-policy`, `acme-burst`. + +### Quota Parameter {#ratelimitpolicy-quota} + + The "q" parameter uses a non-negative integer value to indicate the quota allocated for client activity (counted in quota units) for a given quota partition ({{service-limit}}). + +### Quota Unit Parameter {#ratelimitpolicy-quotaunit} + +The "qu" parameter value conveys the quota units associated to the "q" parameter. + +### Window Parameter {#ratelimitpolicy-window} + +The "w" parameter value conveys a time "window" in seconds. ({{time-window}}). + +### Partition Key Parameter {#ratelimitpolicy-partitionkey} + +The "pk" parameter value conveys the partition key associated to the request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key. + +## RateLimit Policy Field Examples + +This field MAY convey the time window associated with the expiring-limit, as shown in this example: + +~~~ + RateLimit-Policy: default;l=100;w=10 +~~~ + +These examples show multiple policies being returned: + +~~~ + RateLimit-Policy: permin;l=50;w=60,perhr;l=1000;w=3600,perday;l=5000;w=86400 +~~~ + +The following example shows a policy with a partition key: + +~~~ + RateLimit-Policy: peruser;l=100;w=60;pk=user123 +~~~ + +The following example shows a policy with a partition key and a quota unit: + +~~~ + RateLimit-Policy: peruser;l=65535;w=10;pk=user123;qu=bytes +~~~ + +This field cannot appear in a trailer section. + +# RateLimit Field {#ratelimit-field} + +A server uses the "RateLimit" response header field to communicate the service limit for a quota policy for a particular partition key. + +The field is expressed as List of {{servicelimit-item}}. + +~~~ + RateLimit: default;r=50;t=30 +~~~ + +## Service Limit Item {#servicelimit-item} + +Each service limit item in identifies the quota policy associated with the request and + +The following parameters are defined in this specification: + + r: + : This parameter value conveys the remaining quota units for the identified policy ({{ratelimit-remaining-parameter}}). + + t: + : This OPTIONAL parameter value conveys the time window reset time for the identified policy ({{ratelimit-reset-parameter}}). + + pk: + : The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. + +This field cannot appear in a trailer section. Other parameters are allowed and can be regarded as comments. + +Implementation- or service-specific parameters SHOULD be prefixed parameters with a vendor identifier, e.g. `acme-policy`, `acme-burst`. + + +### Remaining Parameter {#ratelimit-remaining-parameter} + +The "r" parameter indicates the remaining quota units for the identified policy ({{ratelimit-remaining-parameter}}). + +It is a non-negative Integer expressed in [quota units](#quota-unit). +Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. +When remaining parameter value is low, it indicates that the server may soon throttle the client (see {{providing-ratelimit-fields}}). + +### Reset Parameter {#ratelimit-reset-parameter} + +The "t" parameter indicates the number of seconds until the quota associated with the quota policy resets. + +It is a non-negative Integer compatible with the delay-seconds rule, because: + +- it does not rely on clock synchronization and is resilient to clock adjustment + and clock skew between client and server (see {{Section 5.6.7 of HTTP}}); +- it mitigates the risk related to thundering herd when too many clients are serviced with the same timestamp. + +The client MUST NOT assume that all its service limit will be reset at the moment indicated by the reset keyword. The server MAY arbitrarily alter the reset parameter value between subsequent requests; for example, in case of resource saturation or to implement sliding window policies. + +### Partition Key Parameter {#ratelimit-partitionkey} + +The "pk" parameter value conveys the partition key associated to the request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key. + + +## RateLimit Field Examples + +This example shows a RateLimit field with a remaining quota of 50 units and a time window reset in 30 seconds: + +~~~ + RateLimit: default;r=50;t=30 +~~~ + +This example shows a remaining quota of 999 requests for a partition key that has no time window reset: + +~~~ + RateLimit: default;r=999;pk=trial-121323 +~~~ + +This example shows a 300MB remaining quota for an application in the next 60 seconds: + +~~~ + RateLimit: default;r=300000000;pk=App-999;t=60;qu=bytes +~~~ + + +# Server Behavior {#providing-ratelimit-fields} + +A server MAY return RateLimit header fields independently of the response status code. This includes on throttled responses. This document does not mandate any correlation between the RateLimit header field values and the returned status code. + +Servers should be careful when returning RateLimit header fields in redirection responses (i.e., responses with 3xx status codes) because a low remaining keyword value could prevent the client from issuing requests. For example, given the RateLimit header fields below, a client could decide to wait 10 seconds before following the "Location" header field (see {{Section 10.2.2 of HTTP}}), because the remaining keyword value is 0. + +~~~ http-message +HTTP/1.1 301 Moved Permanently +Location: /foo/123 +RateLimit: problemPolicy;r=0, t=10 + +~~~ + +If a response contains both the Retry-After and the RateLimit header fields, the reset keyword value SHOULD reference the same point in time as the Retry-After field value. + +A service using RateLimit header fields MUST NOT convey values exposing an unwanted volume of requests and SHOULD implement mechanisms to cap the ratio between the remaining and the reset keyword values (see {{sec-resource-exhaustion}}); this is especially important when a quota policy uses a large time window. + +Under certain conditions, a server MAY artificially lower RateLimit header field values between subsequent requests, e.g. to respond to Denial of Service attacks or in case of resource saturation. + +## Performance Considerations + +Servers are not required to return RateLimit header fields in every response, and clients need to take this into account. For example, an implementer concerned with performance might provide RateLimit header fields only when a given quota is close to exhaustion. + +Implementers concerned with response fields' size, might take into account their ratio with respect to the content length, or use header-compression HTTP features such as {{?HPACK=RFC7541}}. + +# Client Behavior {#receiving-fields} + +The RateLimit header fields can be used by clients to determine whether the associated request respected the server's quota policy, and as an indication of whether subsequent requests will. However, the server might apply other criteria when servicing future requests, and so the quota policy may not completely reflect whether requests will succeed. + +For example, a successful response with the following fields: + +~~~ + RateLimit: default;r=1;t=7 +~~~ + +does not guarantee that the next request will be successful. Servers' behavior may be subject to other conditions. + +A client is responsible for ensuring that RateLimit header field values returned +cause reasonable client behavior with respect to throughput and latency +(see {{sec-resource-exhaustion}} and {{sec-dos}}). + +A client receiving RateLimit header fields MUST NOT assume that future responses will contain the same RateLimit header fields, or any RateLimit header fields at all. + +Malformed RateLimit header fields MUST be ignored. + +A client SHOULD NOT exceed the quota units conveyed by the remaining keyword before the time window expressed in the reset keyword. + +The value of the reset keyword is generated at response time: a client aware of a significant network latency MAY behave accordingly and use other information (e.g. the "Date" response header field, or otherwise gathered metrics) to better estimate the reset keyword moment intended by the server. + +The details provided in the RateLimit-Policy header field are informative and MAY be ignored. + +If a response contains both the RateLimit and Retry-After fields, the Retry-After field MUST take precedence and the reset keyword MAY be ignored. + +This specification does not mandate a specific throttling behavior and implementers can adopt their preferred policies, including: + +- slowing down or pre-emptively back-off their request rate when + approaching quota limits; +- consuming all the quota according to the exposed limits and then wait. + +## Intermediaries {#intermediaries} + +This section documents the considerations advised in {{Section 16.3.2 of HTTP}}. + +An intermediary that is not part of the originating service infrastructure and is not aware of the quota policy semantic used by the Origin Server SHOULD NOT alter the RateLimit header fields' values in such a way as to communicate a more permissive quota policy; this includes removing the RateLimit header fields. + +An intermediary MAY alter the RateLimit header fields in such a way as to communicate a more restrictive quota policy when: + +- it is aware of the quota unit semantic used by the Origin Server; +- it implements this specification and enforces a quota policy which + is more restrictive than the one conveyed in the fields. + +An intermediary SHOULD forward a request even when presuming that it might not be serviced; the service returning the RateLimit header fields is the sole responsible of enforcing the communicated quota policy, and it is always free to service incoming requests. + +This specification does not mandate any behavior on intermediaries respect to retries, nor requires that intermediaries have any role in respecting quota policies. For example, it is legitimate for a proxy to retransmit a request without notifying the client, and thus consuming quota units. + +[Privacy considerations](#privacy) provide further guidance on intermediaries. + +## Caching + +{{?HTTP-CACHING=RFC9111}} defines how responses can be stored and reused for subsequent requests, +including those with RateLimit header fields. +Because the information in RateLimit header fields on a cached response may not be current, they SHOULD be ignored on responses that come from cache +(i.e., those with a positive current_age; see {{Section 4.2.3 of HTTP-CACHING}}). + +# Security Considerations + +## Throttling does not prevent clients from issuing requests {#sec-throttling-does-not-prevent} + +This specification does not prevent clients from making requests. +Servers should always implement mechanisms to prevent resource exhaustion. + +## Information disclosure {#sec-information-disclosure} + +Servers should not disclose to untrusted parties operational capacity information +that can be used to saturate its infrastructural resources. + +While this specification does not mandate whether non-successful responses consume quota, +if error responses (such as 401 (Unauthorized) and 403 (Forbidden)) count against quota, +a malicious client could probe the endpoint to get traffic information of another user. + +As intermediaries might retransmit requests and consume +quota units without prior knowledge of the user agent, +RateLimit header fields might reveal the existence of an intermediary +to the user agent. + +Where partition keys contain identifying information, either of the client application or the user, servers should be aware of the potential for impersonation and apply the appropriate security mechanisms. + +## Remaining quota units are not granted requests {#sec-remaining-not-granted} + +RateLimit header fields convey hints from the server +to the clients in order to help them avoid being throttled out. + +Clients MUST NOT consider the [quota units](#service-limit) returned in remaining keyword as a service level agreement. + +In case of resource saturation, the server MAY artificially lower the returned values +or not serve the request regardless of the advertised quotas. + +## Reliability of the reset keyword {#sec-reset-reliability} + +Consider that quota might not be restored after the moment referenced by the [reset keyword](#ratelimit-reset-parameter), +and the reset parameter value may not be constant. + +Subsequent requests might return a higher reset parameter value +to limit concurrency or implement dynamic or adaptive throttling policies. + +## Resource exhaustion {#sec-resource-exhaustion} + +When returning reset values, servers must be aware that +many throttled clients may come back at the very moment specified. + +This is true for Retry-After too. + +For example, if the quota resets every day at `18:00:00` +and your server returns the reset parameter accordingly + +~~~ + Date: Tue, 15 Nov 1994 18:00:00 GMT + RateLimit: daily;r=1;t=36400 +~~~ + +there's a high probability that all clients will show up at `18:00:00`. + +This could be mitigated by adding some jitter to the reset value. + +Resource exhaustion issues can be associated with quota policies using a +large time window, because a user agent by chance or on purpose +might consume most of its quota units in a significantly shorter interval. + +This behavior can be even triggered by the provided RateLimit header fields. +The following example describes a service +with an unconsumed quota policy of 10000 quota units per 1000 seconds. + +~~~ +RateLimit-Policy: somepolicy;l=10000;w=1000 +RateLimit: somepolicy;r=10000;t=10 +~~~ + +A client implementing a simple ratio between remaining keyword and reset keyword could infer an average throughput of 1000 quota units per second, while the limit keyword conveys a quota-policy with an average of 10 quota units per second. +If the service cannot handle such load, it should return either a lower remaining keyword value or an higher reset keyword value. +Moreover, complementing large time window quota policies with a short time window one mitigates those risks. + + +### Denial of Service {#sec-dos} + +RateLimit header fields may contain unexpected values by chance or on purpose. +For example, an excessively high remaining keyword value may be: + +- used by a malicious intermediary to trigger a Denial of Service attack + or consume client resources boosting its requests; +- passed by a misconfigured server; + +or a high reset keyword value could inhibit clients to contact the server (e.g. similarly to receiving "Retry-after: 1000000"). + +To mitigate this risk, clients can set thresholds that they consider reasonable in terms of quota units, time window, concurrent requests or throughput, and define a consistent behavior when the RateLimit exceed those thresholds. +For example this means capping the maximum number of request per second, or implementing retries when the reset keyword exceeds ten minutes. + +The considerations above are not limited to RateLimit header fields, but apply to all fields affecting how clients behave in subsequent requests (e.g. Retry-After). + + +# Privacy Considerations {#privacy} + +Clients that act upon a request to rate limit +are potentially re-identifiable (see {{Section 5.2.1 of PRIVACY}}) +because they react to information that might only be given to them. +Note that this might apply to other fields too (e.g. Retry-After). + +Since rate limiting is usually implemented in contexts where +clients are either identified or profiled +(e.g. assigning different quota units to different users), +this is rarely a concern. + +Privacy enhancing infrastructures using RateLimit header fields +can define specific techniques to mitigate the risks of re-identification. + +# IANA Considerations + +IANA is requested to update one registry and create one new registry. + +Please add the following entries to the +"Hypertext Transfer Protocol (HTTP) Field Name Registry" registry ({{HTTP}}): + +|---------------------|-----------|---------------| +| Field Name | Status | Specification | +|---------------------|-----------|---------------| +| RateLimit | permanent | {{ratelimit-field}} of {{&SELF}} | +| RateLimit-Policy | permanent | {{ratelimit-policy-field}} of {{&SELF}} | +|---------------------|-----------|---------------| + + +--- back + +# Rate-limiting and quotas {#rate-limiting} + +Servers use quota mechanisms to avoid systems overload, to ensure an equitable distribution of computational resources or to enforce other policies - e.g. monetization. + +A basic quota mechanism limits the number of acceptable requests in a given time window, e.g. 10 requests per second. + +When quota is exceeded, servers usually do not serve the request replying instead with a 4xx HTTP status code (e.g. 429 or 403) or adopt more aggressive policies like dropping connections. + +Quotas may be enforced on different basis (e.g. per user, per IP, per geographic area, ..) and at different levels. For example, an user may be allowed to issue: + +- 10 requests per second; +- limited to 60 requests per minute; +- limited to 1000 requests per hour. + +Moreover system metrics, statistics and heuristics can be used to implement more complex policies, +where the number of acceptable requests and the time window are computed dynamically. + +To help clients throttling their requests, +servers may expose the counters used to evaluate quota policies via HTTP header fields. + +Those response headers may be added by HTTP intermediaries such as API gateways and reverse proxies. + +On the web we can find many different rate-limit headers, +usually containing the number of allowed requests in a given time window, and when the window is reset. + +The common choice is to return three headers containing: + +- the maximum number of allowed requests in the time window; +- the number of remaining requests in the current window; +- the time remaining in the current window expressed in seconds or + as a timestamp; + +## Interoperability issues + +A major interoperability issue in throttling is the lack of standard headers, because: + +- each implementation associates different semantics to the + same header field names; +- header field names proliferates. + +User agents interfacing with different servers may thus need to process different headers, +or the very same application interface that sits behind different reverse proxies +may reply with different throttling headers. + +# Examples + +## Responses without defining policies + +Some servers may not expose the policy limits in the RateLimit-Policy header field. Clients can still use the RateLimit header field to throttle their requests. + +### Throttling information in responses + +The client exhausted its quota for the next 50 seconds. +The limit and time-window is communicated out-of-band. + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 200 Ok +Content-Type: application/json +RateLimit: default;r=0;t=50 + +{"hello": "world"} +~~~ + +Since the field values are not necessarily correlated with +the response status code, +a subsequent request is not required to fail. +The example below shows that the server decided to serve the request +even if remaining keyword value is 0. +Another server, or the same server under other load conditions, could have decided to throttle the request instead. + +Request: + +~~~ http-message +GET /items/456 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 200 Ok +Content-Type: application/json +RateLimit: default;r=0;t=48 + +{"still": "successful"} +~~~ + +### Multiple policies in response {#use-with-multiple-policies} + +The server uses two different policies to limit the client's requests: + +- 5000 daily quota units; +- 1000 hourly quota units. + +The client consumed 4900 quota units in the first 14 hours. + +Despite the next hourly limit of 1000 quota units, +the closest limit to reach is the daily one. + +The server then exposes the RateLimit header fields to +inform the client that: + +- it has only 100 quota units left in the daily quota and the window will reset in 10 hours; + +The server MAY choose to omit returning the hourly policy as it uses the same quota units as the daily policy and the daily policy is the one that is closest to being exhausted. + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 200 Ok +Content-Type: application/json +RateLimit: dayLimit;r=100;t=36000 + +{"hello": "world"} +~~~ + +### Use for limiting concurrency {#use-for-limiting-concurrency} + +RateLimit header fields may be used to limit concurrency, +advertising limits that are lower than the usual ones +in case of saturation, thus increasing availability. + +The server adopted a basic policy of 100 quota units per minute, +and in case of resource exhaustion adapts the returned values +reducing both limit and remaining keyword values. + +After 2 seconds the client consumed 40 quota units + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 200 Ok +Content-Type: application/json +RateLimit-Policy: basic;l=100;w=60 +RateLimit: basic;r=60;t=58 + +{"elapsed": 2, "issued": 40} +~~~ + +At the subsequent request - due to resource exhaustion - +the server advertises only `r=20`. + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 200 Ok +Content-Type: application/json +RateLimit-Policy: basic;l=100;w=60 +RateLimit: basic;r=20;t=56 + +{"elapsed": 4, "issued": 41} +~~~ + +### Use in throttled responses + +A client exhausted its quota and the server throttles it +sending Retry-After. + +In this example, the values of Retry-After and RateLimit header field reference the same moment, +but this is not a requirement. + +The 429 (Too Many Request) HTTP status code is just used as an example. + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 429 Too Many Requests +Content-Type: application/json +Date: Mon, 05 Aug 2019 09:27:00 GMT +Retry-After: Mon, 05 Aug 2019 09:27:05 GMT +RateLimit: default;r=0;t=5 + +{ +"title": "Too Many Requests", +"status": 429, +"detail": "You have exceeded your quota" +} +~~~ + +## Responses with defined policies + +### Throttling window specified via parameter + +The client has 99 quota units left for the next 50 seconds. +The time window is communicated by the `w` parameter, so we know the throughput is 100 quota units per minute. + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 200 Ok +Content-Type: application/json +RateLimit: fixedwindow;r=99;t=50 +RateLimit-Policy: fixedwindow;l=100;w=60 +{"hello": "world"} +~~~ + + +### Dynamic limits with parameterized windows + +The policy conveyed by the RateLimit header field states that +the server accepts 100 quota units per minute. + +To avoid resource exhaustion, the server artificially lowers +the actual limits returned in the throttling headers. + +The remaining keyword then advertises +only 9 quota units for the next 50 seconds to slow down the client. + +Note that the server could have lowered even the other +values in the RateLimit header field: this specification +does not mandate any relation between the field values +contained in subsequent responses. + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 200 Ok +Content-Type: application/json +RateLimit-Policy: dynamic;l=100;w=60 +RateLimit: dynamic;r=9;t=50 + + +{ + "status": 200, + "detail": "Just slow down without waiting." +} +~~~ + +### Dynamic limits for pushing back and slowing down + +Continuing the previous example, let's say the client waits 10 seconds and +performs a new request which, due to resource exhaustion, the server rejects +and pushes back, advertising `r=0` for the next 20 seconds. + +The server advertises a smaller window with a lower limit to slow +down the client for the rest of its original window after the 20 seconds elapse. + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 429 Too Many Requests +Content-Type: application/json +RateLimit-Policy: dynamic;l=15;w=20 +RateLimit: dynamic;r=0;t=20 + +{ + "status": 429, + "detail": "Wait 20 seconds, then slow down!" +} +~~~ + +## Dynamic limits for pushing back with Retry-After and slow down + +Alternatively, given the same context where the previous example starts, we +can convey the same information to the client via Retry-After, with +the advantage that the server can now specify the policy's nominal limit and +window that will apply after the reset, e.g. assuming the resource exhaustion +is likely to be gone by then, so the advertised policy does not need to be +adjusted, yet we managed to stop requests for a while and slow down the rest of +the current window. + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 429 Too Many Requests +Content-Type: application/json +Retry-After: 20 +RateLimit-Policy: dynamic;l=100;w=60 +RateLimit: dynamic;r=15;t=40 + +{ + "status": 429, + "detail": "Wait 20 seconds, then slow down!" +} +~~~ + +Note that in this last response the client is expected to honor +Retry-After and perform no requests for the specified amount of +time, whereas the previous example would not force the client to stop +requests before the reset time is elapsed, as it would still be free to +query again the server even if it is likely to have the request rejected. + +### Missing Remaining information + +The server does not expose remaining values +(for example, because the underlying counters are not available). +Instead, it resets the limit counter every second. + +It communicates to the client the limit of 10 quota units per second +always returning the limit and reset keywords. + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 200 Ok +Content-Type: application/json +RateLimit-Policy: quota;l=100;w=1 +RateLimit: quota;t=1 + +{"first": "request"} +~~~ + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 200 Ok +Content-Type: application/json +RateLimit-Policy: quota;l=10 +RateLimit: quota;t=1 + +{"second": "request"} +~~~ + +### Use with multiple windows + +This is a standardized way of describing the policy +detailed in {{use-with-multiple-policies}}: + +- 5000 daily quota units; +- 1000 hourly quota units. + +The client consumed 4900 quota units in the first 14 hours. + +Despite the next hourly limit of 1000 quota units, the closest limit +to reach is the daily one. + +The server then exposes the RateLimit header fields to inform the client that: + +- it has only 100 quota units left; +- the window will reset in 10 hours; +- the expiring-limit is 5000. + +Request: + +~~~ http-message +GET /items/123 HTTP/1.1 +Host: api.example + +~~~ + +Response: + +~~~ http-message +HTTP/1.1 200 OK +Content-Type: application/json +RateLimit-Policy: hour;l=1000;w=3600, day;l=5000;w=86400 +RateLimit: day;r=100;t=36000 + +{"hello": "world"} +~~~ + +# FAQ +{:numbered="false" removeinrfc="true"} + +1. Why defining standard fields for throttling? + + To simplify enforcement of throttling policies and enable clients to constraint their requests to avoid being throttled. + +2. Can I use RateLimit header fields in throttled responses (eg with status code 429)? + + Yes, you can. + +3. Are those specs tied to RFC 6585? + + No. {{?RFC6585}} defines the `429` status code and we use it just as an example of a throttled request, + that could instead use even `403` or whatever status code. + +4. Why is the partition key necessary? + + Without a partition key, a server can only effectively only have one scope (aka partition), which is impractical for most services, or it needs to communicate the scopes out-of-band. + This prevents the development of generic connector code that can be used to prevent requests from being throttled. + Many APIs rely on API keys, user identity or client identity to allocate quota. + As soon as a single client processes requests for more than one partition, the client needs to know the corresponding partition key to properly track requests against allocated quota. + +5. Why using delay-seconds instead of a UNIX Timestamp? + Why not using subsecond precision? + + Using delay-seconds aligns with Retry-After, which is returned in similar contexts, + eg on 429 responses. + + Timestamps require a clock synchronization protocol + (see {{Section 5.6.7 of HTTP}}). + This may be problematic (e.g. clock adjustment, clock skew, failure of hardcoded clock synchronization servers, + IoT devices, ..). + Moreover timestamps may not be monotonically increasing due to clock adjustment. + See [Another NTP client failure story](https://community.ntppool.org/t/another-ntp-client-failure-story/1014/) + + We did not use subsecond precision because: + + - that is more subject to system clock correction + like the one implemented via the adjtimex() Linux system call; + - response-time latency may not make it worth. A brief discussion on the subject is + on the [httpwg ml](https://lists.w3.org/Archives/Public/ietf-http-wg/2019JulSep/0202.html) + - almost all rate-limit headers implementations do not use it. + +6. Shouldn't I limit concurrency instead of request rate? + + You can use this specification to limit concurrency + at the HTTP level (see {#use-for-limiting-concurrency}) + and help clients to shape their requests avoiding being throttled out. + + A problematic way to limit concurrency is connection dropping, + especially when connections are multiplexed (e.g. HTTP/2) + because this results in unserviced client requests, + which is something we want to avoid. + + A semantic way to limit concurrency is to return 503 + Retry-After + in case of resource saturation (e.g. thrashing, connection queues too long, + Service Level Objectives not meet, ..). + Saturation conditions can be either dynamic or static: all this is out of + the scope for the current document. + +7. Do a positive value of remaining paramter imply any service guarantee for my + future requests to be served? + + No. FAQ integrated in {{ratelimit-remaining-parameter}}. + +8. Is the quota-policy definition {{quota-policy}} too complex? + + You can always return the simplest form + +~~~ +RateLimit:default;r=50;t=60 +~~~ + + The policy key clearly connects the current usage status of a policy to the defined limits. + So for the following field: + +~~~ +RateLimit-Policy: sliding;l=100;w=60;burst=1000;comment="sliding window", fixed;l=5000;w=3600;burst=0;comment="fixed window" +RateLimit: sliding;r=50;t=44 +~~~ + + the value "sliding" identifies the policy being reported. + +9. Can intermediaries alter RateLimit header fields? + + Generally, they should not because it might result in unserviced requests. + There are reasonable use cases for intermediaries mangling RateLimit header fields though, + e.g. when they enforce stricter quota-policies, + or when they are an active component of the service. + In those case we will consider them as part of the originating infrastructure. + +10. Why the `w` parameter is just informative? + Could it be used by a client to determine the request rate? + + A non-informative `w` parameter might be fine in an environment + where clients and servers are tightly coupled. Conveying policies + with this detail on a large scale would be very complex and implementations + would be likely not interoperable. We thus decided to leave `w` as + an informational parameter and only rely on the limit, remaining and reset keywords + for defining the throttling + behavior. + +11. Can I use RateLimit fields in trailers? + Servers usually establish whether the request is in-quota before creating a response, so the RateLimit field values should be already available in that moment. + Supporting trailers has the only advantage that allows to provide more up-to-date information to the client in case of slow responses. + However, this complicates client implementations with respect to combining fields from headers and accounting for intermediaries that drop trailers. + Since there are no current implementations that use trailers, we decided to leave this as a future-work. + +# RateLimit header fields currently used on the web +{:numbered="false" removeinrfc="true"} + +Commonly used header field names are: + +- `X-RateLimit-Limit`, + `X-RateLimit-Remaining`, + `X-RateLimit-Reset`; + +There are variants too, where the window is specified +in the header field name, eg: + +- `x-ratelimit-limit-minute`, `x-ratelimit-limit-hour`, `x-ratelimit-limit-day` +- `x-ratelimit-remaining-minute`, `x-ratelimit-remaining-hour`, `x-ratelimit-remaining-day` + +Here are some interoperability issues: + +- `X-RateLimit-Remaining` references different values, depending on the implementation: + + * seconds remaining to the window expiration + * milliseconds remaining to the window expiration + * seconds since UTC, in UNIX Timestamp [UNIX] + * a datetime, either `IMF-fixdate` {{HTTP}} or {{?RFC3339}} + +- different headers, with the same semantic, are used by different implementers: + + * X-RateLimit-Limit and X-Rate-Limit-Limit + * X-RateLimit-Remaining and X-Rate-Limit-Remaining + * X-RateLimit-Reset and X-Rate-Limit-Reset + +The semantic of RateLimit depends on the windowing algorithm. +A sliding window policy for example, may result in having a remaining keyword value related to the ratio between the current and the maximum throughput. +e.g. + +~~~ +RateLimit-Policy: sliding;l=12;w=1 +RateLimit: sliding;l=12;r=6;t=1 ; using 50% of throughput, that is 6 units/s + +~~~ + +If this is the case, the optimal solution is to achieve + +~~~ +RateLimit-Policy: sliding;l=12;w=1 +RateLimit: sliding;l=12;r=1;t=1 ; using 100% of throughput, that is 12 units/s +~~~ + +At this point you should stop increasing your request rate. + +# Acknowledgements +{:numbered="false"} + +Thanks to Willi Schoenborn, Alejandro Martinez Ruiz, Alessandro Ranellucci, +Amos Jeffries, +Martin Thomson, +Erik Wilde and Mark Nottingham for being the initial contributors +of these specifications. +Kudos to the first community implementers: +Aapo Talvensaari, +Nathan Friedly +and Sanyam Dogra. + +In addition to the people above, this document owes a lot to the extensive discussion in the HTTPAPI workgroup, including +Rich Salz, +Darrel Miller +and Julian Reschke. + +# Changes +{:numbered="false" removeinrfc="true"} + +## Since draft-ietf-httpapi-ratelimit-headers-07 +{:numbered="false" removeinrfc="true"} + +* Refactored both fields to lists of Items that identify policy and use parameters +* Added quota unit parameter +* Added partition key parameter + + +## Since draft-ietf-httpapi-ratelimit-headers-03 +{:numbered="false" removeinrfc="true"} + +* Split policy informatiom in RateLimit-Policy #81 + + +## Since draft-ietf-httpapi-ratelimit-headers-02 +{:numbered="false" removeinrfc="true"} + +* Address throttling scope #83 + +## Since draft-ietf-httpapi-ratelimit-headers-01 +{:numbered="false" removeinrfc="true"} + +* Update IANA considerations #60 +* Use Structured fields #58 +* Reorganize document #67 + +## Since draft-ietf-httpapi-ratelimit-headers-00 +{:numbered="false" removeinrfc="true"} + +* Use I-D.httpbis-semantics, which includes referencing delay-seconds + instead of delta-seconds. #5 diff --git a/draft-ietf-httpapi-ratelimit-headers.txt b/draft-ietf-httpapi-ratelimit-headers.txt new file mode 100644 index 0000000..1deaa44 --- /dev/null +++ b/draft-ietf-httpapi-ratelimit-headers.txt @@ -0,0 +1,1435 @@ + + + + +HTTPAPI R. Polli +Internet-Draft Team Digitale, Italian Government +Intended status: Standards Track A. Martinez +Expires: 2 April 2025 Red Hat + D. Miller + Microsoft + 29 September 2024 + + + RateLimit header fields for HTTP + draft-ietf-httpapi-ratelimit-headers-latest + +Abstract + + This document defines the RateLimit-Policy and RateLimit HTTP header + fields for servers to advertise their service policy limits and the + current limits, thereby allowing clients to avoid being throttled. + +About This Document + + This note is to be removed before publishing as an RFC. + + Status information for this document may be found at + https://datatracker.ietf.org/doc/draft-ietf-httpapi-ratelimit- + headers/. + + Discussion of this document takes place on the HTTPAPI Working Group + mailing list (mailto:httpapi@ietf.org), which is archived at + https://mailarchive.ietf.org/arch/browse/httpapi/. Subscribe at + https://www.ietf.org/mailman/listinfo/httpapi/. Working Group + information can be found at https://datatracker.ietf.org/wg/httpapi/ + about/. + + Source for this draft and an issue tracker can be found at + https://github.com/ietf-wg-httpapi/ratelimit-headers. + +Status of This Memo + + This Internet-Draft is submitted in full conformance with the + provisions of BCP 78 and BCP 79. + + Internet-Drafts are working documents of the Internet Engineering + Task Force (IETF). Note that other groups may also distribute + working documents as Internet-Drafts. The list of current Internet- + Drafts is at https://datatracker.ietf.org/drafts/current/. + + Internet-Drafts are draft documents valid for a maximum of six months + and may be updated, replaced, or obsoleted by other documents at any + time. It is inappropriate to use Internet-Drafts as reference + material or to cite them other than as "work in progress." + + This Internet-Draft will expire on 2 April 2025. + +Copyright Notice + + Copyright (c) 2024 IETF Trust and the persons identified as the + document authors. All rights reserved. + + This document is subject to BCP 78 and the IETF Trust's Legal + Provisions Relating to IETF Documents (https://trustee.ietf.org/ + license-info) in effect on the date of publication of this document. + Please review these documents carefully, as they describe your rights + and restrictions with respect to this document. Code Components + extracted from this document must include Revised BSD License text as + described in Section 4.e of the Trust Legal Provisions and are + provided without warranty as described in the Revised BSD License. + +Table of Contents + + 1. Introduction + 1.1. Goals + 1.2. Notational Conventions + 2. Terminology + 2.1. Quota + 2.2. Quota Unit + 2.3. Quota Partition + 2.4. Time Window + 2.5. Quota Policy + 2.6. Service Limit + 3. RateLimit-Policy Field + 3.1. Quota Policy Item + 3.1.1. Quota Parameter + 3.1.2. Quota Unit Parameter + 3.1.3. Window Parameter + 3.1.4. Partition Key Parameter + 3.2. RateLimit Policy Field Examples + 4. RateLimit Field + 4.1. Service Limit Item + 4.1.1. Remaining Parameter + 4.1.2. Reset Parameter + 4.1.3. Partition Key Parameter + 4.2. RateLimit Field Examples + 5. Server Behavior + 5.1. Performance Considerations + 6. Client Behavior + 6.1. Intermediaries + 6.2. Caching + 7. Security Considerations + 7.1. Throttling does not prevent clients from issuing requests + 7.2. Information disclosure + 7.3. Remaining quota units are not granted requests + 7.4. Reliability of the reset keyword + 7.5. Resource exhaustion + 7.5.1. Denial of Service + 8. Privacy Considerations + 9. IANA Considerations + 10. References + 10.1. Normative References + 10.2. Informative References + Appendix A. Rate-limiting and quotas + A.1. Interoperability issues + Appendix B. Examples + B.1. Responses without defining policies + B.1.1. Throttling information in responses + B.1.2. Multiple policies in response + B.1.3. Use for limiting concurrency + B.1.4. Use in throttled responses + B.2. Responses with defined policies + B.2.1. Throttling window specified via parameter + B.2.2. Dynamic limits with parameterized windows + B.2.3. Dynamic limits for pushing back and slowing down + B.3. Dynamic limits for pushing back with Retry-After and slow + down + B.3.1. Missing Remaining information + B.3.2. Use with multiple windows + FAQ + RateLimit header fields currently used on the web + Acknowledgements + Changes + Since draft-ietf-httpapi-ratelimit-headers-07 + Since draft-ietf-httpapi-ratelimit-headers-03 + Since draft-ietf-httpapi-ratelimit-headers-02 + Since draft-ietf-httpapi-ratelimit-headers-01 + Since draft-ietf-httpapi-ratelimit-headers-00 + Authors' Addresses + +1. Introduction + + Rate limiting of HTTP clients has become a widespread practice, + especially for HTTP APIs. Typically, servers who do so limit the + number of acceptable requests in a given time window (e.g. 10 + requests per second). See Appendix A for further information on the + current usage of rate limiting in HTTP. + + Currently, there is no standard way for servers to communicate quotas + so that clients can throttle their requests to prevent errors. This + document defines a set of standard HTTP header fields to enable rate + limiting: + + * RateLimit: to convey the server's current limit of quota units + available to the client in the policy time window, the remaining + quota units in the current window, and the time remaining in the + current window, specified in seconds, and + + * RateLimit-Policy: the service policy limits. + + These fields enable establishing complex rate limiting policies, + including using multiple and variable time windows and dynamic + quotas, and implementing concurrency limits. + + The behavior of the RateLimit header field is compatible with the + delay-seconds notation of Retry-After. + +1.1. Goals + + The goals of this document are: + + Interoperability: Standardize the names and semantics of rate-limit + headers to ease their enforcement and adoption; + + Resiliency: Improve resiliency of HTTP infrastructure by providing + clients with information useful to throttle their requests and + prevent 4xx or 5xx responses; + + Documentation: Simplify API documentation by eliminating the need to + include detailed quota limits and related fields in API + documentation. + + The following features are out of the scope of this document: + + Authorization: RateLimit header fields are not meant to support + authorization or other kinds of access controls. + + Response status code: RateLimit header fields may be returned in + both successful (see Section 15.3 of [HTTP]) and non-successful + responses. This specification does not cover whether non + Successful responses count on quota usage, nor does it mandates + any correlation between the RateLimit values and the returned + status code. + + Throttling algorithm: This specification does not mandate a specific + throttling algorithm. The values published in the fields, + including the window size, can be statically or dynamically + evaluated. + + Service Level Agreement: Conveyed quota hints do not imply any + service guarantee. Server is free to throttle respectful clients + under certain circumstances. + +1.2. Notational Conventions + + The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", + "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and + "OPTIONAL" in this document are to be interpreted as described in + BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all + capitals, as shown here. + + The term Origin is to be interpreted as described in Section 7 of + [WEB-ORIGIN]. + + This document uses the terms List, Item and Integer from Section 3 of + [STRUCTURED-FIELDS] to specify syntax and parsing, along with the + concept of "bare item". + +2. Terminology + +2.1. Quota + + A quota is an allocation of capacity to enable a server to limit + client requests. That capacity is counted in quota units and may be + reallocated at the end of a time window Section 2.4. + +2.2. Quota Unit + + A quota unit is the unit of measure used to count the activity of a + client. + +2.3. Quota Partition + + A quota partition is a division of a server's capacity across + different clients, users and owned resources. + +2.4. Time Window + + A time window indicates a period of time associated to the allocated + quota. + + The time window is a non-negative Integer value expressing an + interval in seconds, similar to the "delay-seconds" rule defined in + Section 10.2.3 of [HTTP]. Sub-second precision is not supported. + +2.5. Quota Policy + + A quota policy is maintained by a server to limit the activity + (counted in quota units (Section 2.2)) of a given quota partition + (Section 2.3) over a period of time (known as the time window + (Section 2.4)) to a specified amount known as the Section 2.1. + + Quota policies can be advertised by servers (see Section 3), but they + are not required to be, and more than one quota policy can affect a + given request from a client to a server. + +2.6. Service Limit + + A service limit is the current limit of the amount of activity that a + server will allow based on the remaining quota for a particular quota + partition within the time-window, if defined. + +3. RateLimit-Policy Field + + The "RateLimit-Policy" response header field is a non-empty List of + Section 3.1. Its value is informative. The values are expected to + remain consistent over a the lifetime of a connection. It is this + characteristic that differentiates it from the RateLimit (Section 4) + that contains values that may change on every request. + + RateLimit-Policy: burst;q=100;w=60,daily;q=1000;w=86400 + +3.1. Quota Policy Item + + A quota policy Item contains information about a server's capacity + allocation for a quota partition associated with the request. + + The following parameters are defined in this specification: + + q: The REQUIRED "q" parameter indicates the quota allocated. + (Section 3.1.1) + + qu: The OPTIONAL "qu" parameter value conveys the quota units + associated to the "q" parameter. The default quota unit is + "request". (Section 3.1.2) + + w: The OPTIONAL "w" parameter value conveys a time "window" + (Section 2.4). (Section 3.1.3) + + pk: The OPTIONAL "pk" parameter value conveys the partition key + associated to the corresponding request. Section 3.1.4 + + Other parameters are allowed and can be regarded as comments. + + Implementation- or service-specific parameters SHOULD be prefixed + parameters with a vendor identifier, e.g. acme-policy, acme-burst. + +3.1.1. Quota Parameter + + The "q" parameter uses a non-negative integer value to indicate the + quota allocated for client activity (counted in quota units) for a + given quota partition (Section 2.6). + +3.1.2. Quota Unit Parameter + + The "qu" parameter value conveys the quota units associated to the + "q" parameter. + +3.1.3. Window Parameter + + The "w" parameter value conveys a time "window" in seconds. + (Section 2.4). + +3.1.4. Partition Key Parameter + + The "pk" parameter value conveys the partition key associated to the + request. Servers MAY use the partition key to divide server capacity + across different clients and resources. Quotas are allocated per + partition key. + +3.2. RateLimit Policy Field Examples + + This field MAY convey the time window associated with the expiring- + limit, as shown in this example: + + RateLimit-Policy: default;l=100;w=10 + + These examples show multiple policies being returned: + + RateLimit-Policy: permin;l=50;w=60,perhr;l=1000;w=3600,perday;l=5000;w=86400 + + The following example shows a policy with a partition key: + + RateLimit-Policy: peruser;l=100;w=60;pk=user123 + + The following example shows a policy with a partition key and a quota + unit: + + RateLimit-Policy: peruser;l=65535;w=10;pk=user123;qu=bytes + + This field cannot appear in a trailer section. + +4. RateLimit Field + + A server uses the "RateLimit" response header field to communicate + the service limit for a quota policy for a particular partition key. + + The field is expressed as List of Section 4.1. + + RateLimit: default;r=50;t=30 + +4.1. Service Limit Item + + Each service limit item in identifies the quota policy associated + with the request and + + The following parameters are defined in this specification: + + r: This parameter value conveys the remaining quota units for the + identified policy (Section 4.1.1). + + t: This OPTIONAL parameter value conveys the time window reset time + for the identified policy (Section 4.1.2). + + pk: The OPTIONAL "pk" parameter value conveys the partition key + associated to the corresponding request. + + This field cannot appear in a trailer section. Other parameters are + allowed and can be regarded as comments. + + Implementation- or service-specific parameters SHOULD be prefixed + parameters with a vendor identifier, e.g. acme-policy, acme-burst. + +4.1.1. Remaining Parameter + + The "r" parameter indicates the remaining quota units for the + identified policy (Section 4.1.1). + + It is a non-negative Integer expressed in quota units (Section 2.2). + Clients MUST NOT assume that a positive remaining value is a + guarantee that further requests will be served. When remaining + parameter value is low, it indicates that the server may soon + throttle the client (see Section 5). + +4.1.2. Reset Parameter + + The "t" parameter indicates the number of seconds until the quota + associated with the quota policy resets. + + It is a non-negative Integer compatible with the delay-seconds rule, + because: + + * it does not rely on clock synchronization and is resilient to + clock adjustment and clock skew between client and server (see + Section 5.6.7 of [HTTP]); + + * it mitigates the risk related to thundering herd when too many + clients are serviced with the same timestamp. + + The client MUST NOT assume that all its service limit will be reset + at the moment indicated by the reset keyword. The server MAY + arbitrarily alter the reset parameter value between subsequent + requests; for example, in case of resource saturation or to implement + sliding window policies. + +4.1.3. Partition Key Parameter + + The "pk" parameter value conveys the partition key associated to the + request. Servers MAY use the partition key to divide server capacity + across different clients and resources. Quotas are allocated per + partition key. + +4.2. RateLimit Field Examples + + This example shows a RateLimit field with a remaining quota of 50 + units and a time window reset in 30 seconds: + + RateLimit: default;r=50;t=30 + + This example shows a remaining quota of 999 requests for a partition + key that has no time window reset: + + RateLimit: default;r=999;pk=trial-121323 + + This example shows a 300MB remaining quota for an application in the + next 60 seconds: + + RateLimit: default;r=300000000;pk=App-999;t=60;qu=bytes + +5. Server Behavior + + A server MAY return RateLimit header fields independently of the + response status code. This includes on throttled responses. This + document does not mandate any correlation between the RateLimit + header field values and the returned status code. + + Servers should be careful when returning RateLimit header fields in + redirection responses (i.e., responses with 3xx status codes) because + a low remaining keyword value could prevent the client from issuing + requests. For example, given the RateLimit header fields below, a + client could decide to wait 10 seconds before following the + "Location" header field (see Section 10.2.2 of [HTTP]), because the + remaining keyword value is 0. + + HTTP/1.1 301 Moved Permanently + Location: /foo/123 + RateLimit: problemPolicy;r=0, t=10 + + If a response contains both the Retry-After and the RateLimit header + fields, the reset keyword value SHOULD reference the same point in + time as the Retry-After field value. + + A service using RateLimit header fields MUST NOT convey values + exposing an unwanted volume of requests and SHOULD implement + mechanisms to cap the ratio between the remaining and the reset + keyword values (see Section 7.5); this is especially important when a + quota policy uses a large time window. + + Under certain conditions, a server MAY artificially lower RateLimit + header field values between subsequent requests, e.g. to respond to + Denial of Service attacks or in case of resource saturation. + +5.1. Performance Considerations + + Servers are not required to return RateLimit header fields in every + response, and clients need to take this into account. For example, + an implementer concerned with performance might provide RateLimit + header fields only when a given quota is close to exhaustion. + + Implementers concerned with response fields' size, might take into + account their ratio with respect to the content length, or use + header-compression HTTP features such as [HPACK]. + +6. Client Behavior + + The RateLimit header fields can be used by clients to determine + whether the associated request respected the server's quota policy, + and as an indication of whether subsequent requests will. However, + the server might apply other criteria when servicing future requests, + and so the quota policy may not completely reflect whether requests + will succeed. + + For example, a successful response with the following fields: + + RateLimit: default;r=1;t=7 + + does not guarantee that the next request will be successful. + Servers' behavior may be subject to other conditions. + + A client is responsible for ensuring that RateLimit header field + values returned cause reasonable client behavior with respect to + throughput and latency (see Section 7.5 and Section 7.5.1). + + A client receiving RateLimit header fields MUST NOT assume that + future responses will contain the same RateLimit header fields, or + any RateLimit header fields at all. + + Malformed RateLimit header fields MUST be ignored. + + A client SHOULD NOT exceed the quota units conveyed by the remaining + keyword before the time window expressed in the reset keyword. + + The value of the reset keyword is generated at response time: a + client aware of a significant network latency MAY behave accordingly + and use other information (e.g. the "Date" response header field, or + otherwise gathered metrics) to better estimate the reset keyword + moment intended by the server. + + The details provided in the RateLimit-Policy header field are + informative and MAY be ignored. + + If a response contains both the RateLimit and Retry-After fields, the + Retry-After field MUST take precedence and the reset keyword MAY be + ignored. + + This specification does not mandate a specific throttling behavior + and implementers can adopt their preferred policies, including: + + * slowing down or pre-emptively back-off their request rate when + approaching quota limits; + + * consuming all the quota according to the exposed limits and then + wait. + +6.1. Intermediaries + + This section documents the considerations advised in Section 16.3.2 + of [HTTP]. + + An intermediary that is not part of the originating service + infrastructure and is not aware of the quota policy semantic used by + the Origin Server SHOULD NOT alter the RateLimit header fields' + values in such a way as to communicate a more permissive quota + policy; this includes removing the RateLimit header fields. + + An intermediary MAY alter the RateLimit header fields in such a way + as to communicate a more restrictive quota policy when: + + * it is aware of the quota unit semantic used by the Origin Server; + + * it implements this specification and enforces a quota policy which + is more restrictive than the one conveyed in the fields. + + An intermediary SHOULD forward a request even when presuming that it + might not be serviced; the service returning the RateLimit header + fields is the sole responsible of enforcing the communicated quota + policy, and it is always free to service incoming requests. + + This specification does not mandate any behavior on intermediaries + respect to retries, nor requires that intermediaries have any role in + respecting quota policies. For example, it is legitimate for a proxy + to retransmit a request without notifying the client, and thus + consuming quota units. + + Privacy considerations (Section 8) provide further guidance on + intermediaries. + +6.2. Caching + + [HTTP-CACHING] defines how responses can be stored and reused for + subsequent requests, including those with RateLimit header fields. + Because the information in RateLimit header fields on a cached + response may not be current, they SHOULD be ignored on responses that + come from cache (i.e., those with a positive current_age; see + Section 4.2.3 of [HTTP-CACHING]). + +7. Security Considerations + +7.1. Throttling does not prevent clients from issuing requests + + This specification does not prevent clients from making requests. + Servers should always implement mechanisms to prevent resource + exhaustion. + +7.2. Information disclosure + + Servers should not disclose to untrusted parties operational capacity + information that can be used to saturate its infrastructural + resources. + + While this specification does not mandate whether non-successful + responses consume quota, if error responses (such as 401 + (Unauthorized) and 403 (Forbidden)) count against quota, a malicious + client could probe the endpoint to get traffic information of another + user. + + As intermediaries might retransmit requests and consume quota units + without prior knowledge of the user agent, RateLimit header fields + might reveal the existence of an intermediary to the user agent. + + Where partition keys contain identifying information, either of the + client application or the user, servers should be aware of the + potential for impersonation and apply the appropriate security + mechanisms. + +7.3. Remaining quota units are not granted requests + + RateLimit header fields convey hints from the server to the clients + in order to help them avoid being throttled out. + + Clients MUST NOT consider the quota units (Section 2.6) returned in + remaining keyword as a service level agreement. + + In case of resource saturation, the server MAY artificially lower the + returned values or not serve the request regardless of the advertised + quotas. + +7.4. Reliability of the reset keyword + + Consider that quota might not be restored after the moment referenced + by the reset keyword (Section 4.1.2), and the reset parameter value + may not be constant. + + Subsequent requests might return a higher reset parameter value to + limit concurrency or implement dynamic or adaptive throttling + policies. + +7.5. Resource exhaustion + + When returning reset values, servers must be aware that many + throttled clients may come back at the very moment specified. + + This is true for Retry-After too. + + For example, if the quota resets every day at 18:00:00 and your + server returns the reset parameter accordingly + + Date: Tue, 15 Nov 1994 18:00:00 GMT + RateLimit: daily;r=1;t=36400 + + there's a high probability that all clients will show up at 18:00:00. + + This could be mitigated by adding some jitter to the reset value. + + Resource exhaustion issues can be associated with quota policies + using a large time window, because a user agent by chance or on + purpose might consume most of its quota units in a significantly + shorter interval. + + This behavior can be even triggered by the provided RateLimit header + fields. The following example describes a service with an unconsumed + quota policy of 10000 quota units per 1000 seconds. + + RateLimit-Policy: somepolicy;l=10000;w=1000 + RateLimit: somepolicy;r=10000;t=10 + + A client implementing a simple ratio between remaining keyword and + reset keyword could infer an average throughput of 1000 quota units + per second, while the limit keyword conveys a quota-policy with an + average of 10 quota units per second. If the service cannot handle + such load, it should return either a lower remaining keyword value or + an higher reset keyword value. Moreover, complementing large time + window quota policies with a short time window one mitigates those + risks. + +7.5.1. Denial of Service + + RateLimit header fields may contain unexpected values by chance or on + purpose. For example, an excessively high remaining keyword value + may be: + + * used by a malicious intermediary to trigger a Denial of Service + attack or consume client resources boosting its requests; + + * passed by a misconfigured server; + + or a high reset keyword value could inhibit clients to contact the + server (e.g. similarly to receiving "Retry-after: 1000000"). + + To mitigate this risk, clients can set thresholds that they consider + reasonable in terms of quota units, time window, concurrent requests + or throughput, and define a consistent behavior when the RateLimit + exceed those thresholds. For example this means capping the maximum + number of request per second, or implementing retries when the reset + keyword exceeds ten minutes. + + The considerations above are not limited to RateLimit header fields, + but apply to all fields affecting how clients behave in subsequent + requests (e.g. Retry-After). + +8. Privacy Considerations + + Clients that act upon a request to rate limit are potentially re- + identifiable (see Section 5.2.1 of [PRIVACY]) because they react to + information that might only be given to them. Note that this might + apply to other fields too (e.g. Retry-After). + + Since rate limiting is usually implemented in contexts where clients + are either identified or profiled (e.g. assigning different quota + units to different users), this is rarely a concern. + + Privacy enhancing infrastructures using RateLimit header fields can + define specific techniques to mitigate the risks of re- + identification. + +9. IANA Considerations + + IANA is requested to update one registry and create one new registry. + + Please add the following entries to the "Hypertext Transfer Protocol + (HTTP) Field Name Registry" registry ([HTTP]): + + +==================+===========+=======================+ + | Field Name | Status | Specification | + +==================+===========+=======================+ + | RateLimit | permanent | Section 4 of RFC nnnn | + +------------------+-----------+-----------------------+ + | RateLimit-Policy | permanent | Section 3 of RFC nnnn | + +------------------+-----------+-----------------------+ + + Table 1 + +10. References + +10.1. Normative References + + [HTTP] Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, + Ed., "HTTP Semantics", STD 97, RFC 9110, + DOI 10.17487/RFC9110, June 2022, + . + + [IANA] Cotton, M., Leiba, B., and T. Narten, "Guidelines for + Writing an IANA Considerations Section in RFCs", BCP 26, + RFC 8126, DOI 10.17487/RFC8126, June 2017, + . + + [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate + Requirement Levels", BCP 14, RFC 2119, + DOI 10.17487/RFC2119, March 1997, + . + + [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC + 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, + May 2017, . + + [STRUCTURED-FIELDS] + Nottingham, M. and P. Kamp, "Structured Field Values for + HTTP", RFC 8941, DOI 10.17487/RFC8941, February 2021, + . + + [WEB-ORIGIN] + Barth, A., "The Web Origin Concept", RFC 6454, + DOI 10.17487/RFC6454, December 2011, + . + +10.2. Informative References + + [HPACK] Peon, R. and H. Ruellan, "HPACK: Header Compression for + HTTP/2", RFC 7541, DOI 10.17487/RFC7541, May 2015, + . + + [HTTP-CACHING] + Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, + Ed., "HTTP Caching", STD 98, RFC 9111, + DOI 10.17487/RFC9111, June 2022, + . + + [PRIVACY] Cooper, A., Tschofenig, H., Aboba, B., Peterson, J., + Morris, J., Hansen, M., and R. Smith, "Privacy + Considerations for Internet Protocols", RFC 6973, + DOI 10.17487/RFC6973, July 2013, + . + + [RFC3339] Klyne, G. and C. Newman, "Date and Time on the Internet: + Timestamps", RFC 3339, DOI 10.17487/RFC3339, July 2002, + . + + [RFC6585] Nottingham, M. and R. Fielding, "Additional HTTP Status + Codes", RFC 6585, DOI 10.17487/RFC6585, April 2012, + . + + [UNIX] The Open Group, "The Single UNIX Specification, Version 2 + - 6 Vol Set for UNIX 98", February 1997. + +Appendix A. Rate-limiting and quotas + + Servers use quota mechanisms to avoid systems overload, to ensure an + equitable distribution of computational resources or to enforce other + policies - e.g. monetization. + + A basic quota mechanism limits the number of acceptable requests in a + given time window, e.g. 10 requests per second. + + When quota is exceeded, servers usually do not serve the request + replying instead with a 4xx HTTP status code (e.g. 429 or 403) or + adopt more aggressive policies like dropping connections. + + Quotas may be enforced on different basis (e.g. per user, per IP, per + geographic area, ..) and at different levels. For example, an user + may be allowed to issue: + + * 10 requests per second; + + * limited to 60 requests per minute; + + * limited to 1000 requests per hour. + + Moreover system metrics, statistics and heuristics can be used to + implement more complex policies, where the number of acceptable + requests and the time window are computed dynamically. + + To help clients throttling their requests, servers may expose the + counters used to evaluate quota policies via HTTP header fields. + + Those response headers may be added by HTTP intermediaries such as + API gateways and reverse proxies. + + On the web we can find many different rate-limit headers, usually + containing the number of allowed requests in a given time window, and + when the window is reset. + + The common choice is to return three headers containing: + + * the maximum number of allowed requests in the time window; + + * the number of remaining requests in the current window; + + * the time remaining in the current window expressed in seconds or + as a timestamp; + +A.1. Interoperability issues + + A major interoperability issue in throttling is the lack of standard + headers, because: + + * each implementation associates different semantics to the same + header field names; + + * header field names proliferates. + + User agents interfacing with different servers may thus need to + process different headers, or the very same application interface + that sits behind different reverse proxies may reply with different + throttling headers. + +Appendix B. Examples + +B.1. Responses without defining policies + + Some servers may not expose the policy limits in the RateLimit-Policy + header field. Clients can still use the RateLimit header field to + throttle their requests. + +B.1.1. Throttling information in responses + + The client exhausted its quota for the next 50 seconds. The limit + and time-window is communicated out-of-band. + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 200 Ok + Content-Type: application/json + RateLimit: default;r=0;t=50 + + {"hello": "world"} + + Since the field values are not necessarily correlated with the + response status code, a subsequent request is not required to fail. + The example below shows that the server decided to serve the request + even if remaining keyword value is 0. Another server, or the same + server under other load conditions, could have decided to throttle + the request instead. + + Request: + + GET /items/456 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 200 Ok + Content-Type: application/json + RateLimit: default;r=0;t=48 + + {"still": "successful"} + +B.1.2. Multiple policies in response + + The server uses two different policies to limit the client's + requests: + + * 5000 daily quota units; + + * 1000 hourly quota units. + + The client consumed 4900 quota units in the first 14 hours. + + Despite the next hourly limit of 1000 quota units, the closest limit + to reach is the daily one. + + The server then exposes the RateLimit header fields to inform the + client that: + + * it has only 100 quota units left in the daily quota and the window + will reset in 10 hours; + + The server MAY choose to omit returning the hourly policy as it uses + the same quota units as the daily policy and the daily policy is the + one that is closest to being exhausted. + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 200 Ok + Content-Type: application/json + RateLimit: dayLimit;r=100;t=36000 + + {"hello": "world"} + +B.1.3. Use for limiting concurrency + + RateLimit header fields may be used to limit concurrency, advertising + limits that are lower than the usual ones in case of saturation, thus + increasing availability. + + The server adopted a basic policy of 100 quota units per minute, and + in case of resource exhaustion adapts the returned values reducing + both limit and remaining keyword values. + + After 2 seconds the client consumed 40 quota units + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 200 Ok + Content-Type: application/json + RateLimit-Policy: basic;l=100;w=60 + RateLimit: basic;r=60;t=58 + + {"elapsed": 2, "issued": 40} + + At the subsequent request - due to resource exhaustion - the server + advertises only r=20. + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 200 Ok + Content-Type: application/json + RateLimit-Policy: basic;l=100;w=60 + RateLimit: basic;r=20;t=56 + + {"elapsed": 4, "issued": 41} + +B.1.4. Use in throttled responses + + A client exhausted its quota and the server throttles it sending + Retry-After. + + In this example, the values of Retry-After and RateLimit header field + reference the same moment, but this is not a requirement. + + The 429 (Too Many Request) HTTP status code is just used as an + example. + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 429 Too Many Requests + Content-Type: application/json + Date: Mon, 05 Aug 2019 09:27:00 GMT + Retry-After: Mon, 05 Aug 2019 09:27:05 GMT + RateLimit: default;r=0;t=5 + + { + "title": "Too Many Requests", + "status": 429, + "detail": "You have exceeded your quota" + } + +B.2. Responses with defined policies + +B.2.1. Throttling window specified via parameter + + The client has 99 quota units left for the next 50 seconds. The time + window is communicated by the w parameter, so we know the throughput + is 100 quota units per minute. + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 200 Ok + Content-Type: application/json + RateLimit: fixedwindow;r=99;t=50 + RateLimit-Policy: fixedwindow;l=100;w=60 + {"hello": "world"} + +B.2.2. Dynamic limits with parameterized windows + + The policy conveyed by the RateLimit header field states that the + server accepts 100 quota units per minute. + + To avoid resource exhaustion, the server artificially lowers the + actual limits returned in the throttling headers. + + The remaining keyword then advertises only 9 quota units for the next + 50 seconds to slow down the client. + + Note that the server could have lowered even the other values in the + RateLimit header field: this specification does not mandate any + relation between the field values contained in subsequent responses. + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 200 Ok + Content-Type: application/json + RateLimit-Policy: dynamic;l=100;w=60 + RateLimit: dynamic;r=9;t=50 + + + { + "status": 200, + "detail": "Just slow down without waiting." + } + +B.2.3. Dynamic limits for pushing back and slowing down + + Continuing the previous example, let's say the client waits 10 + seconds and performs a new request which, due to resource exhaustion, + the server rejects and pushes back, advertising r=0 for the next 20 + seconds. + + The server advertises a smaller window with a lower limit to slow + down the client for the rest of its original window after the 20 + seconds elapse. + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 429 Too Many Requests + Content-Type: application/json + RateLimit-Policy: dynamic;l=15;w=20 + RateLimit: dynamic;r=0;t=20 + + { + "status": 429, + "detail": "Wait 20 seconds, then slow down!" + } + +B.3. Dynamic limits for pushing back with Retry-After and slow down + + Alternatively, given the same context where the previous example + starts, we can convey the same information to the client via Retry- + After, with the advantage that the server can now specify the + policy's nominal limit and window that will apply after the reset, + e.g. assuming the resource exhaustion is likely to be gone by then, + so the advertised policy does not need to be adjusted, yet we managed + to stop requests for a while and slow down the rest of the current + window. + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 429 Too Many Requests + Content-Type: application/json + Retry-After: 20 + RateLimit-Policy: dynamic;l=100;w=60 + RateLimit: dynamic;r=15;t=40 + + { + "status": 429, + "detail": "Wait 20 seconds, then slow down!" + } + + Note that in this last response the client is expected to honor + Retry-After and perform no requests for the specified amount of time, + whereas the previous example would not force the client to stop + requests before the reset time is elapsed, as it would still be free + to query again the server even if it is likely to have the request + rejected. + +B.3.1. Missing Remaining information + + The server does not expose remaining values (for example, because the + underlying counters are not available). Instead, it resets the limit + counter every second. + + It communicates to the client the limit of 10 quota units per second + always returning the limit and reset keywords. + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 200 Ok + Content-Type: application/json + RateLimit-Policy: quota;l=100;w=1 + RateLimit: quota;t=1 + + {"first": "request"} + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 200 Ok + Content-Type: application/json + RateLimit-Policy: quota;l=10 + RateLimit: quota;t=1 + + {"second": "request"} + +B.3.2. Use with multiple windows + + This is a standardized way of describing the policy detailed in + Appendix B.1.2: + + * 5000 daily quota units; + + * 1000 hourly quota units. + + The client consumed 4900 quota units in the first 14 hours. + + Despite the next hourly limit of 1000 quota units, the closest limit + to reach is the daily one. + + The server then exposes the RateLimit header fields to inform the + client that: + + * it has only 100 quota units left; + + * the window will reset in 10 hours; + + * the expiring-limit is 5000. + + Request: + + GET /items/123 HTTP/1.1 + Host: api.example + + Response: + + HTTP/1.1 200 OK + Content-Type: application/json + RateLimit-Policy: hour;l=1000;w=3600, day;l=5000;w=86400 + RateLimit: day;r=100;t=36000 + + {"hello": "world"} + +FAQ + + This section is to be removed before publishing as an RFC. + + 1. Why defining standard fields for throttling? + + To simplify enforcement of throttling policies and enable clients + to constraint their requests to avoid being throttled. + + 2. Can I use RateLimit header fields in throttled responses (eg with + status code 429)? + + Yes, you can. + + 3. Are those specs tied to RFC 6585? + + No. [RFC6585] defines the 429 status code and we use it just as + an example of a throttled request, that could instead use even + 403 or whatever status code. + + 4. Why is the partition key necessary? + + Without a partition key, a server can only effectively only have + one scope (aka partition), which is impractical for most + services, or it needs to communicate the scopes out-of-band. + This prevents the development of generic connector code that can + be used to prevent requests from being throttled. Many APIs rely + on API keys, user identity or client identity to allocate quota. + As soon as a single client processes requests for more than one + partition, the client needs to know the corresponding partition + key to properly track requests against allocated quota. + + 5. Why using delay-seconds instead of a UNIX Timestamp? Why not + using subsecond precision? + + Using delay-seconds aligns with Retry-After, which is returned in + similar contexts, eg on 429 responses. + + Timestamps require a clock synchronization protocol (see + Section 5.6.7 of [HTTP]). This may be problematic (e.g. clock + adjustment, clock skew, failure of hardcoded clock + synchronization servers, IoT devices, ..). Moreover timestamps + may not be monotonically increasing due to clock adjustment. See + Another NTP client failure story + (https://community.ntppool.org/t/another-ntp-client-failure- + story/1014/) + + We did not use subsecond precision because: + + * that is more subject to system clock correction like the one + implemented via the adjtimex() Linux system call; + + * response-time latency may not make it worth. A brief + discussion on the subject is on the httpwg ml + (https://lists.w3.org/Archives/Public/ietf-http- + wg/2019JulSep/0202.html) + + * almost all rate-limit headers implementations do not use it. + + 6. Shouldn't I limit concurrency instead of request rate? + + You can use this specification to limit concurrency at the HTTP + level (see {#use-for-limiting-concurrency}) and help clients to + shape their requests avoiding being throttled out. + + A problematic way to limit concurrency is connection dropping, + especially when connections are multiplexed (e.g. HTTP/2) + because this results in unserviced client requests, which is + something we want to avoid. + + A semantic way to limit concurrency is to return 503 + Retry- + After in case of resource saturation (e.g. thrashing, connection + queues too long, Service Level Objectives not meet, ..). + Saturation conditions can be either dynamic or static: all this + is out of the scope for the current document. + + 7. Do a positive value of remaining paramter imply any service + guarantee for my future requests to be served? + + No. FAQ integrated in Section 4.1.1. + + 8. Is the quota-policy definition Section 2.5 too complex? + + You can always return the simplest form + + RateLimit:default;r=50;t=60 + + The policy key clearly connects the current usage status of a policy + to the defined limits. So for the following field: + +RateLimit-Policy: sliding;l=100;w=60;burst=1000;comment="sliding window", fixed;l=5000;w=3600;burst=0;comment="fixed window" +RateLimit: sliding;r=50;t=44 + + the value "sliding" identifies the policy being reported. + + 1. Can intermediaries alter RateLimit header fields? + + Generally, they should not because it might result in unserviced + requests. There are reasonable use cases for intermediaries + mangling RateLimit header fields though, e.g. when they enforce + stricter quota-policies, or when they are an active component of + the service. In those case we will consider them as part of the + originating infrastructure. + + 2. Why the w parameter is just informative? Could it be used by a + client to determine the request rate? + + A non-informative w parameter might be fine in an environment + where clients and servers are tightly coupled. Conveying + policies with this detail on a large scale would be very complex + and implementations would be likely not interoperable. We thus + decided to leave w as an informational parameter and only rely on + the limit, remaining and reset keywords for defining the + throttling behavior. + + 3. Can I use RateLimit fields in trailers? Servers usually + establish whether the request is in-quota before creating a + response, so the RateLimit field values should be already + available in that moment. Supporting trailers has the only + advantage that allows to provide more up-to-date information to + the client in case of slow responses. However, this complicates + client implementations with respect to combining fields from + headers and accounting for intermediaries that drop trailers. + Since there are no current implementations that use trailers, we + decided to leave this as a future-work. + +RateLimit header fields currently used on the web + + This section is to be removed before publishing as an RFC. + + Commonly used header field names are: + + * X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset; + + There are variants too, where the window is specified in the header + field name, eg: + + * x-ratelimit-limit-minute, x-ratelimit-limit-hour, x-ratelimit- + limit-day + + * x-ratelimit-remaining-minute, x-ratelimit-remaining-hour, x- + ratelimit-remaining-day + + Here are some interoperability issues: + + * X-RateLimit-Remaining references different values, depending on + the implementation: + + - seconds remaining to the window expiration + + - milliseconds remaining to the window expiration + + - seconds since UTC, in UNIX Timestamp [UNIX] + + - a datetime, either IMF-fixdate [HTTP] or [RFC3339] + + * different headers, with the same semantic, are used by different + implementers: + + - X-RateLimit-Limit and X-Rate-Limit-Limit + + - X-RateLimit-Remaining and X-Rate-Limit-Remaining + + - X-RateLimit-Reset and X-Rate-Limit-Reset + + The semantic of RateLimit depends on the windowing algorithm. A + sliding window policy for example, may result in having a remaining + keyword value related to the ratio between the current and the + maximum throughput. e.g. + +RateLimit-Policy: sliding;l=12;w=1 +RateLimit: sliding;l=12;r=6;t=1 ; using 50% of throughput, that is 6 units/s + + If this is the case, the optimal solution is to achieve + +RateLimit-Policy: sliding;l=12;w=1 +RateLimit: sliding;l=12;r=1;t=1 ; using 100% of throughput, that is 12 units/s + + At this point you should stop increasing your request rate. + +Acknowledgements + + Thanks to Willi Schoenborn, Alejandro Martinez Ruiz, Alessandro + Ranellucci, Amos Jeffries, Martin Thomson, Erik Wilde and Mark + Nottingham for being the initial contributors of these + specifications. Kudos to the first community implementers: Aapo + Talvensaari, Nathan Friedly and Sanyam Dogra. + + In addition to the people above, this document owes a lot to the + extensive discussion in the HTTPAPI workgroup, including Rich Salz, + Darrel Miller and Julian Reschke. + +Changes + + This section is to be removed before publishing as an RFC. + +Since draft-ietf-httpapi-ratelimit-headers-07 + + This section is to be removed before publishing as an RFC. + + * Refactored both fields to lists of Items that identify policy and + use parameters + + * Added quota unit parameter + + * Added partition key parameter + +Since draft-ietf-httpapi-ratelimit-headers-03 + + This section is to be removed before publishing as an RFC. + + * Split policy informatiom in RateLimit-Policy #81 + +Since draft-ietf-httpapi-ratelimit-headers-02 + + This section is to be removed before publishing as an RFC. + + * Address throttling scope #83 + +Since draft-ietf-httpapi-ratelimit-headers-01 + + This section is to be removed before publishing as an RFC. + + * Update IANA considerations #60 + + * Use Structured fields #58 + + * Reorganize document #67 + +Since draft-ietf-httpapi-ratelimit-headers-00 + + This section is to be removed before publishing as an RFC. + + * Use I-D.httpbis-semantics, which includes referencing delay- + seconds instead of delta-seconds. #5 + +Authors' Addresses + + Roberto Polli + Team Digitale, Italian Government + Italy + Email: robipolli@gmail.com + + + Alejandro Martinez Ruiz + Red Hat + Email: alex@flawedcode.org + + + Darrel Miller + Microsoft + Email: darrel@tavis.ca From c9d03f7e324c4fc8b2c139f5ca252b1039d31435 Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Sun, 29 Sep 2024 15:49:42 -0400 Subject: [PATCH 27/28] Updated upload artifacts workflow --- .github/workflows/ghpages.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ghpages.yml b/.github/workflows/ghpages.yml index 7990c18..8bc4a3c 100644 --- a/.github/workflows/ghpages.yml +++ b/.github/workflows/ghpages.yml @@ -48,11 +48,11 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: "Save HTML" - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: path: "*.html" - name: "Save Text" - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: path: "*.txt" From f75528e2cbeed28f38ac402982126c3e40dd9ac4 Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Sun, 29 Sep 2024 15:53:19 -0400 Subject: [PATCH 28/28] Removed generated files from source --- draft-ietf-httpapi-ratelimit-headers.html | 2948 --------------------- draft-ietf-httpapi-ratelimit-headers.md~ | 1169 -------- draft-ietf-httpapi-ratelimit-headers.txt | 1435 ---------- 3 files changed, 5552 deletions(-) delete mode 100644 draft-ietf-httpapi-ratelimit-headers.html delete mode 100644 draft-ietf-httpapi-ratelimit-headers.md~ delete mode 100644 draft-ietf-httpapi-ratelimit-headers.txt diff --git a/draft-ietf-httpapi-ratelimit-headers.html b/draft-ietf-httpapi-ratelimit-headers.html deleted file mode 100644 index 60ed7d9..0000000 --- a/draft-ietf-httpapi-ratelimit-headers.html +++ /dev/null @@ -1,2948 +0,0 @@ - - - - - - -RateLimit header fields for HTTP - - - - - - - - - - - - - - - - - - - - - - - - - -
Internet-DraftRateLimit header fields for HTTPSeptember 2024
Polli, et al.Expires 2 April 2025[Page]
-
-
-
-
Workgroup:
-
HTTPAPI
-
Internet-Draft:
-
draft-ietf-httpapi-ratelimit-headers-latest
-
Published:
-
- -
-
Intended Status:
-
Standards Track
-
Expires:
-
-
Authors:
-
-
-
R. Polli
-
Team Digitale, Italian Government
-
-
-
A. Martinez
-
Red Hat
-
-
-
D. Miller
-
Microsoft
-
-
-
-
-

RateLimit header fields for HTTP

-
-

Abstract

-

This document defines the RateLimit-Policy and RateLimit HTTP header fields for servers to advertise their service policy limits and the current limits, thereby allowing clients to avoid being throttled.¶

-
-
-

-About This Document -

-

This note is to be removed before publishing as an RFC.¶

-

- Status information for this document may be found at https://datatracker.ietf.org/doc/draft-ietf-httpapi-ratelimit-headers/.¶

-

- Discussion of this document takes place on the - HTTPAPI Working Group mailing list (mailto:httpapi@ietf.org), - which is archived at https://mailarchive.ietf.org/arch/browse/httpapi/. - Subscribe at https://www.ietf.org/mailman/listinfo/httpapi/. - Working Group information can be found at https://datatracker.ietf.org/wg/httpapi/about/.¶

-

Source for this draft and an issue tracker can be found at - https://github.com/ietf-wg-httpapi/ratelimit-headers.¶

-
-
-
-

-Status of This Memo -

-

- This Internet-Draft is submitted in full conformance with the - provisions of BCP 78 and BCP 79.¶

-

- Internet-Drafts are working documents of the Internet Engineering Task - Force (IETF). Note that other groups may also distribute working - documents as Internet-Drafts. The list of current Internet-Drafts is - at https://datatracker.ietf.org/drafts/current/.¶

-

- Internet-Drafts are draft documents valid for a maximum of six months - and may be updated, replaced, or obsoleted by other documents at any - time. It is inappropriate to use Internet-Drafts as reference - material or to cite them other than as "work in progress."¶

-

- This Internet-Draft will expire on 2 April 2025.¶

-
-
- -
-
- â–²

-Table of Contents -

- -
-
-
-
-

-1. Introduction -

-

Rate limiting of HTTP clients has become a widespread practice, especially for HTTP APIs. Typically, servers who do so limit the number of acceptable requests in a given time window (e.g. 10 requests per second). See Appendix A for further information on the current usage of rate limiting in HTTP.¶

-

Currently, there is no standard way for servers to communicate quotas so that clients can throttle their requests to prevent errors. This document defines a set of standard HTTP header fields to enable rate limiting:¶

-
    -
  • -

    RateLimit: to convey -the server's current limit of quota units available to the client in the policy time window, -the remaining quota units in the current window, -and the time remaining in the current window, specified in seconds, and¶

    -
  • -
  • -

    RateLimit-Policy: the service policy limits.¶

    -
  • -
-

These fields enable establishing complex rate limiting policies, including using multiple and variable time windows and dynamic quotas, and implementing concurrency limits.¶

-

The behavior of the RateLimit header field is compatible with the delay-seconds notation of Retry-After.¶

-
-
-

-1.1. Goals -

-

The goals of this document are:¶

-
-
Interoperability:
-
-

Standardize the names and semantics of rate-limit headers -to ease their enforcement and adoption;¶

-
-
-
Resiliency:
-
-

Improve resiliency of HTTP infrastructure by -providing clients with information useful -to throttle their requests and -prevent 4xx or 5xx responses;¶

-
-
-
Documentation:
-
-

Simplify API documentation by eliminating the need -to include detailed quota limits -and related fields in API documentation.¶

-
-
-
-

The following features are out of the scope of this document:¶

-
-
Authorization:
-
-

RateLimit header fields are not meant to support -authorization or other kinds of access controls.¶

-
-
-
Response status code:
-
-

RateLimit header fields may be returned in both -successful (see Section 15.3 of [HTTP]) and non-successful responses. -This specification does not cover whether non Successful -responses count on quota usage, -nor does it mandates any correlation between the RateLimit values -and the returned status code.¶

-
-
-
Throttling algorithm:
-
-

This specification does not mandate a specific throttling algorithm. -The values published in the fields, including the window size, -can be statically or dynamically evaluated.¶

-
-
-
Service Level Agreement:
-
-

Conveyed quota hints do not imply any service guarantee. -Server is free to throttle respectful clients under certain circumstances.¶

-
-
-
-
-
-
-
-

-1.2. Notational Conventions -

-

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL -NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", -"MAY", and "OPTIONAL" in this document are to be interpreted as -described in BCP 14 [RFC2119] [RFC8174] when, and only when, they -appear in all capitals, as shown here.¶

-

The term Origin is to be interpreted as described in Section 7 of [WEB-ORIGIN].¶

-

This document uses the terms List, Item and Integer from Section 3 of [STRUCTURED-FIELDS] to specify syntax and parsing, along with the concept of "bare item".¶

-
-
-
-
-
-
-

-2. Terminology -

-
-
-

-2.1. Quota -

-

A quota is an allocation of capacity to enable a server to limit client requests. That capacity is counted in quota units and may be reallocated at the end of a time window Section 2.4.¶

-
-
-
-
-

-2.2. Quota Unit -

-

A quota unit is the unit of measure used to count the activity of a client.¶

-
-
-
-
-

-2.3. Quota Partition -

-

A quota partition is a division of a server's capacity across different clients, users and owned resources.¶

-
-
-
-
-

-2.4. Time Window -

-

A time window indicates a period of time associated to the allocated quota.¶

-

The time window is a non-negative Integer value expressing an interval in seconds, similar to the "delay-seconds" rule defined in Section 10.2.3 of [HTTP]. Sub-second precision is not supported.¶

-
-
-
-
-

-2.5. Quota Policy -

-

A quota policy is maintained by a server to limit the activity (counted in quota units (Section 2.2)) of a given quota partition (Section 2.3) over a period of time (known as the time window (Section 2.4)) to a specified amount known as the Section 2.1.¶

-

Quota policies can be advertised by servers (see Section 3), but they are not required to be, and more than one quota policy can affect a given request from a client to a server.¶

-
-
-
-
-

-2.6. Service Limit -

-

A service limit is the current limit of the amount of activity that a server will allow based on the remaining quota for a particular quota partition within the time-window, if defined.¶

-
-
-
-
-
-
-

-3. RateLimit-Policy Field -

-

The "RateLimit-Policy" response header field is a non-empty List of Section 3.1. Its value is informative. The values are expected to remain consistent over a the lifetime of a connection. It is this characteristic that differentiates it from the RateLimit (Section 4) that contains values that may change on every request.¶

-
-
-   RateLimit-Policy: burst;q=100;w=60,daily;q=1000;w=86400
-
¶ -
-
-
-

-3.1. Quota Policy Item -

-

A quota policy Item contains information about a server's capacity allocation for a quota partition associated with the request.¶

-

The following parameters are defined in this specification:¶

-
-
q:
-
-

The REQUIRED "q" parameter indicates the quota allocated. (Section 3.1.1)¶

-
-
-
qu:
-
-

The OPTIONAL "qu" parameter value conveys the quota units associated to the "q" parameter. The default quota unit is "request". (Section 3.1.2)¶

-
-
-
w:
-
-

The OPTIONAL "w" parameter value conveys a time "window" (Section 2.4). (Section 3.1.3)¶

-
-
-
pk:
-
-

The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. Section 3.1.4¶

-
-
-
-

Other parameters are allowed and can be regarded as comments.¶

-

Implementation- or service-specific parameters SHOULD be prefixed parameters with a vendor identifier, e.g. acme-policy, acme-burst.¶

-
-
-

-3.1.1. Quota Parameter -

-

The "q" parameter uses a non-negative integer value to indicate the quota allocated for client activity (counted in quota units) for a given quota partition (Section 2.6).¶

-
-
-
-
-

-3.1.2. Quota Unit Parameter -

-

The "qu" parameter value conveys the quota units associated to the "q" parameter.¶

-
-
-
-
-

-3.1.3. Window Parameter -

-

The "w" parameter value conveys a time "window" in seconds. (Section 2.4).¶

-
-
-
-
-

-3.1.4. Partition Key Parameter -

-

The "pk" parameter value conveys the partition key associated to the request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key.¶

-
-
-
-
-
-
-

-3.2. RateLimit Policy Field Examples -

-

This field MAY convey the time window associated with the expiring-limit, as shown in this example:¶

-
-
-   RateLimit-Policy: default;l=100;w=10
-
¶ -
-

These examples show multiple policies being returned:¶

-
-
-   RateLimit-Policy: permin;l=50;w=60,perhr;l=1000;w=3600,perday;l=5000;w=86400
-
¶ -
-

The following example shows a policy with a partition key:¶

-
-
-   RateLimit-Policy: peruser;l=100;w=60;pk=user123
-
¶ -
-

The following example shows a policy with a partition key and a quota unit:¶

-
-
-   RateLimit-Policy: peruser;l=65535;w=10;pk=user123;qu=bytes
-
¶ -
-

This field cannot appear in a trailer section.¶

-
-
-
-
-
-
-

-4. RateLimit Field -

-

A server uses the "RateLimit" response header field to communicate the service limit for a quota policy for a particular partition key.¶

-

The field is expressed as List of Section 4.1.¶

-
-
-   RateLimit: default;r=50;t=30
-
¶ -
-
-
-

-4.1. Service Limit Item -

-

Each service limit item in identifies the quota policy associated with the request and¶

-

The following parameters are defined in this specification:¶

-
-
r:
-
-

This parameter value conveys the remaining quota units for the identified policy (Section 4.1.1).¶

-
-
-
t:
-
-

This OPTIONAL parameter value conveys the time window reset time for the identified policy (Section 4.1.2).¶

-
-
-
pk:
-
-

The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request.¶

-
-
-
-

This field cannot appear in a trailer section. Other parameters are allowed and can be regarded as comments.¶

-

Implementation- or service-specific parameters SHOULD be prefixed parameters with a vendor identifier, e.g. acme-policy, acme-burst.¶

-
-
-

-4.1.1. Remaining Parameter -

-

The "r" parameter indicates the remaining quota units for the identified policy (Section 4.1.1).¶

-

It is a non-negative Integer expressed in quota units (Section 2.2). -Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. -When remaining parameter value is low, it indicates that the server may soon throttle the client (see Section 5).¶

-
-
-
-
-

-4.1.2. Reset Parameter -

-

The "t" parameter indicates the number of seconds until the quota associated with the quota policy resets.¶

-

It is a non-negative Integer compatible with the delay-seconds rule, because:¶

-
    -
  • -

    it does not rely on clock synchronization and is resilient to clock adjustment -and clock skew between client and server (see Section 5.6.7 of [HTTP]);¶

    -
  • -
  • -

    it mitigates the risk related to thundering herd when too many clients are serviced with the same timestamp.¶

    -
  • -
-

The client MUST NOT assume that all its service limit will be reset at the moment indicated by the reset keyword. The server MAY arbitrarily alter the reset parameter value between subsequent requests; for example, in case of resource saturation or to implement sliding window policies.¶

-
-
-
-
-

-4.1.3. Partition Key Parameter -

-

The "pk" parameter value conveys the partition key associated to the request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key.¶

-
-
-
-
-
-
-

-4.2. RateLimit Field Examples -

-

This example shows a RateLimit field with a remaining quota of 50 units and a time window reset in 30 seconds:¶

-
-
-   RateLimit: default;r=50;t=30
-
¶ -
-

This example shows a remaining quota of 999 requests for a partition key that has no time window reset:¶

-
-
-   RateLimit: default;r=999;pk=trial-121323
-
¶ -
-

This example shows a 300MB remaining quota for an application in the next 60 seconds:¶

-
-
-   RateLimit: default;r=300000000;pk=App-999;t=60;qu=bytes
-
¶ -
-
-
-
-
-
-
-

-5. Server Behavior -

-

A server MAY return RateLimit header fields independently of the response status code. This includes on throttled responses. This document does not mandate any correlation between the RateLimit header field values and the returned status code.¶

-

Servers should be careful when returning RateLimit header fields in redirection responses (i.e., responses with 3xx status codes) because a low remaining keyword value could prevent the client from issuing requests. For example, given the RateLimit header fields below, a client could decide to wait 10 seconds before following the "Location" header field (see Section 10.2.2 of [HTTP]), because the remaining keyword value is 0.¶

-
-
-HTTP/1.1 301 Moved Permanently
-Location: /foo/123
-RateLimit: problemPolicy;r=0, t=10
-
-
¶ -
-

If a response contains both the Retry-After and the RateLimit header fields, the reset keyword value SHOULD reference the same point in time as the Retry-After field value.¶

-

A service using RateLimit header fields MUST NOT convey values exposing an unwanted volume of requests and SHOULD implement mechanisms to cap the ratio between the remaining and the reset keyword values (see Section 7.5); this is especially important when a quota policy uses a large time window.¶

-

Under certain conditions, a server MAY artificially lower RateLimit header field values between subsequent requests, e.g. to respond to Denial of Service attacks or in case of resource saturation.¶

-
-
-

-5.1. Performance Considerations -

-

Servers are not required to return RateLimit header fields in every response, and clients need to take this into account. For example, an implementer concerned with performance might provide RateLimit header fields only when a given quota is close to exhaustion.¶

-

Implementers concerned with response fields' size, might take into account their ratio with respect to the content length, or use header-compression HTTP features such as [HPACK].¶

-
-
-
-
-
-
-

-6. Client Behavior -

-

The RateLimit header fields can be used by clients to determine whether the associated request respected the server's quota policy, and as an indication of whether subsequent requests will. However, the server might apply other criteria when servicing future requests, and so the quota policy may not completely reflect whether requests will succeed.¶

-

For example, a successful response with the following fields:¶

-
-
-   RateLimit: default;r=1;t=7
-
¶ -
-

does not guarantee that the next request will be successful. Servers' behavior may be subject to other conditions.¶

-

A client is responsible for ensuring that RateLimit header field values returned -cause reasonable client behavior with respect to throughput and latency -(see Section 7.5 and Section 7.5.1).¶

-

A client receiving RateLimit header fields MUST NOT assume that future responses will contain the same RateLimit header fields, or any RateLimit header fields at all.¶

-

Malformed RateLimit header fields MUST be ignored.¶

-

A client SHOULD NOT exceed the quota units conveyed by the remaining keyword before the time window expressed in the reset keyword.¶

-

The value of the reset keyword is generated at response time: a client aware of a significant network latency MAY behave accordingly and use other information (e.g. the "Date" response header field, or otherwise gathered metrics) to better estimate the reset keyword moment intended by the server.¶

-

The details provided in the RateLimit-Policy header field are informative and MAY be ignored.¶

-

If a response contains both the RateLimit and Retry-After fields, the Retry-After field MUST take precedence and the reset keyword MAY be ignored.¶

-

This specification does not mandate a specific throttling behavior and implementers can adopt their preferred policies, including:¶

-
    -
  • -

    slowing down or pre-emptively back-off their request rate when -approaching quota limits;¶

    -
  • -
  • -

    consuming all the quota according to the exposed limits and then wait.¶

    -
  • -
-
-
-

-6.1. Intermediaries -

-

This section documents the considerations advised in Section 16.3.2 of [HTTP].¶

-

An intermediary that is not part of the originating service infrastructure and is not aware of the quota policy semantic used by the Origin Server SHOULD NOT alter the RateLimit header fields' values in such a way as to communicate a more permissive quota policy; this includes removing the RateLimit header fields.¶

-

An intermediary MAY alter the RateLimit header fields in such a way as to communicate a more restrictive quota policy when:¶

-
    -
  • -

    it is aware of the quota unit semantic used by the Origin Server;¶

    -
  • -
  • -

    it implements this specification and enforces a quota policy which -is more restrictive than the one conveyed in the fields.¶

    -
  • -
-

An intermediary SHOULD forward a request even when presuming that it might not be serviced; the service returning the RateLimit header fields is the sole responsible of enforcing the communicated quota policy, and it is always free to service incoming requests.¶

-

This specification does not mandate any behavior on intermediaries respect to retries, nor requires that intermediaries have any role in respecting quota policies. For example, it is legitimate for a proxy to retransmit a request without notifying the client, and thus consuming quota units.¶

-

Privacy considerations (Section 8) provide further guidance on intermediaries.¶

-
-
-
-
-

-6.2. Caching -

-

[HTTP-CACHING] defines how responses can be stored and reused for subsequent requests, -including those with RateLimit header fields. -Because the information in RateLimit header fields on a cached response may not be current, they SHOULD be ignored on responses that come from cache -(i.e., those with a positive current_age; see Section 4.2.3 of [HTTP-CACHING]).¶

-
-
-
-
-
-
-

-7. Security Considerations -

-
-
-

-7.1. Throttling does not prevent clients from issuing requests -

-

This specification does not prevent clients from making requests. -Servers should always implement mechanisms to prevent resource exhaustion.¶

-
-
-
-
-

-7.2. Information disclosure -

-

Servers should not disclose to untrusted parties operational capacity information -that can be used to saturate its infrastructural resources.¶

-

While this specification does not mandate whether non-successful responses consume quota, -if error responses (such as 401 (Unauthorized) and 403 (Forbidden)) count against quota, -a malicious client could probe the endpoint to get traffic information of another user.¶

-

As intermediaries might retransmit requests and consume -quota units without prior knowledge of the user agent, -RateLimit header fields might reveal the existence of an intermediary -to the user agent.¶

-

Where partition keys contain identifying information, either of the client application or the user, servers should be aware of the potential for impersonation and apply the appropriate security mechanisms.¶

-
-
-
-
-

-7.3. Remaining quota units are not granted requests -

-

RateLimit header fields convey hints from the server -to the clients in order to help them avoid being throttled out.¶

-

Clients MUST NOT consider the quota units (Section 2.6) returned in remaining keyword as a service level agreement.¶

-

In case of resource saturation, the server MAY artificially lower the returned values -or not serve the request regardless of the advertised quotas.¶

-
-
-
-
-

-7.4. Reliability of the reset keyword -

-

Consider that quota might not be restored after the moment referenced by the reset keyword (Section 4.1.2), -and the reset parameter value may not be constant.¶

-

Subsequent requests might return a higher reset parameter value -to limit concurrency or implement dynamic or adaptive throttling policies.¶

-
-
-
-
-

-7.5. Resource exhaustion -

-

When returning reset values, servers must be aware that -many throttled clients may come back at the very moment specified.¶

-

This is true for Retry-After too.¶

-

For example, if the quota resets every day at 18:00:00 -and your server returns the reset parameter accordingly¶

-
-
-   Date: Tue, 15 Nov 1994 18:00:00 GMT
-   RateLimit: daily;r=1;t=36400
-
¶ -
-

there's a high probability that all clients will show up at 18:00:00.¶

-

This could be mitigated by adding some jitter to the reset value.¶

-

Resource exhaustion issues can be associated with quota policies using a -large time window, because a user agent by chance or on purpose -might consume most of its quota units in a significantly shorter interval.¶

-

This behavior can be even triggered by the provided RateLimit header fields. -The following example describes a service -with an unconsumed quota policy of 10000 quota units per 1000 seconds.¶

-
-
-RateLimit-Policy: somepolicy;l=10000;w=1000
-RateLimit: somepolicy;r=10000;t=10
-
¶ -
-

A client implementing a simple ratio between remaining keyword and reset keyword could infer an average throughput of 1000 quota units per second, while the limit keyword conveys a quota-policy with an average of 10 quota units per second. -If the service cannot handle such load, it should return either a lower remaining keyword value or an higher reset keyword value. -Moreover, complementing large time window quota policies with a short time window one mitigates those risks.¶

-
-
-

-7.5.1. Denial of Service -

-

RateLimit header fields may contain unexpected values by chance or on purpose. -For example, an excessively high remaining keyword value may be:¶

-
    -
  • -

    used by a malicious intermediary to trigger a Denial of Service attack -or consume client resources boosting its requests;¶

    -
  • -
  • -

    passed by a misconfigured server;¶

    -
  • -
-

or a high reset keyword value could inhibit clients to contact the server (e.g. similarly to receiving "Retry-after: 1000000").¶

-

To mitigate this risk, clients can set thresholds that they consider reasonable in terms of quota units, time window, concurrent requests or throughput, and define a consistent behavior when the RateLimit exceed those thresholds. -For example this means capping the maximum number of request per second, or implementing retries when the reset keyword exceeds ten minutes.¶

-

The considerations above are not limited to RateLimit header fields, but apply to all fields affecting how clients behave in subsequent requests (e.g. Retry-After).¶

-
-
-
-
-
-
-
-
-

-8. Privacy Considerations -

-

Clients that act upon a request to rate limit -are potentially re-identifiable (see Section 5.2.1 of [PRIVACY]) -because they react to information that might only be given to them. -Note that this might apply to other fields too (e.g. Retry-After).¶

-

Since rate limiting is usually implemented in contexts where -clients are either identified or profiled -(e.g. assigning different quota units to different users), -this is rarely a concern.¶

-

Privacy enhancing infrastructures using RateLimit header fields -can define specific techniques to mitigate the risks of re-identification.¶

-
-
-
-
-

-9. IANA Considerations -

-

IANA is requested to update one registry and create one new registry.¶

-

Please add the following entries to the -"Hypertext Transfer Protocol (HTTP) Field Name Registry" registry ([HTTP]):¶

- - - - - - - - - - - - - - - - - - - - - -
Table 1
Field NameStatusSpecification
RateLimitpermanent - Section 4 of RFC nnnn
RateLimit-Policypermanent - Section 3 of RFC nnnn
-
-
-
-

-10. References -

-
-
-

-10.1. Normative References -

-
-
[HTTP]
-
-Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, Ed., "HTTP Semantics", STD 97, RFC 9110, DOI 10.17487/RFC9110, , <https://www.rfc-editor.org/rfc/rfc9110>.
-
-
[IANA]
-
-Cotton, M., Leiba, B., and T. Narten, "Guidelines for Writing an IANA Considerations Section in RFCs", BCP 26, RFC 8126, DOI 10.17487/RFC8126, , <https://www.rfc-editor.org/rfc/rfc8126>.
-
-
[RFC2119]
-
-Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, , <https://www.rfc-editor.org/rfc/rfc2119>.
-
-
[RFC8174]
-
-Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, , <https://www.rfc-editor.org/rfc/rfc8174>.
-
-
[STRUCTURED-FIELDS]
-
-Nottingham, M. and P. Kamp, "Structured Field Values for HTTP", RFC 8941, DOI 10.17487/RFC8941, , <https://www.rfc-editor.org/rfc/rfc8941>.
-
-
[WEB-ORIGIN]
-
-Barth, A., "The Web Origin Concept", RFC 6454, DOI 10.17487/RFC6454, , <https://www.rfc-editor.org/rfc/rfc6454>.
-
-
-
-
-
-
-

-10.2. Informative References -

-
-
[HPACK]
-
-Peon, R. and H. Ruellan, "HPACK: Header Compression for HTTP/2", RFC 7541, DOI 10.17487/RFC7541, , <https://www.rfc-editor.org/rfc/rfc7541>.
-
-
[HTTP-CACHING]
-
-Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, Ed., "HTTP Caching", STD 98, RFC 9111, DOI 10.17487/RFC9111, , <https://www.rfc-editor.org/rfc/rfc9111>.
-
-
[PRIVACY]
-
-Cooper, A., Tschofenig, H., Aboba, B., Peterson, J., Morris, J., Hansen, M., and R. Smith, "Privacy Considerations for Internet Protocols", RFC 6973, DOI 10.17487/RFC6973, , <https://www.rfc-editor.org/rfc/rfc6973>.
-
-
[RFC3339]
-
-Klyne, G. and C. Newman, "Date and Time on the Internet: Timestamps", RFC 3339, DOI 10.17487/RFC3339, , <https://www.rfc-editor.org/rfc/rfc3339>.
-
-
[RFC6585]
-
-Nottingham, M. and R. Fielding, "Additional HTTP Status Codes", RFC 6585, DOI 10.17487/RFC6585, , <https://www.rfc-editor.org/rfc/rfc6585>.
-
-
[UNIX]
-
-The Open Group, "The Single UNIX Specification, Version 2 - 6 Vol Set for UNIX 98", .
-
-
-
-
-
-
-
-

-Appendix A. Rate-limiting and quotas -

-

Servers use quota mechanisms to avoid systems overload, to ensure an equitable distribution of computational resources or to enforce other policies - e.g. monetization.¶

-

A basic quota mechanism limits the number of acceptable requests in a given time window, e.g. 10 requests per second.¶

-

When quota is exceeded, servers usually do not serve the request replying instead with a 4xx HTTP status code (e.g. 429 or 403) or adopt more aggressive policies like dropping connections.¶

-

Quotas may be enforced on different basis (e.g. per user, per IP, per geographic area, ..) and at different levels. For example, an user may be allowed to issue:¶

-
    -
  • -

    10 requests per second;¶

    -
  • -
  • -

    limited to 60 requests per minute;¶

    -
  • -
  • -

    limited to 1000 requests per hour.¶

    -
  • -
-

Moreover system metrics, statistics and heuristics can be used to implement more complex policies, -where the number of acceptable requests and the time window are computed dynamically.¶

-

To help clients throttling their requests, -servers may expose the counters used to evaluate quota policies via HTTP header fields.¶

-

Those response headers may be added by HTTP intermediaries such as API gateways and reverse proxies.¶

-

On the web we can find many different rate-limit headers, -usually containing the number of allowed requests in a given time window, and when the window is reset.¶

-

The common choice is to return three headers containing:¶

-
    -
  • -

    the maximum number of allowed requests in the time window;¶

    -
  • -
  • -

    the number of remaining requests in the current window;¶

    -
  • -
  • -

    the time remaining in the current window expressed in seconds or -as a timestamp;¶

    -
  • -
-
-
-

-A.1. Interoperability issues -

-

A major interoperability issue in throttling is the lack of standard headers, because:¶

-
    -
  • -

    each implementation associates different semantics to the -same header field names;¶

    -
  • -
  • -

    header field names proliferates.¶

    -
  • -
-

User agents interfacing with different servers may thus need to process different headers, -or the very same application interface that sits behind different reverse proxies -may reply with different throttling headers.¶

-
-
-
-
-
-
-

-Appendix B. Examples -

-
-
-

-B.1. Responses without defining policies -

-

Some servers may not expose the policy limits in the RateLimit-Policy header field. Clients can still use the RateLimit header field to throttle their requests.¶

-
-
-

-B.1.1. Throttling information in responses -

-

The client exhausted its quota for the next 50 seconds. -The limit and time-window is communicated out-of-band.¶

-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 200 Ok
-Content-Type: application/json
-RateLimit: default;r=0;t=50
-
-{"hello": "world"}
-
¶ -
-

Since the field values are not necessarily correlated with -the response status code, -a subsequent request is not required to fail. -The example below shows that the server decided to serve the request -even if remaining keyword value is 0. -Another server, or the same server under other load conditions, could have decided to throttle the request instead.¶

-

Request:¶

-
-
-GET /items/456 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 200 Ok
-Content-Type: application/json
-RateLimit: default;r=0;t=48
-
-{"still": "successful"}
-
¶ -
-
-
-
-
-

-B.1.2. Multiple policies in response -

-

The server uses two different policies to limit the client's requests:¶

-
    -
  • -

    5000 daily quota units;¶

    -
  • -
  • -

    1000 hourly quota units.¶

    -
  • -
-

The client consumed 4900 quota units in the first 14 hours.¶

-

Despite the next hourly limit of 1000 quota units, -the closest limit to reach is the daily one.¶

-

The server then exposes the RateLimit header fields to -inform the client that:¶

-
    -
  • -

    it has only 100 quota units left in the daily quota and the window will reset in 10 hours;¶

    -
  • -
-

The server MAY choose to omit returning the hourly policy as it uses the same quota units as the daily policy and the daily policy is the one that is closest to being exhausted.¶

-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 200 Ok
-Content-Type: application/json
-RateLimit: dayLimit;r=100;t=36000
-
-{"hello": "world"}
-
¶ -
-
-
-
-
-

-B.1.3. Use for limiting concurrency -

-

RateLimit header fields may be used to limit concurrency, -advertising limits that are lower than the usual ones -in case of saturation, thus increasing availability.¶

-

The server adopted a basic policy of 100 quota units per minute, -and in case of resource exhaustion adapts the returned values -reducing both limit and remaining keyword values.¶

-

After 2 seconds the client consumed 40 quota units¶

-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 200 Ok
-Content-Type: application/json
-RateLimit-Policy: basic;l=100;w=60
-RateLimit: basic;r=60;t=58
-
-{"elapsed": 2, "issued": 40}
-
¶ -
-

At the subsequent request - due to resource exhaustion - -the server advertises only r=20.¶

-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 200 Ok
-Content-Type: application/json
-RateLimit-Policy: basic;l=100;w=60
-RateLimit: basic;r=20;t=56
-
-{"elapsed": 4, "issued": 41}
-
¶ -
-
-
-
-
-

-B.1.4. Use in throttled responses -

-

A client exhausted its quota and the server throttles it -sending Retry-After.¶

-

In this example, the values of Retry-After and RateLimit header field reference the same moment, -but this is not a requirement.¶

-

The 429 (Too Many Request) HTTP status code is just used as an example.¶

-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 429 Too Many Requests
-Content-Type: application/json
-Date: Mon, 05 Aug 2019 09:27:00 GMT
-Retry-After: Mon, 05 Aug 2019 09:27:05 GMT
-RateLimit: default;r=0;t=5
-
-{
-"title": "Too Many Requests",
-"status": 429,
-"detail": "You have exceeded your quota"
-}
-
¶ -
-
-
-
-
-
-
-

-B.2. Responses with defined policies -

-
-
-

-B.2.1. Throttling window specified via parameter -

-

The client has 99 quota units left for the next 50 seconds. -The time window is communicated by the w parameter, so we know the throughput is 100 quota units per minute.¶

-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 200 Ok
-Content-Type: application/json
-RateLimit: fixedwindow;r=99;t=50
-RateLimit-Policy: fixedwindow;l=100;w=60
-{"hello": "world"}
-
¶ -
-
-
-
-
-

-B.2.2. Dynamic limits with parameterized windows -

-

The policy conveyed by the RateLimit header field states that -the server accepts 100 quota units per minute.¶

-

To avoid resource exhaustion, the server artificially lowers -the actual limits returned in the throttling headers.¶

-

The remaining keyword then advertises -only 9 quota units for the next 50 seconds to slow down the client.¶

-

Note that the server could have lowered even the other -values in the RateLimit header field: this specification -does not mandate any relation between the field values -contained in subsequent responses.¶

-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 200 Ok
-Content-Type: application/json
-RateLimit-Policy: dynamic;l=100;w=60
-RateLimit: dynamic;r=9;t=50
-
-
-{
-  "status": 200,
-  "detail": "Just slow down without waiting."
-}
-
¶ -
-
-
-
-
-

-B.2.3. Dynamic limits for pushing back and slowing down -

-

Continuing the previous example, let's say the client waits 10 seconds and -performs a new request which, due to resource exhaustion, the server rejects -and pushes back, advertising r=0 for the next 20 seconds.¶

-

The server advertises a smaller window with a lower limit to slow -down the client for the rest of its original window after the 20 seconds elapse.¶

-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 429 Too Many Requests
-Content-Type: application/json
-RateLimit-Policy: dynamic;l=15;w=20
-RateLimit: dynamic;r=0;t=20
-
-{
-  "status": 429,
-  "detail": "Wait 20 seconds, then slow down!"
-}
-
¶ -
-
-
-
-
-
-
-

-B.3. Dynamic limits for pushing back with Retry-After and slow down -

-

Alternatively, given the same context where the previous example starts, we -can convey the same information to the client via Retry-After, with -the advantage that the server can now specify the policy's nominal limit and -window that will apply after the reset, e.g. assuming the resource exhaustion -is likely to be gone by then, so the advertised policy does not need to be -adjusted, yet we managed to stop requests for a while and slow down the rest of -the current window.¶

-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 429 Too Many Requests
-Content-Type: application/json
-Retry-After: 20
-RateLimit-Policy: dynamic;l=100;w=60
-RateLimit: dynamic;r=15;t=40
-
-{
-  "status": 429,
-  "detail": "Wait 20 seconds, then slow down!"
-}
-
¶ -
-

Note that in this last response the client is expected to honor -Retry-After and perform no requests for the specified amount of -time, whereas the previous example would not force the client to stop -requests before the reset time is elapsed, as it would still be free to -query again the server even if it is likely to have the request rejected.¶

-
-
-

-B.3.1. Missing Remaining information -

-

The server does not expose remaining values -(for example, because the underlying counters are not available). -Instead, it resets the limit counter every second.¶

-

It communicates to the client the limit of 10 quota units per second -always returning the limit and reset keywords.¶

-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 200 Ok
-Content-Type: application/json
-RateLimit-Policy: quota;l=100;w=1
-RateLimit: quota;t=1
-
-{"first": "request"}
-
¶ -
-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 200 Ok
-Content-Type: application/json
-RateLimit-Policy: quota;l=10
-RateLimit: quota;t=1
-
-{"second": "request"}
-
¶ -
-
-
-
-
-

-B.3.2. Use with multiple windows -

-

This is a standardized way of describing the policy -detailed in Appendix B.1.2:¶

-
    -
  • -

    5000 daily quota units;¶

    -
  • -
  • -

    1000 hourly quota units.¶

    -
  • -
-

The client consumed 4900 quota units in the first 14 hours.¶

-

Despite the next hourly limit of 1000 quota units, the closest limit -to reach is the daily one.¶

-

The server then exposes the RateLimit header fields to inform the client that:¶

-
    -
  • -

    it has only 100 quota units left;¶

    -
  • -
  • -

    the window will reset in 10 hours;¶

    -
  • -
  • -

    the expiring-limit is 5000.¶

    -
  • -
-

Request:¶

-
-
-GET /items/123 HTTP/1.1
-Host: api.example
-
-
¶ -
-

Response:¶

-
-
-HTTP/1.1 200 OK
-Content-Type: application/json
-RateLimit-Policy: hour;l=1000;w=3600, day;l=5000;w=86400
-RateLimit: day;r=100;t=36000
-
-{"hello": "world"}
-
¶ -
-
-
-
-
-
-
-
-
-

-FAQ -

-

This section is to be removed before publishing as an RFC.¶

-
    -
  1. -

    Why defining standard fields for throttling?¶

    -

    -To simplify enforcement of throttling policies and enable clients to constraint their requests to avoid being throttled.¶

    -
  2. -
  3. -

    Can I use RateLimit header fields in throttled responses (eg with status code 429)?¶

    -

    -Yes, you can.¶

    -
  4. -
  5. -

    Are those specs tied to RFC 6585?¶

    -

    -No. [RFC6585] defines the 429 status code and we use it just as an example of a throttled request, -that could instead use even 403 or whatever status code.¶

    -
  6. -
  7. -

    Why is the partition key necessary?¶

    -

    -Without a partition key, a server can only effectively only have one scope (aka partition), which is impractical for most services, or it needs to communicate the scopes out-of-band. -This prevents the development of generic connector code that can be used to prevent requests from being throttled. -Many APIs rely on API keys, user identity or client identity to allocate quota. -As soon as a single client processes requests for more than one partition, the client needs to know the corresponding partition key to properly track requests against allocated quota.¶

    -
  8. -
  9. -

    Why using delay-seconds instead of a UNIX Timestamp? -Why not using subsecond precision?¶

    -

    -Using delay-seconds aligns with Retry-After, which is returned in similar contexts, -eg on 429 responses.¶

    -

    -Timestamps require a clock synchronization protocol -(see Section 5.6.7 of [HTTP]). -This may be problematic (e.g. clock adjustment, clock skew, failure of hardcoded clock synchronization servers, -IoT devices, ..). -Moreover timestamps may not be monotonically increasing due to clock adjustment. -See Another NTP client failure story¶

    -

    -We did not use subsecond precision because:¶

    -
      -
    • -

      that is more subject to system clock correction -like the one implemented via the adjtimex() Linux system call;¶

      -
    • -
    • -

      response-time latency may not make it worth. A brief discussion on the subject is -on the httpwg ml¶

      -
    • -
    • -

      almost all rate-limit headers implementations do not use it.¶

      -
    • -
    -
  10. -
  11. -

    Shouldn't I limit concurrency instead of request rate?¶

    -

    -You can use this specification to limit concurrency -at the HTTP level (see {#use-for-limiting-concurrency}) -and help clients to shape their requests avoiding being throttled out.¶

    -

    -A problematic way to limit concurrency is connection dropping, -especially when connections are multiplexed (e.g. HTTP/2) -because this results in unserviced client requests, -which is something we want to avoid.¶

    -

    -A semantic way to limit concurrency is to return 503 + Retry-After -in case of resource saturation (e.g. thrashing, connection queues too long, -Service Level Objectives not meet, ..). -Saturation conditions can be either dynamic or static: all this is out of -the scope for the current document.¶

    -
  12. -
  13. -

    Do a positive value of remaining paramter imply any service guarantee for my -future requests to be served?¶

    -

    -No. FAQ integrated in Section 4.1.1.¶

    -
  14. -
  15. -

    Is the quota-policy definition Section 2.5 too complex?¶

    -

    -You can always return the simplest form¶

    -
  16. -
-
-
-RateLimit:default;r=50;t=60
-
¶ -
-

The policy key clearly connects the current usage status of a policy to the defined limits. - So for the following field:¶

-
-
-RateLimit-Policy: sliding;l=100;w=60;burst=1000;comment="sliding window", fixed;l=5000;w=3600;burst=0;comment="fixed window"
-RateLimit: sliding;r=50;t=44
-
¶ -
-

the value "sliding" identifies the policy being reported.¶

-
    -
  1. -

    Can intermediaries alter RateLimit header fields?¶

    -

    -Generally, they should not because it might result in unserviced requests. - There are reasonable use cases for intermediaries mangling RateLimit header fields though, - e.g. when they enforce stricter quota-policies, - or when they are an active component of the service. - In those case we will consider them as part of the originating infrastructure.¶

    -
  2. -
  3. -

    Why the w parameter is just informative? -Could it be used by a client to determine the request rate?¶

    -

    -A non-informative w parameter might be fine in an environment -where clients and servers are tightly coupled. Conveying policies -with this detail on a large scale would be very complex and implementations -would be likely not interoperable. We thus decided to leave w as -an informational parameter and only rely on the limit, remaining and reset keywords -for defining the throttling -behavior.¶

    -
  4. -
  5. -

    Can I use RateLimit fields in trailers? -Servers usually establish whether the request is in-quota before creating a response, so the RateLimit field values should be already available in that moment. -Supporting trailers has the only advantage that allows to provide more up-to-date information to the client in case of slow responses. -However, this complicates client implementations with respect to combining fields from headers and accounting for intermediaries that drop trailers. -Since there are no current implementations that use trailers, we decided to leave this as a future-work.¶

    -
  6. -
-
-
-
-
-

-RateLimit header fields currently used on the web -

-

This section is to be removed before publishing as an RFC.¶

-

Commonly used header field names are:¶

-
    -
  • -

    X-RateLimit-Limit, -X-RateLimit-Remaining, -X-RateLimit-Reset;¶

    -
  • -
-

There are variants too, where the window is specified -in the header field name, eg:¶

-
    -
  • -

    x-ratelimit-limit-minute, x-ratelimit-limit-hour, x-ratelimit-limit-day¶

    -
  • -
  • -

    x-ratelimit-remaining-minute, x-ratelimit-remaining-hour, x-ratelimit-remaining-day¶

    -
  • -
-

Here are some interoperability issues:¶

-
    -
  • -

    X-RateLimit-Remaining references different values, depending on the implementation:¶

    -
      -
    • -

      seconds remaining to the window expiration¶

      -
    • -
    • -

      milliseconds remaining to the window expiration¶

      -
    • -
    • -

      seconds since UTC, in UNIX Timestamp [UNIX]¶

      -
    • -
    • -

      a datetime, either IMF-fixdate [HTTP] or [RFC3339]¶

      -
    • -
    -
  • -
  • -

    different headers, with the same semantic, are used by different implementers:¶

    -
      -
    • -

      X-RateLimit-Limit and X-Rate-Limit-Limit¶

      -
    • -
    • -

      X-RateLimit-Remaining and X-Rate-Limit-Remaining¶

      -
    • -
    • -

      X-RateLimit-Reset and X-Rate-Limit-Reset¶

      -
    • -
    -
  • -
-

The semantic of RateLimit depends on the windowing algorithm. -A sliding window policy for example, may result in having a remaining keyword value related to the ratio between the current and the maximum throughput. -e.g.¶

-
-
-RateLimit-Policy: sliding;l=12;w=1
-RateLimit: sliding;l=12;r=6;t=1          ; using 50% of throughput, that is 6 units/s
-
-
¶ -
-

If this is the case, the optimal solution is to achieve¶

-
-
-RateLimit-Policy: sliding;l=12;w=1
-RateLimit: sliding;l=12;r=1;t=1          ; using 100% of throughput, that is 12 units/s
-
¶ -
-

At this point you should stop increasing your request rate.¶

-
-
-
-
-

-Acknowledgements -

-

Thanks to Willi Schoenborn, Alejandro Martinez Ruiz, Alessandro Ranellucci, -Amos Jeffries, -Martin Thomson, -Erik Wilde and Mark Nottingham for being the initial contributors -of these specifications. -Kudos to the first community implementers: -Aapo Talvensaari, -Nathan Friedly -and Sanyam Dogra.¶

-

In addition to the people above, this document owes a lot to the extensive discussion in the HTTPAPI workgroup, including -Rich Salz, -Darrel Miller -and Julian Reschke.¶

-
-
-
-
-

-Changes -

-

This section is to be removed before publishing as an RFC.¶

-
-
-

-Since draft-ietf-httpapi-ratelimit-headers-07 -

-

This section is to be removed before publishing as an RFC.¶

-
    -
  • -

    Refactored both fields to lists of Items that identify policy and use parameters¶

    -
  • -
  • -

    Added quota unit parameter¶

    -
  • -
  • -

    Added partition key parameter¶

    -
  • -
-
-
-
-
-

-Since draft-ietf-httpapi-ratelimit-headers-03 -

-

This section is to be removed before publishing as an RFC.¶

-
    -
  • -

    Split policy informatiom in RateLimit-Policy #81¶

    -
  • -
-
-
-
-
-

-Since draft-ietf-httpapi-ratelimit-headers-02 -

-

This section is to be removed before publishing as an RFC.¶

-
    -
  • -

    Address throttling scope #83¶

    -
  • -
-
-
-
-
-

-Since draft-ietf-httpapi-ratelimit-headers-01 -

-

This section is to be removed before publishing as an RFC.¶

-
    -
  • -

    Update IANA considerations #60¶

    -
  • -
  • -

    Use Structured fields #58¶

    -
  • -
  • -

    Reorganize document #67¶

    -
  • -
-
-
-
-
-

-Since draft-ietf-httpapi-ratelimit-headers-00 -

-

This section is to be removed before publishing as an RFC.¶

-
    -
  • -

    Use I-D.httpbis-semantics, which includes referencing delay-seconds -instead of delta-seconds. #5¶

    -
  • -
-
-
-
-
-
-
-

-Authors' Addresses -

-
-
Roberto Polli
-
Team Digitale, Italian Government
-
Italy
- -
-
-
Alejandro Martinez Ruiz
-
Red Hat
- -
-
-
Darrel Miller
-
Microsoft
- -
-
-
- - - diff --git a/draft-ietf-httpapi-ratelimit-headers.md~ b/draft-ietf-httpapi-ratelimit-headers.md~ deleted file mode 100644 index 2fcf76d..0000000 --- a/draft-ietf-httpapi-ratelimit-headers.md~ +++ /dev/null @@ -1,1169 +0,0 @@ ---- -title: RateLimit header fields for HTTP -abbrev: -docname: draft-ietf-httpapi-ratelimit-headers-latest -category: std - -ipr: trust200902 -area: Applications and Real-Time -workgroup: HTTPAPI -keyword: Internet-Draft - -stand_alone: yes -pi: [toc, tocindent, sortrefs, symrefs, strict, compact, comments, inline, docmapping] - -venue: - group: HTTPAPI - type: Working Group - home: https://datatracker.ietf.org/wg/httpapi/about/ - mail: httpapi@ietf.org - arch: https://mailarchive.ietf.org/arch/browse/httpapi/ - repo: https://github.com/ietf-wg-httpapi/ratelimit-headers - -author: - - - ins: R. Polli - name: Roberto Polli - org: Team Digitale, Italian Government - email: robipolli@gmail.com - country: Italy - - - ins: A. Martinez - name: Alejandro Martinez Ruiz - org: Red Hat - email: alex@flawedcode.org - - - ins: D. Miller - name: Darrel Miller - org: Microsoft - email: darrel@tavis.ca - -entity: - SELF: "RFC nnnn" - -normative: - IANA: RFC8126 - HTTP: RFC9110 - -informative: - PRIVACY: RFC6973 - UNIX: - title: The Single UNIX Specification, Version 2 - 6 Vol Set for UNIX 98 - author: - name: The Open Group - ins: The Open Group - date: 1997-02 ---- abstract - -This document defines the RateLimit-Policy and RateLimit HTTP header fields for servers to advertise their service policy limits and the current limits, thereby allowing clients to avoid being throttled. - ---- middle - -# Introduction - -Rate limiting of HTTP clients has become a widespread practice, especially for HTTP APIs. Typically, servers who do so limit the number of acceptable requests in a given time window (e.g. 10 requests per second). See {{rate-limiting}} for further information on the current usage of rate limiting in HTTP. - -Currently, there is no standard way for servers to communicate quotas so that clients can throttle their requests to prevent errors. This document defines a set of standard HTTP header fields to enable rate limiting: - -- RateLimit: to convey - the server's current limit of quota units available to the client in the policy time window, - the remaining quota units in the current window, - and the time remaining in the current window, specified in seconds, and -- RateLimit-Policy: the service policy limits. - -These fields enable establishing complex rate limiting policies, including using multiple and variable time windows and dynamic quotas, and implementing concurrency limits. - -The behavior of the RateLimit header field is compatible with the delay-seconds notation of Retry-After. - -## Goals {#goals} - -The goals of this document are: - - Interoperability: - : Standardize the names and semantics of rate-limit headers - to ease their enforcement and adoption; - - Resiliency: - : Improve resiliency of HTTP infrastructure by - providing clients with information useful - to throttle their requests and - prevent 4xx or 5xx responses; - - Documentation: - : Simplify API documentation by eliminating the need - to include detailed quota limits - and related fields in API documentation. - -The following features are out of the scope of this document: - - Authorization: - : RateLimit header fields are not meant to support - authorization or other kinds of access controls. - - Response status code: - : RateLimit header fields may be returned in both - successful (see {{Section 15.3 of HTTP}}) and non-successful responses. - This specification does not cover whether non Successful - responses count on quota usage, - nor does it mandates any correlation between the RateLimit values - and the returned status code. - - Throttling algorithm: - : This specification does not mandate a specific throttling algorithm. - The values published in the fields, including the window size, - can be statically or dynamically evaluated. - - Service Level Agreement: - : Conveyed quota hints do not imply any service guarantee. - Server is free to throttle respectful clients under certain circumstances. - -## Notational Conventions - -{::boilerplate bcp14} - -The term Origin is to be interpreted as described in Section 7 of {{!WEB-ORIGIN=RFC6454}}. - -This document uses the terms List, Item and Integer from {{Section 3 of !STRUCTURED-FIELDS=RFC8941}} to specify syntax and parsing, along with the concept of "bare item". - -# Terminology - -## Quota {#quota} - -A quota is an allocation of capacity to enable a server to limit client requests. That capacity is counted in quota units and may be reallocated at the end of a time window {{time-window}}. - -## Quota Unit {#quota-unit} - -A quota unit is the unit of measure used to count the activity of a client. - -## Quota Partition {#quota-partition} - -A quota partition is a division of a server's capacity across different clients, users and owned resources. - -## Time Window {#time-window} - -A time window indicates a period of time associated to the allocated quota. - -The time window is a non-negative Integer value expressing an interval in seconds, similar to the "delay-seconds" rule defined in {{Section 10.2.3 of HTTP}}. Sub-second precision is not supported. - -## Quota Policy {#quota-policy} - -A quota policy is maintained by a server to limit the activity (counted in [quota units](#quota-unit)) of a given [quota partition](#quota-partition) over a period of time (known as the [time window](#time-window)) to a specified amount known as the [quota](#quota). - -Quota policies can be advertised by servers (see {{ratelimit-policy-field}}), but they are not required to be, and more than one quota policy can affect a given request from a client to a server. - -## Service Limit {#service-limit} - -A service limit is the current limit of the amount of activity that a server will allow based on the remaining quota for a particular quota partition within the time-window, if defined. - -# RateLimit-Policy Field {#ratelimit-policy-field} - -The "RateLimit-Policy" response header field is a non-empty List of {{quotapolicy-item}}. Its value is informative. The values are expected to remain consistent over a the lifetime of a connection. It is this characteristic that differentiates it from the [RateLimit](#ratelimit-field) that contains values that may change on every request. - -~~~ - RateLimit-Policy: burst;q=100;w=60,daily;q=1000;w=86400 -~~~ - -## Quota Policy Item {#quotapolicy-item} -A quota policy Item contains information about a server's capacity allocation for a quota partition associated with the request. - -The following parameters are defined in this specification: - - q: - : The REQUIRED "q" parameter indicates the quota allocated. ({{ratelimitpolicy-quota}}) - - qu: - : The OPTIONAL "qu" parameter value conveys the quota units associated to the "q" parameter. The default quota unit is "request". ({{ratelimitpolicy-quotaunit}}) - - w: - : The OPTIONAL "w" parameter value conveys a time "window" ({{time-window}}). ({{ratelimitpolicy-window}}) - - pk: - : The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. {{ratelimitpolicy-partitionkey}} - -Other parameters are allowed and can be regarded as comments. - -Implementation- or service-specific parameters SHOULD be prefixed parameters with a vendor identifier, e.g. `acme-policy`, `acme-burst`. - -### Quota Parameter {#ratelimitpolicy-quota} - - The "q" parameter uses a non-negative integer value to indicate the quota allocated for client activity (counted in quota units) for a given quota partition ({{service-limit}}). - -### Quota Unit Parameter {#ratelimitpolicy-quotaunit} - -The "qu" parameter value conveys the quota units associated to the "q" parameter. - -### Window Parameter {#ratelimitpolicy-window} - -The "w" parameter value conveys a time "window" in seconds. ({{time-window}}). - -### Partition Key Parameter {#ratelimitpolicy-partitionkey} - -The "pk" parameter value conveys the partition key associated to the request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key. - -## RateLimit Policy Field Examples - -This field MAY convey the time window associated with the expiring-limit, as shown in this example: - -~~~ - RateLimit-Policy: default;l=100;w=10 -~~~ - -These examples show multiple policies being returned: - -~~~ - RateLimit-Policy: permin;l=50;w=60,perhr;l=1000;w=3600,perday;l=5000;w=86400 -~~~ - -The following example shows a policy with a partition key: - -~~~ - RateLimit-Policy: peruser;l=100;w=60;pk=user123 -~~~ - -The following example shows a policy with a partition key and a quota unit: - -~~~ - RateLimit-Policy: peruser;l=65535;w=10;pk=user123;qu=bytes -~~~ - -This field cannot appear in a trailer section. - -# RateLimit Field {#ratelimit-field} - -A server uses the "RateLimit" response header field to communicate the service limit for a quota policy for a particular partition key. - -The field is expressed as List of {{servicelimit-item}}. - -~~~ - RateLimit: default;r=50;t=30 -~~~ - -## Service Limit Item {#servicelimit-item} - -Each service limit item in identifies the quota policy associated with the request and - -The following parameters are defined in this specification: - - r: - : This parameter value conveys the remaining quota units for the identified policy ({{ratelimit-remaining-parameter}}). - - t: - : This OPTIONAL parameter value conveys the time window reset time for the identified policy ({{ratelimit-reset-parameter}}). - - pk: - : The OPTIONAL "pk" parameter value conveys the partition key associated to the corresponding request. - -This field cannot appear in a trailer section. Other parameters are allowed and can be regarded as comments. - -Implementation- or service-specific parameters SHOULD be prefixed parameters with a vendor identifier, e.g. `acme-policy`, `acme-burst`. - - -### Remaining Parameter {#ratelimit-remaining-parameter} - -The "r" parameter indicates the remaining quota units for the identified policy ({{ratelimit-remaining-parameter}}). - -It is a non-negative Integer expressed in [quota units](#quota-unit). -Clients MUST NOT assume that a positive remaining value is a guarantee that further requests will be served. -When remaining parameter value is low, it indicates that the server may soon throttle the client (see {{providing-ratelimit-fields}}). - -### Reset Parameter {#ratelimit-reset-parameter} - -The "t" parameter indicates the number of seconds until the quota associated with the quota policy resets. - -It is a non-negative Integer compatible with the delay-seconds rule, because: - -- it does not rely on clock synchronization and is resilient to clock adjustment - and clock skew between client and server (see {{Section 5.6.7 of HTTP}}); -- it mitigates the risk related to thundering herd when too many clients are serviced with the same timestamp. - -The client MUST NOT assume that all its service limit will be reset at the moment indicated by the reset keyword. The server MAY arbitrarily alter the reset parameter value between subsequent requests; for example, in case of resource saturation or to implement sliding window policies. - -### Partition Key Parameter {#ratelimit-partitionkey} - -The "pk" parameter value conveys the partition key associated to the request. Servers MAY use the partition key to divide server capacity across different clients and resources. Quotas are allocated per partition key. - - -## RateLimit Field Examples - -This example shows a RateLimit field with a remaining quota of 50 units and a time window reset in 30 seconds: - -~~~ - RateLimit: default;r=50;t=30 -~~~ - -This example shows a remaining quota of 999 requests for a partition key that has no time window reset: - -~~~ - RateLimit: default;r=999;pk=trial-121323 -~~~ - -This example shows a 300MB remaining quota for an application in the next 60 seconds: - -~~~ - RateLimit: default;r=300000000;pk=App-999;t=60;qu=bytes -~~~ - - -# Server Behavior {#providing-ratelimit-fields} - -A server MAY return RateLimit header fields independently of the response status code. This includes on throttled responses. This document does not mandate any correlation between the RateLimit header field values and the returned status code. - -Servers should be careful when returning RateLimit header fields in redirection responses (i.e., responses with 3xx status codes) because a low remaining keyword value could prevent the client from issuing requests. For example, given the RateLimit header fields below, a client could decide to wait 10 seconds before following the "Location" header field (see {{Section 10.2.2 of HTTP}}), because the remaining keyword value is 0. - -~~~ http-message -HTTP/1.1 301 Moved Permanently -Location: /foo/123 -RateLimit: problemPolicy;r=0, t=10 - -~~~ - -If a response contains both the Retry-After and the RateLimit header fields, the reset keyword value SHOULD reference the same point in time as the Retry-After field value. - -A service using RateLimit header fields MUST NOT convey values exposing an unwanted volume of requests and SHOULD implement mechanisms to cap the ratio between the remaining and the reset keyword values (see {{sec-resource-exhaustion}}); this is especially important when a quota policy uses a large time window. - -Under certain conditions, a server MAY artificially lower RateLimit header field values between subsequent requests, e.g. to respond to Denial of Service attacks or in case of resource saturation. - -## Performance Considerations - -Servers are not required to return RateLimit header fields in every response, and clients need to take this into account. For example, an implementer concerned with performance might provide RateLimit header fields only when a given quota is close to exhaustion. - -Implementers concerned with response fields' size, might take into account their ratio with respect to the content length, or use header-compression HTTP features such as {{?HPACK=RFC7541}}. - -# Client Behavior {#receiving-fields} - -The RateLimit header fields can be used by clients to determine whether the associated request respected the server's quota policy, and as an indication of whether subsequent requests will. However, the server might apply other criteria when servicing future requests, and so the quota policy may not completely reflect whether requests will succeed. - -For example, a successful response with the following fields: - -~~~ - RateLimit: default;r=1;t=7 -~~~ - -does not guarantee that the next request will be successful. Servers' behavior may be subject to other conditions. - -A client is responsible for ensuring that RateLimit header field values returned -cause reasonable client behavior with respect to throughput and latency -(see {{sec-resource-exhaustion}} and {{sec-dos}}). - -A client receiving RateLimit header fields MUST NOT assume that future responses will contain the same RateLimit header fields, or any RateLimit header fields at all. - -Malformed RateLimit header fields MUST be ignored. - -A client SHOULD NOT exceed the quota units conveyed by the remaining keyword before the time window expressed in the reset keyword. - -The value of the reset keyword is generated at response time: a client aware of a significant network latency MAY behave accordingly and use other information (e.g. the "Date" response header field, or otherwise gathered metrics) to better estimate the reset keyword moment intended by the server. - -The details provided in the RateLimit-Policy header field are informative and MAY be ignored. - -If a response contains both the RateLimit and Retry-After fields, the Retry-After field MUST take precedence and the reset keyword MAY be ignored. - -This specification does not mandate a specific throttling behavior and implementers can adopt their preferred policies, including: - -- slowing down or pre-emptively back-off their request rate when - approaching quota limits; -- consuming all the quota according to the exposed limits and then wait. - -## Intermediaries {#intermediaries} - -This section documents the considerations advised in {{Section 16.3.2 of HTTP}}. - -An intermediary that is not part of the originating service infrastructure and is not aware of the quota policy semantic used by the Origin Server SHOULD NOT alter the RateLimit header fields' values in such a way as to communicate a more permissive quota policy; this includes removing the RateLimit header fields. - -An intermediary MAY alter the RateLimit header fields in such a way as to communicate a more restrictive quota policy when: - -- it is aware of the quota unit semantic used by the Origin Server; -- it implements this specification and enforces a quota policy which - is more restrictive than the one conveyed in the fields. - -An intermediary SHOULD forward a request even when presuming that it might not be serviced; the service returning the RateLimit header fields is the sole responsible of enforcing the communicated quota policy, and it is always free to service incoming requests. - -This specification does not mandate any behavior on intermediaries respect to retries, nor requires that intermediaries have any role in respecting quota policies. For example, it is legitimate for a proxy to retransmit a request without notifying the client, and thus consuming quota units. - -[Privacy considerations](#privacy) provide further guidance on intermediaries. - -## Caching - -{{?HTTP-CACHING=RFC9111}} defines how responses can be stored and reused for subsequent requests, -including those with RateLimit header fields. -Because the information in RateLimit header fields on a cached response may not be current, they SHOULD be ignored on responses that come from cache -(i.e., those with a positive current_age; see {{Section 4.2.3 of HTTP-CACHING}}). - -# Security Considerations - -## Throttling does not prevent clients from issuing requests {#sec-throttling-does-not-prevent} - -This specification does not prevent clients from making requests. -Servers should always implement mechanisms to prevent resource exhaustion. - -## Information disclosure {#sec-information-disclosure} - -Servers should not disclose to untrusted parties operational capacity information -that can be used to saturate its infrastructural resources. - -While this specification does not mandate whether non-successful responses consume quota, -if error responses (such as 401 (Unauthorized) and 403 (Forbidden)) count against quota, -a malicious client could probe the endpoint to get traffic information of another user. - -As intermediaries might retransmit requests and consume -quota units without prior knowledge of the user agent, -RateLimit header fields might reveal the existence of an intermediary -to the user agent. - -Where partition keys contain identifying information, either of the client application or the user, servers should be aware of the potential for impersonation and apply the appropriate security mechanisms. - -## Remaining quota units are not granted requests {#sec-remaining-not-granted} - -RateLimit header fields convey hints from the server -to the clients in order to help them avoid being throttled out. - -Clients MUST NOT consider the [quota units](#service-limit) returned in remaining keyword as a service level agreement. - -In case of resource saturation, the server MAY artificially lower the returned values -or not serve the request regardless of the advertised quotas. - -## Reliability of the reset keyword {#sec-reset-reliability} - -Consider that quota might not be restored after the moment referenced by the [reset keyword](#ratelimit-reset-parameter), -and the reset parameter value may not be constant. - -Subsequent requests might return a higher reset parameter value -to limit concurrency or implement dynamic or adaptive throttling policies. - -## Resource exhaustion {#sec-resource-exhaustion} - -When returning reset values, servers must be aware that -many throttled clients may come back at the very moment specified. - -This is true for Retry-After too. - -For example, if the quota resets every day at `18:00:00` -and your server returns the reset parameter accordingly - -~~~ - Date: Tue, 15 Nov 1994 18:00:00 GMT - RateLimit: daily;r=1;t=36400 -~~~ - -there's a high probability that all clients will show up at `18:00:00`. - -This could be mitigated by adding some jitter to the reset value. - -Resource exhaustion issues can be associated with quota policies using a -large time window, because a user agent by chance or on purpose -might consume most of its quota units in a significantly shorter interval. - -This behavior can be even triggered by the provided RateLimit header fields. -The following example describes a service -with an unconsumed quota policy of 10000 quota units per 1000 seconds. - -~~~ -RateLimit-Policy: somepolicy;l=10000;w=1000 -RateLimit: somepolicy;r=10000;t=10 -~~~ - -A client implementing a simple ratio between remaining keyword and reset keyword could infer an average throughput of 1000 quota units per second, while the limit keyword conveys a quota-policy with an average of 10 quota units per second. -If the service cannot handle such load, it should return either a lower remaining keyword value or an higher reset keyword value. -Moreover, complementing large time window quota policies with a short time window one mitigates those risks. - - -### Denial of Service {#sec-dos} - -RateLimit header fields may contain unexpected values by chance or on purpose. -For example, an excessively high remaining keyword value may be: - -- used by a malicious intermediary to trigger a Denial of Service attack - or consume client resources boosting its requests; -- passed by a misconfigured server; - -or a high reset keyword value could inhibit clients to contact the server (e.g. similarly to receiving "Retry-after: 1000000"). - -To mitigate this risk, clients can set thresholds that they consider reasonable in terms of quota units, time window, concurrent requests or throughput, and define a consistent behavior when the RateLimit exceed those thresholds. -For example this means capping the maximum number of request per second, or implementing retries when the reset keyword exceeds ten minutes. - -The considerations above are not limited to RateLimit header fields, but apply to all fields affecting how clients behave in subsequent requests (e.g. Retry-After). - - -# Privacy Considerations {#privacy} - -Clients that act upon a request to rate limit -are potentially re-identifiable (see {{Section 5.2.1 of PRIVACY}}) -because they react to information that might only be given to them. -Note that this might apply to other fields too (e.g. Retry-After). - -Since rate limiting is usually implemented in contexts where -clients are either identified or profiled -(e.g. assigning different quota units to different users), -this is rarely a concern. - -Privacy enhancing infrastructures using RateLimit header fields -can define specific techniques to mitigate the risks of re-identification. - -# IANA Considerations - -IANA is requested to update one registry and create one new registry. - -Please add the following entries to the -"Hypertext Transfer Protocol (HTTP) Field Name Registry" registry ({{HTTP}}): - -|---------------------|-----------|---------------| -| Field Name | Status | Specification | -|---------------------|-----------|---------------| -| RateLimit | permanent | {{ratelimit-field}} of {{&SELF}} | -| RateLimit-Policy | permanent | {{ratelimit-policy-field}} of {{&SELF}} | -|---------------------|-----------|---------------| - - ---- back - -# Rate-limiting and quotas {#rate-limiting} - -Servers use quota mechanisms to avoid systems overload, to ensure an equitable distribution of computational resources or to enforce other policies - e.g. monetization. - -A basic quota mechanism limits the number of acceptable requests in a given time window, e.g. 10 requests per second. - -When quota is exceeded, servers usually do not serve the request replying instead with a 4xx HTTP status code (e.g. 429 or 403) or adopt more aggressive policies like dropping connections. - -Quotas may be enforced on different basis (e.g. per user, per IP, per geographic area, ..) and at different levels. For example, an user may be allowed to issue: - -- 10 requests per second; -- limited to 60 requests per minute; -- limited to 1000 requests per hour. - -Moreover system metrics, statistics and heuristics can be used to implement more complex policies, -where the number of acceptable requests and the time window are computed dynamically. - -To help clients throttling their requests, -servers may expose the counters used to evaluate quota policies via HTTP header fields. - -Those response headers may be added by HTTP intermediaries such as API gateways and reverse proxies. - -On the web we can find many different rate-limit headers, -usually containing the number of allowed requests in a given time window, and when the window is reset. - -The common choice is to return three headers containing: - -- the maximum number of allowed requests in the time window; -- the number of remaining requests in the current window; -- the time remaining in the current window expressed in seconds or - as a timestamp; - -## Interoperability issues - -A major interoperability issue in throttling is the lack of standard headers, because: - -- each implementation associates different semantics to the - same header field names; -- header field names proliferates. - -User agents interfacing with different servers may thus need to process different headers, -or the very same application interface that sits behind different reverse proxies -may reply with different throttling headers. - -# Examples - -## Responses without defining policies - -Some servers may not expose the policy limits in the RateLimit-Policy header field. Clients can still use the RateLimit header field to throttle their requests. - -### Throttling information in responses - -The client exhausted its quota for the next 50 seconds. -The limit and time-window is communicated out-of-band. - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 200 Ok -Content-Type: application/json -RateLimit: default;r=0;t=50 - -{"hello": "world"} -~~~ - -Since the field values are not necessarily correlated with -the response status code, -a subsequent request is not required to fail. -The example below shows that the server decided to serve the request -even if remaining keyword value is 0. -Another server, or the same server under other load conditions, could have decided to throttle the request instead. - -Request: - -~~~ http-message -GET /items/456 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 200 Ok -Content-Type: application/json -RateLimit: default;r=0;t=48 - -{"still": "successful"} -~~~ - -### Multiple policies in response {#use-with-multiple-policies} - -The server uses two different policies to limit the client's requests: - -- 5000 daily quota units; -- 1000 hourly quota units. - -The client consumed 4900 quota units in the first 14 hours. - -Despite the next hourly limit of 1000 quota units, -the closest limit to reach is the daily one. - -The server then exposes the RateLimit header fields to -inform the client that: - -- it has only 100 quota units left in the daily quota and the window will reset in 10 hours; - -The server MAY choose to omit returning the hourly policy as it uses the same quota units as the daily policy and the daily policy is the one that is closest to being exhausted. - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 200 Ok -Content-Type: application/json -RateLimit: dayLimit;r=100;t=36000 - -{"hello": "world"} -~~~ - -### Use for limiting concurrency {#use-for-limiting-concurrency} - -RateLimit header fields may be used to limit concurrency, -advertising limits that are lower than the usual ones -in case of saturation, thus increasing availability. - -The server adopted a basic policy of 100 quota units per minute, -and in case of resource exhaustion adapts the returned values -reducing both limit and remaining keyword values. - -After 2 seconds the client consumed 40 quota units - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 200 Ok -Content-Type: application/json -RateLimit-Policy: basic;l=100;w=60 -RateLimit: basic;r=60;t=58 - -{"elapsed": 2, "issued": 40} -~~~ - -At the subsequent request - due to resource exhaustion - -the server advertises only `r=20`. - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 200 Ok -Content-Type: application/json -RateLimit-Policy: basic;l=100;w=60 -RateLimit: basic;r=20;t=56 - -{"elapsed": 4, "issued": 41} -~~~ - -### Use in throttled responses - -A client exhausted its quota and the server throttles it -sending Retry-After. - -In this example, the values of Retry-After and RateLimit header field reference the same moment, -but this is not a requirement. - -The 429 (Too Many Request) HTTP status code is just used as an example. - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 429 Too Many Requests -Content-Type: application/json -Date: Mon, 05 Aug 2019 09:27:00 GMT -Retry-After: Mon, 05 Aug 2019 09:27:05 GMT -RateLimit: default;r=0;t=5 - -{ -"title": "Too Many Requests", -"status": 429, -"detail": "You have exceeded your quota" -} -~~~ - -## Responses with defined policies - -### Throttling window specified via parameter - -The client has 99 quota units left for the next 50 seconds. -The time window is communicated by the `w` parameter, so we know the throughput is 100 quota units per minute. - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 200 Ok -Content-Type: application/json -RateLimit: fixedwindow;r=99;t=50 -RateLimit-Policy: fixedwindow;l=100;w=60 -{"hello": "world"} -~~~ - - -### Dynamic limits with parameterized windows - -The policy conveyed by the RateLimit header field states that -the server accepts 100 quota units per minute. - -To avoid resource exhaustion, the server artificially lowers -the actual limits returned in the throttling headers. - -The remaining keyword then advertises -only 9 quota units for the next 50 seconds to slow down the client. - -Note that the server could have lowered even the other -values in the RateLimit header field: this specification -does not mandate any relation between the field values -contained in subsequent responses. - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 200 Ok -Content-Type: application/json -RateLimit-Policy: dynamic;l=100;w=60 -RateLimit: dynamic;r=9;t=50 - - -{ - "status": 200, - "detail": "Just slow down without waiting." -} -~~~ - -### Dynamic limits for pushing back and slowing down - -Continuing the previous example, let's say the client waits 10 seconds and -performs a new request which, due to resource exhaustion, the server rejects -and pushes back, advertising `r=0` for the next 20 seconds. - -The server advertises a smaller window with a lower limit to slow -down the client for the rest of its original window after the 20 seconds elapse. - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 429 Too Many Requests -Content-Type: application/json -RateLimit-Policy: dynamic;l=15;w=20 -RateLimit: dynamic;r=0;t=20 - -{ - "status": 429, - "detail": "Wait 20 seconds, then slow down!" -} -~~~ - -## Dynamic limits for pushing back with Retry-After and slow down - -Alternatively, given the same context where the previous example starts, we -can convey the same information to the client via Retry-After, with -the advantage that the server can now specify the policy's nominal limit and -window that will apply after the reset, e.g. assuming the resource exhaustion -is likely to be gone by then, so the advertised policy does not need to be -adjusted, yet we managed to stop requests for a while and slow down the rest of -the current window. - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 429 Too Many Requests -Content-Type: application/json -Retry-After: 20 -RateLimit-Policy: dynamic;l=100;w=60 -RateLimit: dynamic;r=15;t=40 - -{ - "status": 429, - "detail": "Wait 20 seconds, then slow down!" -} -~~~ - -Note that in this last response the client is expected to honor -Retry-After and perform no requests for the specified amount of -time, whereas the previous example would not force the client to stop -requests before the reset time is elapsed, as it would still be free to -query again the server even if it is likely to have the request rejected. - -### Missing Remaining information - -The server does not expose remaining values -(for example, because the underlying counters are not available). -Instead, it resets the limit counter every second. - -It communicates to the client the limit of 10 quota units per second -always returning the limit and reset keywords. - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 200 Ok -Content-Type: application/json -RateLimit-Policy: quota;l=100;w=1 -RateLimit: quota;t=1 - -{"first": "request"} -~~~ - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 200 Ok -Content-Type: application/json -RateLimit-Policy: quota;l=10 -RateLimit: quota;t=1 - -{"second": "request"} -~~~ - -### Use with multiple windows - -This is a standardized way of describing the policy -detailed in {{use-with-multiple-policies}}: - -- 5000 daily quota units; -- 1000 hourly quota units. - -The client consumed 4900 quota units in the first 14 hours. - -Despite the next hourly limit of 1000 quota units, the closest limit -to reach is the daily one. - -The server then exposes the RateLimit header fields to inform the client that: - -- it has only 100 quota units left; -- the window will reset in 10 hours; -- the expiring-limit is 5000. - -Request: - -~~~ http-message -GET /items/123 HTTP/1.1 -Host: api.example - -~~~ - -Response: - -~~~ http-message -HTTP/1.1 200 OK -Content-Type: application/json -RateLimit-Policy: hour;l=1000;w=3600, day;l=5000;w=86400 -RateLimit: day;r=100;t=36000 - -{"hello": "world"} -~~~ - -# FAQ -{:numbered="false" removeinrfc="true"} - -1. Why defining standard fields for throttling? - - To simplify enforcement of throttling policies and enable clients to constraint their requests to avoid being throttled. - -2. Can I use RateLimit header fields in throttled responses (eg with status code 429)? - - Yes, you can. - -3. Are those specs tied to RFC 6585? - - No. {{?RFC6585}} defines the `429` status code and we use it just as an example of a throttled request, - that could instead use even `403` or whatever status code. - -4. Why is the partition key necessary? - - Without a partition key, a server can only effectively only have one scope (aka partition), which is impractical for most services, or it needs to communicate the scopes out-of-band. - This prevents the development of generic connector code that can be used to prevent requests from being throttled. - Many APIs rely on API keys, user identity or client identity to allocate quota. - As soon as a single client processes requests for more than one partition, the client needs to know the corresponding partition key to properly track requests against allocated quota. - -5. Why using delay-seconds instead of a UNIX Timestamp? - Why not using subsecond precision? - - Using delay-seconds aligns with Retry-After, which is returned in similar contexts, - eg on 429 responses. - - Timestamps require a clock synchronization protocol - (see {{Section 5.6.7 of HTTP}}). - This may be problematic (e.g. clock adjustment, clock skew, failure of hardcoded clock synchronization servers, - IoT devices, ..). - Moreover timestamps may not be monotonically increasing due to clock adjustment. - See [Another NTP client failure story](https://community.ntppool.org/t/another-ntp-client-failure-story/1014/) - - We did not use subsecond precision because: - - - that is more subject to system clock correction - like the one implemented via the adjtimex() Linux system call; - - response-time latency may not make it worth. A brief discussion on the subject is - on the [httpwg ml](https://lists.w3.org/Archives/Public/ietf-http-wg/2019JulSep/0202.html) - - almost all rate-limit headers implementations do not use it. - -6. Shouldn't I limit concurrency instead of request rate? - - You can use this specification to limit concurrency - at the HTTP level (see {#use-for-limiting-concurrency}) - and help clients to shape their requests avoiding being throttled out. - - A problematic way to limit concurrency is connection dropping, - especially when connections are multiplexed (e.g. HTTP/2) - because this results in unserviced client requests, - which is something we want to avoid. - - A semantic way to limit concurrency is to return 503 + Retry-After - in case of resource saturation (e.g. thrashing, connection queues too long, - Service Level Objectives not meet, ..). - Saturation conditions can be either dynamic or static: all this is out of - the scope for the current document. - -7. Do a positive value of remaining paramter imply any service guarantee for my - future requests to be served? - - No. FAQ integrated in {{ratelimit-remaining-parameter}}. - -8. Is the quota-policy definition {{quota-policy}} too complex? - - You can always return the simplest form - -~~~ -RateLimit:default;r=50;t=60 -~~~ - - The policy key clearly connects the current usage status of a policy to the defined limits. - So for the following field: - -~~~ -RateLimit-Policy: sliding;l=100;w=60;burst=1000;comment="sliding window", fixed;l=5000;w=3600;burst=0;comment="fixed window" -RateLimit: sliding;r=50;t=44 -~~~ - - the value "sliding" identifies the policy being reported. - -9. Can intermediaries alter RateLimit header fields? - - Generally, they should not because it might result in unserviced requests. - There are reasonable use cases for intermediaries mangling RateLimit header fields though, - e.g. when they enforce stricter quota-policies, - or when they are an active component of the service. - In those case we will consider them as part of the originating infrastructure. - -10. Why the `w` parameter is just informative? - Could it be used by a client to determine the request rate? - - A non-informative `w` parameter might be fine in an environment - where clients and servers are tightly coupled. Conveying policies - with this detail on a large scale would be very complex and implementations - would be likely not interoperable. We thus decided to leave `w` as - an informational parameter and only rely on the limit, remaining and reset keywords - for defining the throttling - behavior. - -11. Can I use RateLimit fields in trailers? - Servers usually establish whether the request is in-quota before creating a response, so the RateLimit field values should be already available in that moment. - Supporting trailers has the only advantage that allows to provide more up-to-date information to the client in case of slow responses. - However, this complicates client implementations with respect to combining fields from headers and accounting for intermediaries that drop trailers. - Since there are no current implementations that use trailers, we decided to leave this as a future-work. - -# RateLimit header fields currently used on the web -{:numbered="false" removeinrfc="true"} - -Commonly used header field names are: - -- `X-RateLimit-Limit`, - `X-RateLimit-Remaining`, - `X-RateLimit-Reset`; - -There are variants too, where the window is specified -in the header field name, eg: - -- `x-ratelimit-limit-minute`, `x-ratelimit-limit-hour`, `x-ratelimit-limit-day` -- `x-ratelimit-remaining-minute`, `x-ratelimit-remaining-hour`, `x-ratelimit-remaining-day` - -Here are some interoperability issues: - -- `X-RateLimit-Remaining` references different values, depending on the implementation: - - * seconds remaining to the window expiration - * milliseconds remaining to the window expiration - * seconds since UTC, in UNIX Timestamp [UNIX] - * a datetime, either `IMF-fixdate` {{HTTP}} or {{?RFC3339}} - -- different headers, with the same semantic, are used by different implementers: - - * X-RateLimit-Limit and X-Rate-Limit-Limit - * X-RateLimit-Remaining and X-Rate-Limit-Remaining - * X-RateLimit-Reset and X-Rate-Limit-Reset - -The semantic of RateLimit depends on the windowing algorithm. -A sliding window policy for example, may result in having a remaining keyword value related to the ratio between the current and the maximum throughput. -e.g. - -~~~ -RateLimit-Policy: sliding;l=12;w=1 -RateLimit: sliding;l=12;r=6;t=1 ; using 50% of throughput, that is 6 units/s - -~~~ - -If this is the case, the optimal solution is to achieve - -~~~ -RateLimit-Policy: sliding;l=12;w=1 -RateLimit: sliding;l=12;r=1;t=1 ; using 100% of throughput, that is 12 units/s -~~~ - -At this point you should stop increasing your request rate. - -# Acknowledgements -{:numbered="false"} - -Thanks to Willi Schoenborn, Alejandro Martinez Ruiz, Alessandro Ranellucci, -Amos Jeffries, -Martin Thomson, -Erik Wilde and Mark Nottingham for being the initial contributors -of these specifications. -Kudos to the first community implementers: -Aapo Talvensaari, -Nathan Friedly -and Sanyam Dogra. - -In addition to the people above, this document owes a lot to the extensive discussion in the HTTPAPI workgroup, including -Rich Salz, -Darrel Miller -and Julian Reschke. - -# Changes -{:numbered="false" removeinrfc="true"} - -## Since draft-ietf-httpapi-ratelimit-headers-07 -{:numbered="false" removeinrfc="true"} - -* Refactored both fields to lists of Items that identify policy and use parameters -* Added quota unit parameter -* Added partition key parameter - - -## Since draft-ietf-httpapi-ratelimit-headers-03 -{:numbered="false" removeinrfc="true"} - -* Split policy informatiom in RateLimit-Policy #81 - - -## Since draft-ietf-httpapi-ratelimit-headers-02 -{:numbered="false" removeinrfc="true"} - -* Address throttling scope #83 - -## Since draft-ietf-httpapi-ratelimit-headers-01 -{:numbered="false" removeinrfc="true"} - -* Update IANA considerations #60 -* Use Structured fields #58 -* Reorganize document #67 - -## Since draft-ietf-httpapi-ratelimit-headers-00 -{:numbered="false" removeinrfc="true"} - -* Use I-D.httpbis-semantics, which includes referencing delay-seconds - instead of delta-seconds. #5 diff --git a/draft-ietf-httpapi-ratelimit-headers.txt b/draft-ietf-httpapi-ratelimit-headers.txt deleted file mode 100644 index 1deaa44..0000000 --- a/draft-ietf-httpapi-ratelimit-headers.txt +++ /dev/null @@ -1,1435 +0,0 @@ - - - - -HTTPAPI R. Polli -Internet-Draft Team Digitale, Italian Government -Intended status: Standards Track A. Martinez -Expires: 2 April 2025 Red Hat - D. Miller - Microsoft - 29 September 2024 - - - RateLimit header fields for HTTP - draft-ietf-httpapi-ratelimit-headers-latest - -Abstract - - This document defines the RateLimit-Policy and RateLimit HTTP header - fields for servers to advertise their service policy limits and the - current limits, thereby allowing clients to avoid being throttled. - -About This Document - - This note is to be removed before publishing as an RFC. - - Status information for this document may be found at - https://datatracker.ietf.org/doc/draft-ietf-httpapi-ratelimit- - headers/. - - Discussion of this document takes place on the HTTPAPI Working Group - mailing list (mailto:httpapi@ietf.org), which is archived at - https://mailarchive.ietf.org/arch/browse/httpapi/. Subscribe at - https://www.ietf.org/mailman/listinfo/httpapi/. Working Group - information can be found at https://datatracker.ietf.org/wg/httpapi/ - about/. - - Source for this draft and an issue tracker can be found at - https://github.com/ietf-wg-httpapi/ratelimit-headers. - -Status of This Memo - - This Internet-Draft is submitted in full conformance with the - provisions of BCP 78 and BCP 79. - - Internet-Drafts are working documents of the Internet Engineering - Task Force (IETF). Note that other groups may also distribute - working documents as Internet-Drafts. The list of current Internet- - Drafts is at https://datatracker.ietf.org/drafts/current/. - - Internet-Drafts are draft documents valid for a maximum of six months - and may be updated, replaced, or obsoleted by other documents at any - time. It is inappropriate to use Internet-Drafts as reference - material or to cite them other than as "work in progress." - - This Internet-Draft will expire on 2 April 2025. - -Copyright Notice - - Copyright (c) 2024 IETF Trust and the persons identified as the - document authors. All rights reserved. - - This document is subject to BCP 78 and the IETF Trust's Legal - Provisions Relating to IETF Documents (https://trustee.ietf.org/ - license-info) in effect on the date of publication of this document. - Please review these documents carefully, as they describe your rights - and restrictions with respect to this document. Code Components - extracted from this document must include Revised BSD License text as - described in Section 4.e of the Trust Legal Provisions and are - provided without warranty as described in the Revised BSD License. - -Table of Contents - - 1. Introduction - 1.1. Goals - 1.2. Notational Conventions - 2. Terminology - 2.1. Quota - 2.2. Quota Unit - 2.3. Quota Partition - 2.4. Time Window - 2.5. Quota Policy - 2.6. Service Limit - 3. RateLimit-Policy Field - 3.1. Quota Policy Item - 3.1.1. Quota Parameter - 3.1.2. Quota Unit Parameter - 3.1.3. Window Parameter - 3.1.4. Partition Key Parameter - 3.2. RateLimit Policy Field Examples - 4. RateLimit Field - 4.1. Service Limit Item - 4.1.1. Remaining Parameter - 4.1.2. Reset Parameter - 4.1.3. Partition Key Parameter - 4.2. RateLimit Field Examples - 5. Server Behavior - 5.1. Performance Considerations - 6. Client Behavior - 6.1. Intermediaries - 6.2. Caching - 7. Security Considerations - 7.1. Throttling does not prevent clients from issuing requests - 7.2. Information disclosure - 7.3. Remaining quota units are not granted requests - 7.4. Reliability of the reset keyword - 7.5. Resource exhaustion - 7.5.1. Denial of Service - 8. Privacy Considerations - 9. IANA Considerations - 10. References - 10.1. Normative References - 10.2. Informative References - Appendix A. Rate-limiting and quotas - A.1. Interoperability issues - Appendix B. Examples - B.1. Responses without defining policies - B.1.1. Throttling information in responses - B.1.2. Multiple policies in response - B.1.3. Use for limiting concurrency - B.1.4. Use in throttled responses - B.2. Responses with defined policies - B.2.1. Throttling window specified via parameter - B.2.2. Dynamic limits with parameterized windows - B.2.3. Dynamic limits for pushing back and slowing down - B.3. Dynamic limits for pushing back with Retry-After and slow - down - B.3.1. Missing Remaining information - B.3.2. Use with multiple windows - FAQ - RateLimit header fields currently used on the web - Acknowledgements - Changes - Since draft-ietf-httpapi-ratelimit-headers-07 - Since draft-ietf-httpapi-ratelimit-headers-03 - Since draft-ietf-httpapi-ratelimit-headers-02 - Since draft-ietf-httpapi-ratelimit-headers-01 - Since draft-ietf-httpapi-ratelimit-headers-00 - Authors' Addresses - -1. Introduction - - Rate limiting of HTTP clients has become a widespread practice, - especially for HTTP APIs. Typically, servers who do so limit the - number of acceptable requests in a given time window (e.g. 10 - requests per second). See Appendix A for further information on the - current usage of rate limiting in HTTP. - - Currently, there is no standard way for servers to communicate quotas - so that clients can throttle their requests to prevent errors. This - document defines a set of standard HTTP header fields to enable rate - limiting: - - * RateLimit: to convey the server's current limit of quota units - available to the client in the policy time window, the remaining - quota units in the current window, and the time remaining in the - current window, specified in seconds, and - - * RateLimit-Policy: the service policy limits. - - These fields enable establishing complex rate limiting policies, - including using multiple and variable time windows and dynamic - quotas, and implementing concurrency limits. - - The behavior of the RateLimit header field is compatible with the - delay-seconds notation of Retry-After. - -1.1. Goals - - The goals of this document are: - - Interoperability: Standardize the names and semantics of rate-limit - headers to ease their enforcement and adoption; - - Resiliency: Improve resiliency of HTTP infrastructure by providing - clients with information useful to throttle their requests and - prevent 4xx or 5xx responses; - - Documentation: Simplify API documentation by eliminating the need to - include detailed quota limits and related fields in API - documentation. - - The following features are out of the scope of this document: - - Authorization: RateLimit header fields are not meant to support - authorization or other kinds of access controls. - - Response status code: RateLimit header fields may be returned in - both successful (see Section 15.3 of [HTTP]) and non-successful - responses. This specification does not cover whether non - Successful responses count on quota usage, nor does it mandates - any correlation between the RateLimit values and the returned - status code. - - Throttling algorithm: This specification does not mandate a specific - throttling algorithm. The values published in the fields, - including the window size, can be statically or dynamically - evaluated. - - Service Level Agreement: Conveyed quota hints do not imply any - service guarantee. Server is free to throttle respectful clients - under certain circumstances. - -1.2. Notational Conventions - - The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", - "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and - "OPTIONAL" in this document are to be interpreted as described in - BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all - capitals, as shown here. - - The term Origin is to be interpreted as described in Section 7 of - [WEB-ORIGIN]. - - This document uses the terms List, Item and Integer from Section 3 of - [STRUCTURED-FIELDS] to specify syntax and parsing, along with the - concept of "bare item". - -2. Terminology - -2.1. Quota - - A quota is an allocation of capacity to enable a server to limit - client requests. That capacity is counted in quota units and may be - reallocated at the end of a time window Section 2.4. - -2.2. Quota Unit - - A quota unit is the unit of measure used to count the activity of a - client. - -2.3. Quota Partition - - A quota partition is a division of a server's capacity across - different clients, users and owned resources. - -2.4. Time Window - - A time window indicates a period of time associated to the allocated - quota. - - The time window is a non-negative Integer value expressing an - interval in seconds, similar to the "delay-seconds" rule defined in - Section 10.2.3 of [HTTP]. Sub-second precision is not supported. - -2.5. Quota Policy - - A quota policy is maintained by a server to limit the activity - (counted in quota units (Section 2.2)) of a given quota partition - (Section 2.3) over a period of time (known as the time window - (Section 2.4)) to a specified amount known as the Section 2.1. - - Quota policies can be advertised by servers (see Section 3), but they - are not required to be, and more than one quota policy can affect a - given request from a client to a server. - -2.6. Service Limit - - A service limit is the current limit of the amount of activity that a - server will allow based on the remaining quota for a particular quota - partition within the time-window, if defined. - -3. RateLimit-Policy Field - - The "RateLimit-Policy" response header field is a non-empty List of - Section 3.1. Its value is informative. The values are expected to - remain consistent over a the lifetime of a connection. It is this - characteristic that differentiates it from the RateLimit (Section 4) - that contains values that may change on every request. - - RateLimit-Policy: burst;q=100;w=60,daily;q=1000;w=86400 - -3.1. Quota Policy Item - - A quota policy Item contains information about a server's capacity - allocation for a quota partition associated with the request. - - The following parameters are defined in this specification: - - q: The REQUIRED "q" parameter indicates the quota allocated. - (Section 3.1.1) - - qu: The OPTIONAL "qu" parameter value conveys the quota units - associated to the "q" parameter. The default quota unit is - "request". (Section 3.1.2) - - w: The OPTIONAL "w" parameter value conveys a time "window" - (Section 2.4). (Section 3.1.3) - - pk: The OPTIONAL "pk" parameter value conveys the partition key - associated to the corresponding request. Section 3.1.4 - - Other parameters are allowed and can be regarded as comments. - - Implementation- or service-specific parameters SHOULD be prefixed - parameters with a vendor identifier, e.g. acme-policy, acme-burst. - -3.1.1. Quota Parameter - - The "q" parameter uses a non-negative integer value to indicate the - quota allocated for client activity (counted in quota units) for a - given quota partition (Section 2.6). - -3.1.2. Quota Unit Parameter - - The "qu" parameter value conveys the quota units associated to the - "q" parameter. - -3.1.3. Window Parameter - - The "w" parameter value conveys a time "window" in seconds. - (Section 2.4). - -3.1.4. Partition Key Parameter - - The "pk" parameter value conveys the partition key associated to the - request. Servers MAY use the partition key to divide server capacity - across different clients and resources. Quotas are allocated per - partition key. - -3.2. RateLimit Policy Field Examples - - This field MAY convey the time window associated with the expiring- - limit, as shown in this example: - - RateLimit-Policy: default;l=100;w=10 - - These examples show multiple policies being returned: - - RateLimit-Policy: permin;l=50;w=60,perhr;l=1000;w=3600,perday;l=5000;w=86400 - - The following example shows a policy with a partition key: - - RateLimit-Policy: peruser;l=100;w=60;pk=user123 - - The following example shows a policy with a partition key and a quota - unit: - - RateLimit-Policy: peruser;l=65535;w=10;pk=user123;qu=bytes - - This field cannot appear in a trailer section. - -4. RateLimit Field - - A server uses the "RateLimit" response header field to communicate - the service limit for a quota policy for a particular partition key. - - The field is expressed as List of Section 4.1. - - RateLimit: default;r=50;t=30 - -4.1. Service Limit Item - - Each service limit item in identifies the quota policy associated - with the request and - - The following parameters are defined in this specification: - - r: This parameter value conveys the remaining quota units for the - identified policy (Section 4.1.1). - - t: This OPTIONAL parameter value conveys the time window reset time - for the identified policy (Section 4.1.2). - - pk: The OPTIONAL "pk" parameter value conveys the partition key - associated to the corresponding request. - - This field cannot appear in a trailer section. Other parameters are - allowed and can be regarded as comments. - - Implementation- or service-specific parameters SHOULD be prefixed - parameters with a vendor identifier, e.g. acme-policy, acme-burst. - -4.1.1. Remaining Parameter - - The "r" parameter indicates the remaining quota units for the - identified policy (Section 4.1.1). - - It is a non-negative Integer expressed in quota units (Section 2.2). - Clients MUST NOT assume that a positive remaining value is a - guarantee that further requests will be served. When remaining - parameter value is low, it indicates that the server may soon - throttle the client (see Section 5). - -4.1.2. Reset Parameter - - The "t" parameter indicates the number of seconds until the quota - associated with the quota policy resets. - - It is a non-negative Integer compatible with the delay-seconds rule, - because: - - * it does not rely on clock synchronization and is resilient to - clock adjustment and clock skew between client and server (see - Section 5.6.7 of [HTTP]); - - * it mitigates the risk related to thundering herd when too many - clients are serviced with the same timestamp. - - The client MUST NOT assume that all its service limit will be reset - at the moment indicated by the reset keyword. The server MAY - arbitrarily alter the reset parameter value between subsequent - requests; for example, in case of resource saturation or to implement - sliding window policies. - -4.1.3. Partition Key Parameter - - The "pk" parameter value conveys the partition key associated to the - request. Servers MAY use the partition key to divide server capacity - across different clients and resources. Quotas are allocated per - partition key. - -4.2. RateLimit Field Examples - - This example shows a RateLimit field with a remaining quota of 50 - units and a time window reset in 30 seconds: - - RateLimit: default;r=50;t=30 - - This example shows a remaining quota of 999 requests for a partition - key that has no time window reset: - - RateLimit: default;r=999;pk=trial-121323 - - This example shows a 300MB remaining quota for an application in the - next 60 seconds: - - RateLimit: default;r=300000000;pk=App-999;t=60;qu=bytes - -5. Server Behavior - - A server MAY return RateLimit header fields independently of the - response status code. This includes on throttled responses. This - document does not mandate any correlation between the RateLimit - header field values and the returned status code. - - Servers should be careful when returning RateLimit header fields in - redirection responses (i.e., responses with 3xx status codes) because - a low remaining keyword value could prevent the client from issuing - requests. For example, given the RateLimit header fields below, a - client could decide to wait 10 seconds before following the - "Location" header field (see Section 10.2.2 of [HTTP]), because the - remaining keyword value is 0. - - HTTP/1.1 301 Moved Permanently - Location: /foo/123 - RateLimit: problemPolicy;r=0, t=10 - - If a response contains both the Retry-After and the RateLimit header - fields, the reset keyword value SHOULD reference the same point in - time as the Retry-After field value. - - A service using RateLimit header fields MUST NOT convey values - exposing an unwanted volume of requests and SHOULD implement - mechanisms to cap the ratio between the remaining and the reset - keyword values (see Section 7.5); this is especially important when a - quota policy uses a large time window. - - Under certain conditions, a server MAY artificially lower RateLimit - header field values between subsequent requests, e.g. to respond to - Denial of Service attacks or in case of resource saturation. - -5.1. Performance Considerations - - Servers are not required to return RateLimit header fields in every - response, and clients need to take this into account. For example, - an implementer concerned with performance might provide RateLimit - header fields only when a given quota is close to exhaustion. - - Implementers concerned with response fields' size, might take into - account their ratio with respect to the content length, or use - header-compression HTTP features such as [HPACK]. - -6. Client Behavior - - The RateLimit header fields can be used by clients to determine - whether the associated request respected the server's quota policy, - and as an indication of whether subsequent requests will. However, - the server might apply other criteria when servicing future requests, - and so the quota policy may not completely reflect whether requests - will succeed. - - For example, a successful response with the following fields: - - RateLimit: default;r=1;t=7 - - does not guarantee that the next request will be successful. - Servers' behavior may be subject to other conditions. - - A client is responsible for ensuring that RateLimit header field - values returned cause reasonable client behavior with respect to - throughput and latency (see Section 7.5 and Section 7.5.1). - - A client receiving RateLimit header fields MUST NOT assume that - future responses will contain the same RateLimit header fields, or - any RateLimit header fields at all. - - Malformed RateLimit header fields MUST be ignored. - - A client SHOULD NOT exceed the quota units conveyed by the remaining - keyword before the time window expressed in the reset keyword. - - The value of the reset keyword is generated at response time: a - client aware of a significant network latency MAY behave accordingly - and use other information (e.g. the "Date" response header field, or - otherwise gathered metrics) to better estimate the reset keyword - moment intended by the server. - - The details provided in the RateLimit-Policy header field are - informative and MAY be ignored. - - If a response contains both the RateLimit and Retry-After fields, the - Retry-After field MUST take precedence and the reset keyword MAY be - ignored. - - This specification does not mandate a specific throttling behavior - and implementers can adopt their preferred policies, including: - - * slowing down or pre-emptively back-off their request rate when - approaching quota limits; - - * consuming all the quota according to the exposed limits and then - wait. - -6.1. Intermediaries - - This section documents the considerations advised in Section 16.3.2 - of [HTTP]. - - An intermediary that is not part of the originating service - infrastructure and is not aware of the quota policy semantic used by - the Origin Server SHOULD NOT alter the RateLimit header fields' - values in such a way as to communicate a more permissive quota - policy; this includes removing the RateLimit header fields. - - An intermediary MAY alter the RateLimit header fields in such a way - as to communicate a more restrictive quota policy when: - - * it is aware of the quota unit semantic used by the Origin Server; - - * it implements this specification and enforces a quota policy which - is more restrictive than the one conveyed in the fields. - - An intermediary SHOULD forward a request even when presuming that it - might not be serviced; the service returning the RateLimit header - fields is the sole responsible of enforcing the communicated quota - policy, and it is always free to service incoming requests. - - This specification does not mandate any behavior on intermediaries - respect to retries, nor requires that intermediaries have any role in - respecting quota policies. For example, it is legitimate for a proxy - to retransmit a request without notifying the client, and thus - consuming quota units. - - Privacy considerations (Section 8) provide further guidance on - intermediaries. - -6.2. Caching - - [HTTP-CACHING] defines how responses can be stored and reused for - subsequent requests, including those with RateLimit header fields. - Because the information in RateLimit header fields on a cached - response may not be current, they SHOULD be ignored on responses that - come from cache (i.e., those with a positive current_age; see - Section 4.2.3 of [HTTP-CACHING]). - -7. Security Considerations - -7.1. Throttling does not prevent clients from issuing requests - - This specification does not prevent clients from making requests. - Servers should always implement mechanisms to prevent resource - exhaustion. - -7.2. Information disclosure - - Servers should not disclose to untrusted parties operational capacity - information that can be used to saturate its infrastructural - resources. - - While this specification does not mandate whether non-successful - responses consume quota, if error responses (such as 401 - (Unauthorized) and 403 (Forbidden)) count against quota, a malicious - client could probe the endpoint to get traffic information of another - user. - - As intermediaries might retransmit requests and consume quota units - without prior knowledge of the user agent, RateLimit header fields - might reveal the existence of an intermediary to the user agent. - - Where partition keys contain identifying information, either of the - client application or the user, servers should be aware of the - potential for impersonation and apply the appropriate security - mechanisms. - -7.3. Remaining quota units are not granted requests - - RateLimit header fields convey hints from the server to the clients - in order to help them avoid being throttled out. - - Clients MUST NOT consider the quota units (Section 2.6) returned in - remaining keyword as a service level agreement. - - In case of resource saturation, the server MAY artificially lower the - returned values or not serve the request regardless of the advertised - quotas. - -7.4. Reliability of the reset keyword - - Consider that quota might not be restored after the moment referenced - by the reset keyword (Section 4.1.2), and the reset parameter value - may not be constant. - - Subsequent requests might return a higher reset parameter value to - limit concurrency or implement dynamic or adaptive throttling - policies. - -7.5. Resource exhaustion - - When returning reset values, servers must be aware that many - throttled clients may come back at the very moment specified. - - This is true for Retry-After too. - - For example, if the quota resets every day at 18:00:00 and your - server returns the reset parameter accordingly - - Date: Tue, 15 Nov 1994 18:00:00 GMT - RateLimit: daily;r=1;t=36400 - - there's a high probability that all clients will show up at 18:00:00. - - This could be mitigated by adding some jitter to the reset value. - - Resource exhaustion issues can be associated with quota policies - using a large time window, because a user agent by chance or on - purpose might consume most of its quota units in a significantly - shorter interval. - - This behavior can be even triggered by the provided RateLimit header - fields. The following example describes a service with an unconsumed - quota policy of 10000 quota units per 1000 seconds. - - RateLimit-Policy: somepolicy;l=10000;w=1000 - RateLimit: somepolicy;r=10000;t=10 - - A client implementing a simple ratio between remaining keyword and - reset keyword could infer an average throughput of 1000 quota units - per second, while the limit keyword conveys a quota-policy with an - average of 10 quota units per second. If the service cannot handle - such load, it should return either a lower remaining keyword value or - an higher reset keyword value. Moreover, complementing large time - window quota policies with a short time window one mitigates those - risks. - -7.5.1. Denial of Service - - RateLimit header fields may contain unexpected values by chance or on - purpose. For example, an excessively high remaining keyword value - may be: - - * used by a malicious intermediary to trigger a Denial of Service - attack or consume client resources boosting its requests; - - * passed by a misconfigured server; - - or a high reset keyword value could inhibit clients to contact the - server (e.g. similarly to receiving "Retry-after: 1000000"). - - To mitigate this risk, clients can set thresholds that they consider - reasonable in terms of quota units, time window, concurrent requests - or throughput, and define a consistent behavior when the RateLimit - exceed those thresholds. For example this means capping the maximum - number of request per second, or implementing retries when the reset - keyword exceeds ten minutes. - - The considerations above are not limited to RateLimit header fields, - but apply to all fields affecting how clients behave in subsequent - requests (e.g. Retry-After). - -8. Privacy Considerations - - Clients that act upon a request to rate limit are potentially re- - identifiable (see Section 5.2.1 of [PRIVACY]) because they react to - information that might only be given to them. Note that this might - apply to other fields too (e.g. Retry-After). - - Since rate limiting is usually implemented in contexts where clients - are either identified or profiled (e.g. assigning different quota - units to different users), this is rarely a concern. - - Privacy enhancing infrastructures using RateLimit header fields can - define specific techniques to mitigate the risks of re- - identification. - -9. IANA Considerations - - IANA is requested to update one registry and create one new registry. - - Please add the following entries to the "Hypertext Transfer Protocol - (HTTP) Field Name Registry" registry ([HTTP]): - - +==================+===========+=======================+ - | Field Name | Status | Specification | - +==================+===========+=======================+ - | RateLimit | permanent | Section 4 of RFC nnnn | - +------------------+-----------+-----------------------+ - | RateLimit-Policy | permanent | Section 3 of RFC nnnn | - +------------------+-----------+-----------------------+ - - Table 1 - -10. References - -10.1. Normative References - - [HTTP] Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, - Ed., "HTTP Semantics", STD 97, RFC 9110, - DOI 10.17487/RFC9110, June 2022, - . - - [IANA] Cotton, M., Leiba, B., and T. Narten, "Guidelines for - Writing an IANA Considerations Section in RFCs", BCP 26, - RFC 8126, DOI 10.17487/RFC8126, June 2017, - . - - [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate - Requirement Levels", BCP 14, RFC 2119, - DOI 10.17487/RFC2119, March 1997, - . - - [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC - 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, - May 2017, . - - [STRUCTURED-FIELDS] - Nottingham, M. and P. Kamp, "Structured Field Values for - HTTP", RFC 8941, DOI 10.17487/RFC8941, February 2021, - . - - [WEB-ORIGIN] - Barth, A., "The Web Origin Concept", RFC 6454, - DOI 10.17487/RFC6454, December 2011, - . - -10.2. Informative References - - [HPACK] Peon, R. and H. Ruellan, "HPACK: Header Compression for - HTTP/2", RFC 7541, DOI 10.17487/RFC7541, May 2015, - . - - [HTTP-CACHING] - Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, - Ed., "HTTP Caching", STD 98, RFC 9111, - DOI 10.17487/RFC9111, June 2022, - . - - [PRIVACY] Cooper, A., Tschofenig, H., Aboba, B., Peterson, J., - Morris, J., Hansen, M., and R. Smith, "Privacy - Considerations for Internet Protocols", RFC 6973, - DOI 10.17487/RFC6973, July 2013, - . - - [RFC3339] Klyne, G. and C. Newman, "Date and Time on the Internet: - Timestamps", RFC 3339, DOI 10.17487/RFC3339, July 2002, - . - - [RFC6585] Nottingham, M. and R. Fielding, "Additional HTTP Status - Codes", RFC 6585, DOI 10.17487/RFC6585, April 2012, - . - - [UNIX] The Open Group, "The Single UNIX Specification, Version 2 - - 6 Vol Set for UNIX 98", February 1997. - -Appendix A. Rate-limiting and quotas - - Servers use quota mechanisms to avoid systems overload, to ensure an - equitable distribution of computational resources or to enforce other - policies - e.g. monetization. - - A basic quota mechanism limits the number of acceptable requests in a - given time window, e.g. 10 requests per second. - - When quota is exceeded, servers usually do not serve the request - replying instead with a 4xx HTTP status code (e.g. 429 or 403) or - adopt more aggressive policies like dropping connections. - - Quotas may be enforced on different basis (e.g. per user, per IP, per - geographic area, ..) and at different levels. For example, an user - may be allowed to issue: - - * 10 requests per second; - - * limited to 60 requests per minute; - - * limited to 1000 requests per hour. - - Moreover system metrics, statistics and heuristics can be used to - implement more complex policies, where the number of acceptable - requests and the time window are computed dynamically. - - To help clients throttling their requests, servers may expose the - counters used to evaluate quota policies via HTTP header fields. - - Those response headers may be added by HTTP intermediaries such as - API gateways and reverse proxies. - - On the web we can find many different rate-limit headers, usually - containing the number of allowed requests in a given time window, and - when the window is reset. - - The common choice is to return three headers containing: - - * the maximum number of allowed requests in the time window; - - * the number of remaining requests in the current window; - - * the time remaining in the current window expressed in seconds or - as a timestamp; - -A.1. Interoperability issues - - A major interoperability issue in throttling is the lack of standard - headers, because: - - * each implementation associates different semantics to the same - header field names; - - * header field names proliferates. - - User agents interfacing with different servers may thus need to - process different headers, or the very same application interface - that sits behind different reverse proxies may reply with different - throttling headers. - -Appendix B. Examples - -B.1. Responses without defining policies - - Some servers may not expose the policy limits in the RateLimit-Policy - header field. Clients can still use the RateLimit header field to - throttle their requests. - -B.1.1. Throttling information in responses - - The client exhausted its quota for the next 50 seconds. The limit - and time-window is communicated out-of-band. - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 200 Ok - Content-Type: application/json - RateLimit: default;r=0;t=50 - - {"hello": "world"} - - Since the field values are not necessarily correlated with the - response status code, a subsequent request is not required to fail. - The example below shows that the server decided to serve the request - even if remaining keyword value is 0. Another server, or the same - server under other load conditions, could have decided to throttle - the request instead. - - Request: - - GET /items/456 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 200 Ok - Content-Type: application/json - RateLimit: default;r=0;t=48 - - {"still": "successful"} - -B.1.2. Multiple policies in response - - The server uses two different policies to limit the client's - requests: - - * 5000 daily quota units; - - * 1000 hourly quota units. - - The client consumed 4900 quota units in the first 14 hours. - - Despite the next hourly limit of 1000 quota units, the closest limit - to reach is the daily one. - - The server then exposes the RateLimit header fields to inform the - client that: - - * it has only 100 quota units left in the daily quota and the window - will reset in 10 hours; - - The server MAY choose to omit returning the hourly policy as it uses - the same quota units as the daily policy and the daily policy is the - one that is closest to being exhausted. - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 200 Ok - Content-Type: application/json - RateLimit: dayLimit;r=100;t=36000 - - {"hello": "world"} - -B.1.3. Use for limiting concurrency - - RateLimit header fields may be used to limit concurrency, advertising - limits that are lower than the usual ones in case of saturation, thus - increasing availability. - - The server adopted a basic policy of 100 quota units per minute, and - in case of resource exhaustion adapts the returned values reducing - both limit and remaining keyword values. - - After 2 seconds the client consumed 40 quota units - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 200 Ok - Content-Type: application/json - RateLimit-Policy: basic;l=100;w=60 - RateLimit: basic;r=60;t=58 - - {"elapsed": 2, "issued": 40} - - At the subsequent request - due to resource exhaustion - the server - advertises only r=20. - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 200 Ok - Content-Type: application/json - RateLimit-Policy: basic;l=100;w=60 - RateLimit: basic;r=20;t=56 - - {"elapsed": 4, "issued": 41} - -B.1.4. Use in throttled responses - - A client exhausted its quota and the server throttles it sending - Retry-After. - - In this example, the values of Retry-After and RateLimit header field - reference the same moment, but this is not a requirement. - - The 429 (Too Many Request) HTTP status code is just used as an - example. - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 429 Too Many Requests - Content-Type: application/json - Date: Mon, 05 Aug 2019 09:27:00 GMT - Retry-After: Mon, 05 Aug 2019 09:27:05 GMT - RateLimit: default;r=0;t=5 - - { - "title": "Too Many Requests", - "status": 429, - "detail": "You have exceeded your quota" - } - -B.2. Responses with defined policies - -B.2.1. Throttling window specified via parameter - - The client has 99 quota units left for the next 50 seconds. The time - window is communicated by the w parameter, so we know the throughput - is 100 quota units per minute. - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 200 Ok - Content-Type: application/json - RateLimit: fixedwindow;r=99;t=50 - RateLimit-Policy: fixedwindow;l=100;w=60 - {"hello": "world"} - -B.2.2. Dynamic limits with parameterized windows - - The policy conveyed by the RateLimit header field states that the - server accepts 100 quota units per minute. - - To avoid resource exhaustion, the server artificially lowers the - actual limits returned in the throttling headers. - - The remaining keyword then advertises only 9 quota units for the next - 50 seconds to slow down the client. - - Note that the server could have lowered even the other values in the - RateLimit header field: this specification does not mandate any - relation between the field values contained in subsequent responses. - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 200 Ok - Content-Type: application/json - RateLimit-Policy: dynamic;l=100;w=60 - RateLimit: dynamic;r=9;t=50 - - - { - "status": 200, - "detail": "Just slow down without waiting." - } - -B.2.3. Dynamic limits for pushing back and slowing down - - Continuing the previous example, let's say the client waits 10 - seconds and performs a new request which, due to resource exhaustion, - the server rejects and pushes back, advertising r=0 for the next 20 - seconds. - - The server advertises a smaller window with a lower limit to slow - down the client for the rest of its original window after the 20 - seconds elapse. - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 429 Too Many Requests - Content-Type: application/json - RateLimit-Policy: dynamic;l=15;w=20 - RateLimit: dynamic;r=0;t=20 - - { - "status": 429, - "detail": "Wait 20 seconds, then slow down!" - } - -B.3. Dynamic limits for pushing back with Retry-After and slow down - - Alternatively, given the same context where the previous example - starts, we can convey the same information to the client via Retry- - After, with the advantage that the server can now specify the - policy's nominal limit and window that will apply after the reset, - e.g. assuming the resource exhaustion is likely to be gone by then, - so the advertised policy does not need to be adjusted, yet we managed - to stop requests for a while and slow down the rest of the current - window. - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 429 Too Many Requests - Content-Type: application/json - Retry-After: 20 - RateLimit-Policy: dynamic;l=100;w=60 - RateLimit: dynamic;r=15;t=40 - - { - "status": 429, - "detail": "Wait 20 seconds, then slow down!" - } - - Note that in this last response the client is expected to honor - Retry-After and perform no requests for the specified amount of time, - whereas the previous example would not force the client to stop - requests before the reset time is elapsed, as it would still be free - to query again the server even if it is likely to have the request - rejected. - -B.3.1. Missing Remaining information - - The server does not expose remaining values (for example, because the - underlying counters are not available). Instead, it resets the limit - counter every second. - - It communicates to the client the limit of 10 quota units per second - always returning the limit and reset keywords. - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 200 Ok - Content-Type: application/json - RateLimit-Policy: quota;l=100;w=1 - RateLimit: quota;t=1 - - {"first": "request"} - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 200 Ok - Content-Type: application/json - RateLimit-Policy: quota;l=10 - RateLimit: quota;t=1 - - {"second": "request"} - -B.3.2. Use with multiple windows - - This is a standardized way of describing the policy detailed in - Appendix B.1.2: - - * 5000 daily quota units; - - * 1000 hourly quota units. - - The client consumed 4900 quota units in the first 14 hours. - - Despite the next hourly limit of 1000 quota units, the closest limit - to reach is the daily one. - - The server then exposes the RateLimit header fields to inform the - client that: - - * it has only 100 quota units left; - - * the window will reset in 10 hours; - - * the expiring-limit is 5000. - - Request: - - GET /items/123 HTTP/1.1 - Host: api.example - - Response: - - HTTP/1.1 200 OK - Content-Type: application/json - RateLimit-Policy: hour;l=1000;w=3600, day;l=5000;w=86400 - RateLimit: day;r=100;t=36000 - - {"hello": "world"} - -FAQ - - This section is to be removed before publishing as an RFC. - - 1. Why defining standard fields for throttling? - - To simplify enforcement of throttling policies and enable clients - to constraint their requests to avoid being throttled. - - 2. Can I use RateLimit header fields in throttled responses (eg with - status code 429)? - - Yes, you can. - - 3. Are those specs tied to RFC 6585? - - No. [RFC6585] defines the 429 status code and we use it just as - an example of a throttled request, that could instead use even - 403 or whatever status code. - - 4. Why is the partition key necessary? - - Without a partition key, a server can only effectively only have - one scope (aka partition), which is impractical for most - services, or it needs to communicate the scopes out-of-band. - This prevents the development of generic connector code that can - be used to prevent requests from being throttled. Many APIs rely - on API keys, user identity or client identity to allocate quota. - As soon as a single client processes requests for more than one - partition, the client needs to know the corresponding partition - key to properly track requests against allocated quota. - - 5. Why using delay-seconds instead of a UNIX Timestamp? Why not - using subsecond precision? - - Using delay-seconds aligns with Retry-After, which is returned in - similar contexts, eg on 429 responses. - - Timestamps require a clock synchronization protocol (see - Section 5.6.7 of [HTTP]). This may be problematic (e.g. clock - adjustment, clock skew, failure of hardcoded clock - synchronization servers, IoT devices, ..). Moreover timestamps - may not be monotonically increasing due to clock adjustment. See - Another NTP client failure story - (https://community.ntppool.org/t/another-ntp-client-failure- - story/1014/) - - We did not use subsecond precision because: - - * that is more subject to system clock correction like the one - implemented via the adjtimex() Linux system call; - - * response-time latency may not make it worth. A brief - discussion on the subject is on the httpwg ml - (https://lists.w3.org/Archives/Public/ietf-http- - wg/2019JulSep/0202.html) - - * almost all rate-limit headers implementations do not use it. - - 6. Shouldn't I limit concurrency instead of request rate? - - You can use this specification to limit concurrency at the HTTP - level (see {#use-for-limiting-concurrency}) and help clients to - shape their requests avoiding being throttled out. - - A problematic way to limit concurrency is connection dropping, - especially when connections are multiplexed (e.g. HTTP/2) - because this results in unserviced client requests, which is - something we want to avoid. - - A semantic way to limit concurrency is to return 503 + Retry- - After in case of resource saturation (e.g. thrashing, connection - queues too long, Service Level Objectives not meet, ..). - Saturation conditions can be either dynamic or static: all this - is out of the scope for the current document. - - 7. Do a positive value of remaining paramter imply any service - guarantee for my future requests to be served? - - No. FAQ integrated in Section 4.1.1. - - 8. Is the quota-policy definition Section 2.5 too complex? - - You can always return the simplest form - - RateLimit:default;r=50;t=60 - - The policy key clearly connects the current usage status of a policy - to the defined limits. So for the following field: - -RateLimit-Policy: sliding;l=100;w=60;burst=1000;comment="sliding window", fixed;l=5000;w=3600;burst=0;comment="fixed window" -RateLimit: sliding;r=50;t=44 - - the value "sliding" identifies the policy being reported. - - 1. Can intermediaries alter RateLimit header fields? - - Generally, they should not because it might result in unserviced - requests. There are reasonable use cases for intermediaries - mangling RateLimit header fields though, e.g. when they enforce - stricter quota-policies, or when they are an active component of - the service. In those case we will consider them as part of the - originating infrastructure. - - 2. Why the w parameter is just informative? Could it be used by a - client to determine the request rate? - - A non-informative w parameter might be fine in an environment - where clients and servers are tightly coupled. Conveying - policies with this detail on a large scale would be very complex - and implementations would be likely not interoperable. We thus - decided to leave w as an informational parameter and only rely on - the limit, remaining and reset keywords for defining the - throttling behavior. - - 3. Can I use RateLimit fields in trailers? Servers usually - establish whether the request is in-quota before creating a - response, so the RateLimit field values should be already - available in that moment. Supporting trailers has the only - advantage that allows to provide more up-to-date information to - the client in case of slow responses. However, this complicates - client implementations with respect to combining fields from - headers and accounting for intermediaries that drop trailers. - Since there are no current implementations that use trailers, we - decided to leave this as a future-work. - -RateLimit header fields currently used on the web - - This section is to be removed before publishing as an RFC. - - Commonly used header field names are: - - * X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset; - - There are variants too, where the window is specified in the header - field name, eg: - - * x-ratelimit-limit-minute, x-ratelimit-limit-hour, x-ratelimit- - limit-day - - * x-ratelimit-remaining-minute, x-ratelimit-remaining-hour, x- - ratelimit-remaining-day - - Here are some interoperability issues: - - * X-RateLimit-Remaining references different values, depending on - the implementation: - - - seconds remaining to the window expiration - - - milliseconds remaining to the window expiration - - - seconds since UTC, in UNIX Timestamp [UNIX] - - - a datetime, either IMF-fixdate [HTTP] or [RFC3339] - - * different headers, with the same semantic, are used by different - implementers: - - - X-RateLimit-Limit and X-Rate-Limit-Limit - - - X-RateLimit-Remaining and X-Rate-Limit-Remaining - - - X-RateLimit-Reset and X-Rate-Limit-Reset - - The semantic of RateLimit depends on the windowing algorithm. A - sliding window policy for example, may result in having a remaining - keyword value related to the ratio between the current and the - maximum throughput. e.g. - -RateLimit-Policy: sliding;l=12;w=1 -RateLimit: sliding;l=12;r=6;t=1 ; using 50% of throughput, that is 6 units/s - - If this is the case, the optimal solution is to achieve - -RateLimit-Policy: sliding;l=12;w=1 -RateLimit: sliding;l=12;r=1;t=1 ; using 100% of throughput, that is 12 units/s - - At this point you should stop increasing your request rate. - -Acknowledgements - - Thanks to Willi Schoenborn, Alejandro Martinez Ruiz, Alessandro - Ranellucci, Amos Jeffries, Martin Thomson, Erik Wilde and Mark - Nottingham for being the initial contributors of these - specifications. Kudos to the first community implementers: Aapo - Talvensaari, Nathan Friedly and Sanyam Dogra. - - In addition to the people above, this document owes a lot to the - extensive discussion in the HTTPAPI workgroup, including Rich Salz, - Darrel Miller and Julian Reschke. - -Changes - - This section is to be removed before publishing as an RFC. - -Since draft-ietf-httpapi-ratelimit-headers-07 - - This section is to be removed before publishing as an RFC. - - * Refactored both fields to lists of Items that identify policy and - use parameters - - * Added quota unit parameter - - * Added partition key parameter - -Since draft-ietf-httpapi-ratelimit-headers-03 - - This section is to be removed before publishing as an RFC. - - * Split policy informatiom in RateLimit-Policy #81 - -Since draft-ietf-httpapi-ratelimit-headers-02 - - This section is to be removed before publishing as an RFC. - - * Address throttling scope #83 - -Since draft-ietf-httpapi-ratelimit-headers-01 - - This section is to be removed before publishing as an RFC. - - * Update IANA considerations #60 - - * Use Structured fields #58 - - * Reorganize document #67 - -Since draft-ietf-httpapi-ratelimit-headers-00 - - This section is to be removed before publishing as an RFC. - - * Use I-D.httpbis-semantics, which includes referencing delay- - seconds instead of delta-seconds. #5 - -Authors' Addresses - - Roberto Polli - Team Digitale, Italian Government - Italy - Email: robipolli@gmail.com - - - Alejandro Martinez Ruiz - Red Hat - Email: alex@flawedcode.org - - - Darrel Miller - Microsoft - Email: darrel@tavis.ca