<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?>
<!-- generated by https://github.com/cabo/kramdown-rfc version 1.6.17 (Ruby 2.6.4) -->
<?rfc tocindent="yes"?>
<?rfc strict="yes"?>
<?rfc compact="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc docmapping="yes"?>
<?rfc-ext html-pretty-print="prettyprint https://un5neftqggkzrvwh3w.julianrbryant.com/google/code-prettify/master/loader/run_prettify.js"?>
<rfc xmlns:x="https://umn7fc98gj7rc.julianrbryant.com/net/xml2rfc/ext"
      category="std"
      consensus="true"
      docName="draft-ietf-httpapi-ratelimit-headers-06"
      ipr="trust200902"
      sortRefs="true"
      symRefs="true"
      tocInclude="true">
   <x:feedback template="mailto:httpapi@ietf.org?subject={docname},%20%22{section}%22\&amp;amp;body=%3c{ref}%3e:"/>
   <front>
      <title>RateLimit Fields for HTTP</title>
      <author fullname="Roberto Polli" initials="R." surname="Polli">
         <organization>Team Digitale, Italian Government</organization>
         <address>
            <postal>
               <country>Italy</country>
            </postal>
            <email>robipolli@gmail.com</email>
         </address>
      </author>
      <author fullname="Alejandro Martinez Ruiz" initials="A." surname="Martinez">
         <organization>Red Hat</organization>
         <address>
            <email>alex@flawedcode.org</email>
         </address>
      </author>
      <date day="22" month="December" year="2022"/>
      <area>Applications and Real-Time</area>
      <workgroup>HTTPAPI</workgroup>
      <keyword>Internet-Draft</keyword>
      <abstract>
         <t>This document defines the RateLimit-Limit, RateLimit-Remaining, RateLimit-Reset and RateLimit-Policy HTTP fields for servers to advertise their current service rate limits, thereby allowing clients to avoid being throttled.</t>
      </abstract>
      <note removeInRFC="true" title="About This Document">
         <t>Status information for this document may be found at <eref target="https://un5n600td2wm6fx5hkvdpjt61eja2.julianrbryant.com/doc/draft-ietf-httpapi-ratelimit-headers/"/>.</t>
         <t>Discussion of this document takes place on the HTTPAPI Working Group mailing list (<eref target="mailto:httpapi@ietf.org"/>), which is archived at <eref target="https://un5ydnvhecfvyenpw3yza9h0br.julianrbryant.com/arch/browse/httpapi/"/>. Subscribe at <eref target="https://un5gmtkzgjpvynwjhkae4.julianrbryant.com/mailman/listinfo/httpapi/"/>. Working Group information can be found at <eref target="https://un5n600td2wm6fx5hkvdpjt61eja2.julianrbryant.com/wg/httpapi/about/"/>.</t>
         <t>Source for this draft and an issue tracker can be found at <eref target="https://github.com/ietf-wg-httpapi/ratelimit-headers"/>.</t>
      </note>
   </front>
   <middle>
      <section anchor="introduction">
         <name>Introduction</name>
         <t>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 <xref target="rate-limiting"/> for further information on the current usage of rate limiting in HTTP.</t>
         <t>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 fields to enable rate limiting:</t>
         <t>
            <list style="symbols">
               <t>RateLimit-Limit: the server's quota for requests by the client in the time window,</t>
               <t>RateLimit-Remaining: the remaining quota in the current window,</t>
               <t>RateLimit-Reset: the time remaining in the current window, specified in seconds, and</t>
               <t>RateLimit-Policy: the quota policy.</t>
            </list>
         </t>
         <t>These fields allow the establishment of complex rate limiting policies, including using multiple and variable time windows and dynamic quotas, and implementing concurrency limits.</t>
         <t>The behavior of the RateLimit-Reset field is compatible with the delay-seconds notation of Retry-After.</t>
         <section anchor="goals">
            <name>Goals</name>
            <t>The goals of this document are:</t>
            <dl>
               <dt>Interoperability:</dt>
               <dd>
                  <t>Standardization of the names and semantics of rate-limit headers to ease their enforcement and adoption;</t>
               </dd>
               <dt>Resiliency:</dt>
               <dd>
                  <t>Improve resiliency of HTTP infrastructure by providing clients with information useful to throttle their requests and prevent 4xx or 5xx responses;</t>
               </dd>
               <dt>Documentation:</dt>
               <dd>
                  <t>Simplify API documentation by eliminating the need to include detailed quota limits and related fields in API documentation.</t>
               </dd>
            </dl>
            <t>The following features are out of the scope of this document:</t>
            <dl>
               <dt>Authorization:</dt>
               <dd>
                  <t>RateLimit fields are not meant to support authorization or other kinds of access controls.</t>
               </dd>
               <dt>Throttling scope:</dt>
               <dd>
                  <t>This specification does not cover the throttling scope, that may be the given resource-target, its parent path or the whole Origin (see <xref section="7" sectionFormat="of" target="WEB-ORIGIN"/>). This can be addressed using extensibility mechanisms such as the parameter registry <xref target="iana-ratelimit-parameters"/>.</t>
               </dd>
               <dt>Response status code:</dt>
               <dd>
                  <t>RateLimit fields may be returned in both successful (see <xref section="15.3" sectionFormat="of" target="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 and the returned status code.</t>
               </dd>
               <dt>Throttling policy:</dt>
               <dd>
                  <t>This specification does not mandate a specific throttling policy. The values published in the fields, including the window size, can be statically or dynamically evaluated.</t>
               </dd>
               <dt>Service Level Agreement:</dt>
               <dd>
                  <t>Conveyed quota hints do not imply any service guarantee. Server is free to throttle respectful clients under certain circumstances.</t>
               </dd>
            </dl>
         </section>
         <section anchor="notational-conventions">
            <name>Notational Conventions</name>
            <t>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 <xref target="RFC2119"/>
               <xref target="RFC8174"/> when, and only when, they appear in all capitals, as shown here.</t>
            <t>This document uses the Augmented BNF defined in <xref target="RFC5234"/> and updated by <xref target="RFC7405"/> along with the "#rule" extension defined in <xref section="5.6.1" sectionFormat="of" target="HTTP"/>.</t>
            <t>The term Origin is to be interpreted as described in <xref target="WEB-ORIGIN" x:fmt="of" x:sec="7"/>.</t>
            <t>This document uses the terms List, Item and Integer from <xref section="3" sectionFormat="of" target="STRUCTURED-FIELDS"/> to specify syntax and parsing, along with the concept of "bare item".</t>
            <t>The fields defined in this document are collectively referred to as "RateLimit fields".</t>
         </section>
      </section>
      <section anchor="concepts">
         <name>Concepts</name>
         <section anchor="quota-policy">
            <name>Quota Policy</name>
            <t>A quota policy is described in terms of <xref target="service-limit">quota units</xref> and a <xref target="time-window">time window</xref>. It is an Item whose bare item is a <xref target="service-limit">service limit</xref>, along with associated Parameters.</t>
            <t>The following parameters are defined in this specification:</t>
            <dl>
               <dt>w:</dt>
               <dd>
                  <t>The REQUIRED "w" parameter value conveys a time window value as defined in <xref target="time-window"/>.</t>
               </dd>
            </dl>
            <t>Other parameters are allowed and can be regarded as comments. They ought to be registered within the "Hypertext Transfer Protocol (HTTP) RateLimit Parameters Registry", as described in <xref target="iana-ratelimit-parameters"/>.</t>
            <t>For example, a quota policy of 100 quota units per minute:</t>
            <figure>
               <sourcecode type="example">
   100;w=60
</sourcecode>
            </figure>
            <t>The definition of a quota policy does not imply any specific distribution of quota units within the time window. If applicable, these details can be conveyed as extension parameters.</t>
            <t>For example, two quota policies containing further details via extension parameters:</t>
            <figure>
               <sourcecode type="example">
   100;w=60;comment="fixed window"
   12;w=1;burst=1000;policy="leaky bucket"
</sourcecode>
            </figure>
            <t>To avoid clashes, implementers SHOULD prefix unregistered parameters with a vendor identifier, e.g. <spanx style="verb">acme-policy</spanx>, <spanx style="verb">acme-burst</spanx>. While it is useful to define a clear syntax and semantics even for custom parameters, it is important to note that user agents are not required to process quota policy information.</t>
         </section>
         <section anchor="time-window">
            <name>Time Window</name>
            <t>Rate limit policies limit the number of acceptable requests within a given time interval, known as a time window.</t>
            <t>The time window is a non-negative Integer value expressing that interval in seconds, similar to the "delay-seconds" rule defined in <xref section="10.2.3" sectionFormat="of" target="HTTP"/>. Subsecond precision is not supported.</t>
         </section>
         <section anchor="service-limit">
            <name>Service Limit</name>
            <t>The service limit is associated with the maximum number of requests that the server is willing to accept from one or more clients on a given basis (originating IP, authenticated user, geographical, ..) during a <xref target="time-window">time window</xref>.</t>
            <t>The service limit is a non-negative Integer expressed in quota units.</t>
            <t>The service limit SHOULD match the maximum number of acceptable requests. However, the service limit MAY differ from the total number of acceptable requests when weight mechanisms, bursts, or other server policies are implemented.</t>
            <t>If the service limit does not match the maximum number of acceptable requests the relation with that SHOULD be communicated out-of-band.</t>
            <t>Example: A server could</t>
            <t>
               <list style="symbols">
                  <t>count once requests like <spanx style="verb">/books/{id}</spanx>
                  </t>
                  <t>count twice search requests like <spanx style="verb">/books?author=WuMing</spanx>
                  </t>
               </list>
            </t>
            <t>so that we have the following counters</t>
            <figure>
               <sourcecode type="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
</sourcecode>
            </figure>
         </section>
      </section>
      <section anchor="ratelimit-field-definitions">
         <name>RateLimit Field Definitions</name>
         <t>The following RateLimit response fields are defined.</t>
         <section anchor="ratelimit-limit-field">
            <name>RateLimit-Limit</name>
            <t>The "RateLimit-Limit" response field indicates the <xref target="service-limit">service limit</xref> associated with the client in the current <xref target="time-window">time window</xref>. If the client exceeds that limit, it MAY not be served.</t>
            <t>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.</t>
            <t>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:</t>
            <t>
               <list style="symbols">
                  <t>inferred by the value of RateLimit-Reset field at the moment of the reset, or</t>
                  <t>communicated out-of-band (e.g. in the documentation).</t>
               </list>
            </t>
            <t>The RateLimit-Policy field (see <xref target="ratelimit-policy-field"/>), might contain information on the associated time window.</t>
            <figure>
               <sourcecode type="example">
   RateLimit-Limit: 100
</sourcecode>
            </figure>
            <t>This field can be sent in a trailer section.</t>
         </section>
         <section anchor="ratelimit-policy-field">
            <name>RateLimit-Policy</name>
            <t>The "RateLimit-Policy" response field indicates the quota policies currently associated with the client. Its value is informative.</t>
            <t>The field is a non-empty List of Items. Each item is a <xref target="quota-policy">quota policy</xref>.</t>
            <t>This field can convey the time window associated with the expiring-limit, as shown in this example:</t>
            <figure>
               <sourcecode type="example">
   RateLimit-Policy: 100;w=10
   RateLimit-Limit: 100
</sourcecode>
            </figure>
            <t>These examples show multiple policies being returned:</t>
            <figure>
               <sourcecode type="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
</sourcecode>
            </figure>
            <t>This field can be sent in a trailer section.</t>
         </section>
         <section anchor="ratelimit-remaining-field">
            <name>RateLimit-Remaining</name>
            <t>The "RateLimit-Remaining" response field indicates the remaining quota units associated to the expiring-limit.</t>
            <t>The field is an Item and its value is a non-negative Integer expressed in <xref target="service-limit">quota units</xref>. This specification does not define Parameters for this field. If they appear, they MUST be ignored.</t>
            <t>This field can be sent in a trailer section.</t>
            <t>Clients MUST NOT assume that a positive RateLimit-Remaining field value is a guarantee that further requests will be served.</t>
            <t>When the value of RateLimit-Remaining is low, it indicates that the server may soon throttle the client (see <xref target="providing-ratelimit-fields"/>).</t>
            <t>For example:</t>
            <figure>
               <sourcecode type="example">
   RateLimit-Remaining: 50
</sourcecode>
            </figure>
         </section>
         <section anchor="ratelimit-reset-field">
            <name>RateLimit-Reset</name>
            <t>The "RateLimit-Reset" field response field indicates the number of seconds until the quota associated to the expiring-limit resets.</t>
            <t>The field is a non-negative Integer compatible with the delay-seconds rule, because:</t>
            <t>
               <list style="symbols">
                  <t>it does not rely on clock synchronization and is resilient to clock adjustment and clock skew between client and server (see <xref section="5.6.7" sectionFormat="of" target="HTTP"/>);</t>
                  <t>it mitigates the risk related to thundering herd when too many clients are serviced with the same timestamp.</t>
               </list>
            </t>
            <t>This specification does not define Parameters for this field. If they appear, they MUST be ignored.</t>
            <t>This field can be sent in a trailer section.</t>
            <t>An example of RateLimit-Reset field use is below.</t>
            <figure>
               <sourcecode type="example">
   RateLimit-Reset: 50
</sourcecode>
            </figure>
            <t>The client MUST NOT assume that all its service limit will be reset at the moment indicated by the RateLimit-Reset field. The server MAY arbitrarily alter the RateLimit-Reset field value between subsequent requests; for example, in case of resource saturation or to implement sliding window policies.</t>
         </section>
      </section>
      <section anchor="providing-ratelimit-fields">
         <name>Server Behavior</name>
         <t>A server uses the RateLimit fields to communicate its quota policies. Sending the RateLimit-Limit and RateLimit-Reset fields is REQUIRED; sending RateLimit-Remaining field is RECOMMENDED.</t>
         <t>A server MAY return RateLimit fields independently of the response status code. This includes on throttled responses. This document does not mandate any correlation between the RateLimit field values and the returned status code.</t>
         <t>Servers should be careful when returning RateLimit fields in redirection responses (i.e., responses with 3xx status codes) because a low RateLimit-Remaining field value could prevent the client from issuing requests. For example, given the RateLimit fields below, a client could decide to wait 10 seconds before following the "Location" header field (see <xref section="10.2.2" sectionFormat="of" target="HTTP"/>), because the RateLimit-Remaining field value is 0.</t>
         <figure>
            <sourcecode type="http-message">
HTTP/1.1 301 Moved Permanently
Location: /foo/123
RateLimit-Remaining: 0
RateLimit-Limit: 10
RateLimit-Reset: 10

</sourcecode>
         </figure>
         <t>If a response contains both the Retry-After and the RateLimit-Reset fields, the RateLimit-Reset field value SHOULD reference the same point in time as the Retry-After field value.</t>
         <t>When using a policy involving more than one time window, the server MUST reply with the RateLimit fields related to the time window with the lower RateLimit-Remaining field values.</t>
         <t>A service using RateLimit 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 field values (see <xref target="sec-resource-exhaustion"/>); this is especially important when a quota policy uses a large time window.</t>
         <t>Under certain conditions, a server MAY artificially lower RateLimit field values between subsequent requests, e.g. to respond to Denial of Service attacks or in case of resource saturation.</t>
         <t>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. Nonetheless servers MAY decide to send the RateLimit fields in a trailer section.</t>
         <section anchor="performance-considerations">
            <name>Performance Considerations</name>
            <t>Servers are not required to return RateLimit fields in every response, and clients need to take this into account. For example, an implementer concerned with performance might provide RateLimit fields only when a given quota is going to expire.</t>
            <t>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 <xref target="HPACK"/>.</t>
         </section>
      </section>
      <section anchor="receiving-fields">
         <name>Client Behavior</name>
         <t>The RateLimit 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.</t>
         <t>For example, a successful response with the following fields:</t>
         <figure>
            <sourcecode type="example">
   RateLimit-Limit: 10
   RateLimit-Remaining: 1
   RateLimit-Reset: 7
</sourcecode>
         </figure>
         <t>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 <xref target="service-limit"/>.</t>
         <t>A client MUST validate the RateLimit fields before using them and check if there are significant discrepancies with the expected ones. This includes a RateLimit-Reset field moment too far in the future (e.g. similarly to receiving "Retry-after: 1000000") or a service-limit too high.</t>
         <t>A client receiving RateLimit fields MUST NOT assume that future responses will contain the same RateLimit fields, or any RateLimit fields at all.</t>
         <t>Malformed RateLimit fields MUST be ignored.</t>
         <t>A client SHOULD NOT exceed the quota units conveyed by the RateLimit-Remaining field before the time window expressed in RateLimit-Reset field.</t>
         <t>A client MAY still probe the server if the RateLimit-Reset field is considered too high.</t>
         <t>The value of RateLimit-Reset 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 field moment intended by the server.</t>
         <t>The details provided in RateLimit-Policy field are informative and MAY be ignored.</t>
         <t>If a response contains both the RateLimit-Reset and Retry-After fields, the Retry-After field MUST take precedence and the RateLimit-Reset field MAY be ignored.</t>
         <t>This specification does not mandate a specific throttling behavior and implementers can adopt their preferred policies, including:</t>
         <t>
            <list style="symbols">
               <t>slowing down or preemptively back-off their request rate when approaching quota limits;</t>
               <t>consuming all the quota according to the exposed limits and then wait.</t>
            </list>
         </t>
         <section anchor="intermediaries">
            <name>Intermediaries</name>
            <t>This section documents the considerations advised in <xref section="16.3.2" sectionFormat="of" target="HTTP"/>.</t>
            <t>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 fields' values in such a way as to communicate a more permissive quota policy; this includes removing the RateLimit fields.</t>
            <t>An intermediary MAY alter the RateLimit fields in such a way as to communicate a more restrictive quota policy when:</t>
            <t>
               <list style="symbols">
                  <t>it is aware of the quota unit semantic used by the Origin Server;</t>
                  <t>it implements this specification and enforces a quota policy which is more restrictive than the one conveyed in the fields.</t>
               </list>
            </t>
            <t>An intermediary SHOULD forward a request even when presuming that it might not be serviced; the service returning the RateLimit fields is the sole responsible of enforcing the communicated quota policy, and it is always free to service incoming requests.</t>
            <t>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.</t>
            <t>
               <xref target="privacy">Privacy considerations</xref> provide further guidance on intermediaries.</t>
         </section>
         <section anchor="caching">
            <name>Caching</name>
            <t>
               <xref target="HTTP-CACHING"/> defines how responses can be stored and reused for subsequent requests, including those with RateLimit fields. Because the information in RateLimit 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 <xref section="4.2.3" sectionFormat="of" target="HTTP-CACHING"/>).</t>
         </section>
      </section>
      <section anchor="security-considerations">
         <name>Security Considerations</name>
         <section anchor="sec-throttling-does-not-prevent">
            <name>Throttling does not prevent clients from issuing requests</name>
            <t>This specification does not prevent clients from making requests. Servers should always implement mechanisms to prevent resource exhaustion.</t>
         </section>
         <section anchor="sec-information-disclosure">
            <name>Information disclosure</name>
            <t>Servers should not disclose to untrusted parties operational capacity information that can be used to saturate its infrastructural resources.</t>
            <t>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.</t>
            <t>As intermediaries might retransmit requests and consume quota units without prior knowledge of the user agent, RateLimit fields might reveal the existence of an intermediary to the user agent.</t>
         </section>
         <section anchor="sec-remaining-not-granted">
            <name>Remaining quota units are not granted requests</name>
            <t>RateLimit fields convey hints from the server to the clients in order to help them avoid being throttled out.</t>
            <t>Clients MUST NOT consider the <xref target="service-limit">quota units</xref> returned in RateLimit-Remaining field as a service level agreement.</t>
            <t>In case of resource saturation, the server MAY artificially lower the returned values or not serve the request regardless of the advertised quotas.</t>
         </section>
         <section anchor="sec-reset-reliability">
            <name>Reliability of RateLimit-Reset</name>
            <t>Consider that service limit might not be restored after the moment referenced by RateLimit-Reset field, and the RateLimit-Reset field value may not be fixed nor constant.</t>
            <t>Subsequent requests might return a higher RateLimit-Reset field value to limit concurrency or implement dynamic or adaptive throttling policies.</t>
         </section>
         <section anchor="sec-resource-exhaustion">
            <name>Resource exhaustion</name>
            <t>When returning RateLimit-Reset field you must be aware that many throttled clients may come back at the very moment specified.</t>
            <t>This is true for Retry-After too.</t>
            <t>For example, if the quota resets every day at <spanx style="verb">18:00:00</spanx> and your server returns the RateLimit-Reset field accordingly</t>
            <figure>
               <sourcecode type="example">
   Date: Tue, 15 Nov 1994 08:00:00 GMT
   RateLimit-Reset: 36000
</sourcecode>
            </figure>
            <t>there's a high probability that all clients will show up at <spanx style="verb">18:00:00</spanx>.</t>
            <t>This could be mitigated by adding some jitter to the field-value.</t>
            <t>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.</t>
            <t>This behavior can be even triggered by the provided RateLimit fields. The following example describes a service with an unconsumed quota policy of 10000 quota units per 1000 seconds.</t>
            <figure>
               <sourcecode type="example">
RateLimit-Limit: 10000
RateLimit-Policy: 10000;w=1000
RateLimit-Remaining: 10000
RateLimit-Reset: 10
</sourcecode>
            </figure>
            <t>A client implementing a simple ratio between RateLimit-Remaining field and RateLimit-Reset field could infer an average throughput of 1000 quota units per second, while the RateLimit-Limit field 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 field value or an higher RateLimit-Reset field value. Moreover, complementing large time window quota policies with a short time window one mitigates those risks.</t>
            <section anchor="denial-of-service">
               <name>Denial of Service</name>
               <t>RateLimit fields may contain unexpected values by chance or on purpose. For example, an excessively high RateLimit-Remaining field value may be:</t>
               <t>
                  <list style="symbols">
                     <t>used by a malicious intermediary to trigger a Denial of Service attack or consume client resources boosting its requests;</t>
                     <t>passed by a misconfigured server;</t>
                  </list>
               </t>
               <t>or a high RateLimit-Reset field value could inhibit clients to contact the server.</t>
               <t>Clients MUST validate the received values to mitigate those risks.</t>
            </section>
         </section>
      </section>
      <section anchor="privacy">
         <name>Privacy Considerations</name>
         <t>Clients that act upon a request to rate limit are potentially re-identifiable (see <xref section="5.2.1" sectionFormat="of" target="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).</t>
         <t>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.</t>
         <t>Privacy enhancing infrastructures using RateLimit fields can define specific techniques to mitigate the risks of re-identification.</t>
      </section>
      <section anchor="iana-considerations">
         <name>IANA Considerations</name>
         <t>IANA is requested to update one registry and create one new registry.</t>
         <t>Please add the following entries to the "Hypertext Transfer Protocol (HTTP) Field Name Registry" registry (<xref target="HTTP"/>):</t>
         <texttable>
            <ttcol align="left">Field Name</ttcol>
            <ttcol align="left">Status</ttcol>
            <ttcol align="left">Specification</ttcol>
            <c>RateLimit-Limit</c>
            <c>permanent</c>
            <c>
               <xref target="ratelimit-limit-field"/> of RFC nnnn</c>
            <c>RateLimit-Remaining</c>
            <c>permanent</c>
            <c>
               <xref target="ratelimit-remaining-field"/> of RFC nnnn</c>
            <c>RateLimit-Reset</c>
            <c>permanent</c>
            <c>
               <xref target="ratelimit-reset-field"/> of RFC nnnn</c>
            <c>RateLimit-Policy</c>
            <c>permanent</c>
            <c>
               <xref target="ratelimit-policy-field"/> of RFC nnnn</c>
         </texttable>
         <section anchor="iana-ratelimit-parameters">
            <name>RateLimit Parameters Registration</name>
            <t>IANA is requested to create a new registry to be called "Hypertext Transfer Protocol (HTTP) RateLimit Parameters Registry", to be located at <eref target="https://un5gmtkzgjpuem6gt32g.julianrbryant.com/assignments/http-ratelimit-parameters">https://un5gmtkzgjpuem6gt32g.julianrbryant.com/assignments/http-ratelimit-parameters</eref>. Registration is done on the advice of a Designated Expert, appointed by the IESG or their delegate. All entries are Specification Required (<xref section="4.6" sectionFormat="comma" target="IANA"/>).</t>
            <t>Registration requests consist of the following information:</t>
            <t>
               <list style="symbols">
                  <t>Parameter name: The parameter name, conforming to <xref target="STRUCTURED-FIELDS"/>.</t>
                  <t>Field name: The RateLimit 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.</t>
                  <t>Description: A brief description of the parameter.</t>
                  <t>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.</t>
                  <t>Comments (optional): Any additional information that can be useful.</t>
               </list>
            </t>
            <t>The initial contents of this registry should be:</t>
            <texttable>
               <ttcol align="left">Field Name</ttcol>
               <ttcol align="left">Parameter name</ttcol>
               <ttcol align="left">Description</ttcol>
               <ttcol align="left">Specification</ttcol>
               <ttcol align="left">Comments (optional)</ttcol>
               <c>RateLimit-Policy</c>
               <c>w</c>
               <c>Time window</c>
               <c>
                  <xref target="quota-policy"/> of RFC nnnn</c>
               <c> </c>
            </texttable>
         </section>
      </section>
   </middle>
   <back>
      <references title="Normative References">
         <reference anchor="IANA">
            <front>
               <title>Guidelines for Writing an IANA Considerations Section in RFCs</title>
               <author fullname="M. Cotton" initials="M." surname="Cotton"/>
               <author fullname="B. Leiba" initials="B." surname="Leiba"/>
               <author fullname="T. Narten" initials="T." surname="Narten"/>
               <date month="June" year="2017"/>
            </front>
            <seriesInfo name="BCP" value="26"/>
            <seriesInfo name="RFC" value="8126"/>
            <seriesInfo name="DOI" value="10.17487/RFC8126"/>
         </reference>
         <reference anchor="HTTP">
            <front>
               <title>HTTP Semantics</title>
               <author fullname="R. Fielding"
                        initials="R."
                        role="editor"
                        surname="Fielding"/>
               <author fullname="M. Nottingham"
                        initials="M."
                        role="editor"
                        surname="Nottingham"/>
               <author fullname="J. Reschke"
                        initials="J."
                        role="editor"
                        surname="Reschke"/>
               <date month="June" year="2022"/>
            </front>
            <seriesInfo name="STD" value="97"/>
            <seriesInfo name="RFC" value="9110"/>
            <seriesInfo name="DOI" value="10.17487/RFC9110"/>
         </reference>
         <reference anchor="WEB-ORIGIN">
            <front>
               <title>The Web Origin Concept</title>
               <author fullname="A. Barth" initials="A." surname="Barth"/>
               <date month="December" year="2011"/>
            </front>
            <seriesInfo name="RFC" value="6454"/>
            <seriesInfo name="DOI" value="10.17487/RFC6454"/>
         </reference>
         <reference anchor="RFC2119">
            <front>
               <title>Key words for use in RFCs to Indicate Requirement Levels</title>
               <author fullname="S. Bradner" initials="S." surname="Bradner"/>
               <date month="March" year="1997"/>
            </front>
            <seriesInfo name="BCP" value="14"/>
            <seriesInfo name="RFC" value="2119"/>
            <seriesInfo name="DOI" value="10.17487/RFC2119"/>
         </reference>
         <reference anchor="RFC8174">
            <front>
               <title>Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words</title>
               <author fullname="B. Leiba" initials="B." surname="Leiba"/>
               <date month="May" year="2017"/>
            </front>
            <seriesInfo name="BCP" value="14"/>
            <seriesInfo name="RFC" value="8174"/>
            <seriesInfo name="DOI" value="10.17487/RFC8174"/>
         </reference>
         <reference anchor="RFC5234">
            <front>
               <title>Augmented BNF for Syntax Specifications: ABNF</title>
               <author fullname="D. Crocker"
                        initials="D."
                        role="editor"
                        surname="Crocker"/>
               <author fullname="P. Overell" initials="P." surname="Overell"/>
               <date month="January" year="2008"/>
            </front>
            <seriesInfo name="STD" value="68"/>
            <seriesInfo name="RFC" value="5234"/>
            <seriesInfo name="DOI" value="10.17487/RFC5234"/>
         </reference>
         <reference anchor="RFC7405">
            <front>
               <title>Case-Sensitive String Support in ABNF</title>
               <author fullname="P. Kyzivat" initials="P." surname="Kyzivat"/>
               <date month="December" year="2014"/>
            </front>
            <seriesInfo name="RFC" value="7405"/>
            <seriesInfo name="DOI" value="10.17487/RFC7405"/>
         </reference>
         <reference anchor="STRUCTURED-FIELDS">
            <front>
               <title>Structured Field Values for HTTP</title>
               <author fullname="M. Nottingham" initials="M." surname="Nottingham"/>
               <author fullname="P-H. Kamp" initials="P-H." surname="Kamp"/>
               <date month="February" year="2021"/>
            </front>
            <seriesInfo name="RFC" value="8941"/>
            <seriesInfo name="DOI" value="10.17487/RFC8941"/>
         </reference>
      </references>
      <references title="Informative References">
         <reference anchor="PRIVACY">
            <front>
               <title>Privacy Considerations for Internet Protocols</title>
               <author fullname="A. Cooper" initials="A." surname="Cooper"/>
               <author fullname="H. Tschofenig" initials="H." surname="Tschofenig"/>
               <author fullname="B. Aboba" initials="B." surname="Aboba"/>
               <author fullname="J. Peterson" initials="J." surname="Peterson"/>
               <author fullname="J. Morris" initials="J." surname="Morris"/>
               <author fullname="M. Hansen" initials="M." surname="Hansen"/>
               <author fullname="R. Smith" initials="R." surname="Smith"/>
               <date month="July" year="2013"/>
            </front>
            <seriesInfo name="RFC" value="6973"/>
            <seriesInfo name="DOI" value="10.17487/RFC6973"/>
         </reference>
         <reference anchor="UNIX">
            <front>
               <title>The Single UNIX Specification, Version 2 - 6 Vol Set for UNIX 98</title>
               <author fullname="The Open Group" initials="" surname="The Open Group"/>
               <date month="February" year="1997"/>
            </front>
         </reference>
         <reference anchor="HPACK">
            <front>
               <title>HPACK: Header Compression for HTTP/2</title>
               <author fullname="R. Peon" initials="R." surname="Peon"/>
               <author fullname="H. Ruellan" initials="H." surname="Ruellan"/>
               <date month="May" year="2015"/>
            </front>
            <seriesInfo name="RFC" value="7541"/>
            <seriesInfo name="DOI" value="10.17487/RFC7541"/>
         </reference>
         <reference anchor="HTTP-CACHING">
            <front>
               <title>HTTP Caching</title>
               <author fullname="R. Fielding"
                        initials="R."
                        role="editor"
                        surname="Fielding"/>
               <author fullname="M. Nottingham"
                        initials="M."
                        role="editor"
                        surname="Nottingham"/>
               <author fullname="J. Reschke"
                        initials="J."
                        role="editor"
                        surname="Reschke"/>
               <date month="June" year="2022"/>
            </front>
            <seriesInfo name="STD" value="98"/>
            <seriesInfo name="RFC" value="9111"/>
            <seriesInfo name="DOI" value="10.17487/RFC9111"/>
         </reference>
         <reference anchor="RFC6585">
            <front>
               <title>Additional HTTP Status Codes</title>
               <author fullname="M. Nottingham" initials="M." surname="Nottingham"/>
               <author fullname="R. Fielding" initials="R." surname="Fielding"/>
               <date month="April" year="2012"/>
            </front>
            <seriesInfo name="RFC" value="6585"/>
            <seriesInfo name="DOI" value="10.17487/RFC6585"/>
         </reference>
         <reference anchor="RFC3339">
            <front>
               <title>Date and Time on the Internet: Timestamps</title>
               <author fullname="G. Klyne" initials="G." surname="Klyne"/>
               <author fullname="C. Newman" initials="C." surname="Newman"/>
               <date month="July" year="2002"/>
            </front>
            <seriesInfo name="RFC" value="3339"/>
            <seriesInfo name="DOI" value="10.17487/RFC3339"/>
         </reference>
      </references>
      <section anchor="rate-limiting">
         <name>Rate-limiting and quotas</name>
         <t>Servers use quota mechanisms to avoid systems overload, to ensure an equitable distribution of computational resources or to enforce other policies - e.g. monetization.</t>
         <t>A basic quota mechanism limits the number of acceptable requests in a given time window, e.g. 10 requests per second.</t>
         <t>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.</t>
         <t>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:</t>
         <t>
            <list style="symbols">
               <t>10 requests per second;</t>
               <t>limited to 60 requests per minute;</t>
               <t>limited to 1000 requests per hour.</t>
            </list>
         </t>
         <t>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.</t>
         <t>To help clients throttling their requests, servers may expose the counters used to evaluate quota policies via HTTP header fields.</t>
         <t>Those response headers may be added by HTTP intermediaries such as API gateways and reverse proxies.</t>
         <t>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.</t>
         <t>The common choice is to return three headers containing:</t>
         <t>
            <list style="symbols">
               <t>the maximum number of allowed requests in the time window;</t>
               <t>the number of remaining requests in the current window;</t>
               <t>the time remaining in the current window expressed in seconds or as a timestamp;</t>
            </list>
         </t>
         <section anchor="interoperability-issues">
            <name>Interoperability issues</name>
            <t>A major interoperability issue in throttling is the lack of standard headers, because:</t>
            <t>
               <list style="symbols">
                  <t>each implementation associates different semantics to the same header field names;</t>
                  <t>header field names proliferates.</t>
               </list>
            </t>
            <t>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.</t>
         </section>
      </section>
      <section anchor="examples">
         <name>Examples</name>
         <section anchor="unparameterized-responses">
            <name>Unparameterized responses</name>
            <section anchor="throttling-information-in-responses">
               <name>Throttling information in responses</name>
               <t>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.</t>
               <t>Request:</t>
               <figure>
                  <sourcecode type="http-message">
GET /items/123 HTTP/1.1
Host: api.example

</sourcecode>
               </figure>
               <t>Response:</t>
               <figure>
                  <sourcecode type="http-message">
HTTP/1.1 200 Ok
Content-Type: application/json
RateLimit-Limit: 100
Ratelimit-Remaining: 0
Ratelimit-Reset: 50

{"hello": "world"}
</sourcecode>
               </figure>
               <t>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 field value is 0. Another server, or the same server under other load conditions, could have decided to throttle the request instead.</t>
               <t>Request:</t>
               <figure>
                  <sourcecode type="http-message">
GET /items/456 HTTP/1.1
Host: api.example

</sourcecode>
               </figure>
               <t>Response:</t>
               <figure>
                  <sourcecode type="http-message">
HTTP/1.1 200 Ok
Content-Type: application/json
RateLimit-Limit: 100
Ratelimit-Remaining: 0
Ratelimit-Reset: 48

{"still": "successful"}
</sourcecode>
               </figure>
            </section>
            <section anchor="use-with-custom-fields">
               <name>Use in conjunction with custom fields</name>
               <t>The server uses two custom fields, namely <spanx style="verb">acme-RateLimit-DayLimit</spanx> and <spanx style="verb">acme-RateLimit-HourLimit</spanx> to expose the following policy:</t>
               <t>
                  <list style="symbols">
                     <t>5000 daily quota units;</t>
                     <t>1000 hourly quota units.</t>
                  </list>
               </t>
               <t>The client consumed 4900 quota units in the first 14 hours.</t>
               <t>Despite the next hourly limit of 1000 quota units, the closest limit to reach is the daily one.</t>
               <t>The server then exposes the RateLimit fields to inform the client that:</t>
               <t>
                  <list style="symbols">
                     <t>it has only 100 quota units left;</t>
                     <t>the window will reset in 10 hours.</t>
                  </list>
               </t>
               <t>Request:</t>
               <figure>
                  <sourcecode type="http-message">
GET /items/123 HTTP/1.1
Host: api.example

</sourcecode>
               </figure>
               <t>Response:</t>
               <figure>
                  <sourcecode type="http-message">
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

{"hello": "world"}
</sourcecode>
               </figure>
            </section>
            <section anchor="use-for-limiting-concurrency">
               <name>Use for limiting concurrency</name>
               <t>Throttling fields may be used to limit concurrency, advertising limits that are lower than the usual ones in case of saturation, thus increasing availability.</t>
               <t>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 field values.</t>
               <t>After 2 seconds the client consumed 40 quota units</t>
               <t>Request:</t>
               <figure>
                  <sourcecode type="http-message">
GET /items/123 HTTP/1.1
Host: api.example

</sourcecode>
               </figure>
               <t>Response:</t>
               <figure>
                  <sourcecode type="http-message">
HTTP/1.1 200 Ok
Content-Type: application/json
RateLimit-Limit: 100
RateLimit-Remaining: 60
RateLimit-Reset: 58

{"elapsed": 2, "issued": 40}
</sourcecode>
               </figure>
               <t>At the subsequent request - due to resource exhaustion - the server advertises only <spanx style="verb">RateLimit-Remaining: 20</spanx>.</t>
               <t>Request:</t>
               <figure>
                  <sourcecode type="http-message">
GET /items/123 HTTP/1.1
Host: api.example

</sourcecode>
               </figure>
               <t>Response:</t>
               <figure>
                  <sourcecode type="http-message">
HTTP/1.1 200 Ok
Content-Type: application/json
RateLimit-Limit: 100
RateLimit-Remaining: 20
RateLimit-Reset: 56

{"elapsed": 4, "issued": 41}
</sourcecode>
               </figure>
            </section>
            <section anchor="use-in-throttled-responses">
               <name>Use in throttled responses</name>
               <t>A client exhausted its quota and the server throttles it sending Retry-After.</t>
               <t>In this example, the values of Retry-After and RateLimit-Reset field reference the same moment, but this is not a requirement.</t>
               <t>The 429 (Too Many Request) HTTP status code is just used as an example.</t>
               <t>Request:</t>
               <figure>
                  <sourcecode type="http-message">
GET /items/123 HTTP/1.1
Host: api.example

</sourcecode>
               </figure>
               <t>Response:</t>
               <figure>
                  <sourcecode type="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-Reset: 5
RateLimit-Limit: 100
Ratelimit-Remaining: 0

{
"title": "Too Many Requests",
"status": 429,
"detail": "You have exceeded your quota"
}
</sourcecode>
               </figure>
            </section>
         </section>
         <section anchor="parameterized-responses">
            <name>Parameterized responses</name>
            <section anchor="throttling-window-specified-via-parameter">
               <name>Throttling window specified via parameter</name>
               <t>The client has 99 quota units left for the next 50 seconds. The time window is communicated by the <spanx style="verb">w</spanx> parameter, so we know the throughput is 100 quota units per minute.</t>
               <t>Request:</t>
               <figure>
                  <sourcecode type="http-message">
GET /items/123 HTTP/1.1
Host: api.example

</sourcecode>
               </figure>
               <t>Response:</t>
               <figure>
                  <sourcecode type="http-message">
HTTP/1.1 200 Ok
Content-Type: application/json
RateLimit-Limit: 100
RateLimit-Policy: 100;w=60
Ratelimit-Remaining: 99
Ratelimit-Reset: 50

{"hello": "world"}
</sourcecode>
               </figure>
            </section>
            <section anchor="dynamic-limits-with-parameterized-windows">
               <name>Dynamic limits with parameterized windows</name>
               <t>The policy conveyed by the RateLimit-Limit field states that the server accepts 100 quota units per minute.</t>
               <t>To avoid resource exhaustion, the server artificially lowers the actual limits returned in the throttling headers.</t>
               <t>The RateLimit-Remaining field then advertises only 9 quota units for the next 50 seconds to slow down the client.</t>
               <t>Note that the server could have lowered even the other values in the RateLimit-Limit field: this specification does not mandate any relation between the field values contained in subsequent responses.</t>
               <t>Request:</t>
               <figure>
                  <sourcecode type="http-message">
GET /items/123 HTTP/1.1
Host: api.example

</sourcecode>
               </figure>
               <t>Response:</t>
               <figure>
                  <sourcecode type="http-message">
HTTP/1.1 200 Ok
Content-Type: application/json
RateLimit-Limit: 10
RateLimit-Policy: 100;w=60
Ratelimit-Remaining: 9
Ratelimit-Reset: 50

{
  "status": 200,
  "detail": "Just slow down without waiting."
}
</sourcecode>
               </figure>
            </section>
            <section anchor="dynamic-limits-for-pushing-back-and-slowing-down">
               <name>Dynamic limits for pushing back and slowing down</name>
               <t>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 <spanx style="verb">RateLimit-Remaining: 0</spanx> for the next 20 seconds.</t>
               <t>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.</t>
               <t>Request:</t>
               <figure>
                  <sourcecode type="http-message">
GET /items/123 HTTP/1.1
Host: api.example

</sourcecode>
               </figure>
               <t>Response:</t>
               <figure>
                  <sourcecode type="http-message">
HTTP/1.1 429 Too Many Requests
Content-Type: application/json
RateLimit-Limit: 0
RateLimit-Policy: 15;w=20
Ratelimit-Remaining: 0
Ratelimit-Reset: 20

{
  "status": 429,
  "detail": "Wait 20 seconds, then slow down!"
}
</sourcecode>
               </figure>
            </section>
         </section>
         <section anchor="dynamic-limits-for-pushing-back-with-retry-after-and-slow-down">
            <name>Dynamic limits for pushing back with Retry-After and slow down</name>
            <t>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.</t>
            <t>Request:</t>
            <figure>
               <sourcecode type="http-message">
GET /items/123 HTTP/1.1
Host: api.example

</sourcecode>
            </figure>
            <t>Response:</t>
            <figure>
               <sourcecode type="http-message">
HTTP/1.1 429 Too Many Requests
Content-Type: application/json
Retry-After: 20
RateLimit-Limit: 15
RateLimit-Policy: 100;w=60
Ratelimit-Remaining: 15
Ratelimit-Reset: 40

{
  "status": 429,
  "detail": "Wait 20 seconds, then slow down!"
}
</sourcecode>
            </figure>
            <t>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.</t>
            <section anchor="missing-remaining-information">
               <name>Missing Remaining information</name>
               <t>The server does not expose RateLimit-Remaining field values (for example, because the underlying counters are not available). Instead, it resets the limit counter every second.</t>
               <t>It communicates to the client the limit of 10 quota units per second always returning the couple RateLimit-Limit and RateLimit-Reset field.</t>
               <t>Request:</t>
               <figure>
                  <sourcecode type="http-message">
GET /items/123 HTTP/1.1
Host: api.example

</sourcecode>
               </figure>
               <t>Response:</t>
               <figure>
                  <sourcecode type="http-message">
HTTP/1.1 200 Ok
Content-Type: application/json
RateLimit-Limit: 10
Ratelimit-Reset: 1

{"first": "request"}
</sourcecode>
               </figure>
               <t>Request:</t>
               <figure>
                  <sourcecode type="http-message">
GET /items/123 HTTP/1.1
Host: api.example

</sourcecode>
               </figure>
               <t>Response:</t>
               <figure>
                  <sourcecode type="http-message">
HTTP/1.1 200 Ok
Content-Type: application/json
RateLimit-Limit: 10
Ratelimit-Reset: 1

{"second": "request"}
</sourcecode>
               </figure>
            </section>
            <section anchor="use-with-multiple-windows">
               <name>Use with multiple windows</name>
               <t>This is a standardized way of describing the policy detailed in <xref target="use-with-custom-fields"/>:</t>
               <t>
                  <list style="symbols">
                     <t>5000 daily quota units;</t>
                     <t>1000 hourly quota units.</t>
                  </list>
               </t>
               <t>The client consumed 4900 quota units in the first 14 hours.</t>
               <t>Despite the next hourly limit of 1000 quota units, the closest limit to reach is the daily one.</t>
               <t>The server then exposes the RateLimit fields to inform the client that:</t>
               <t>
                  <list style="symbols">
                     <t>it has only 100 quota units left;</t>
                     <t>the window will reset in 10 hours;</t>
                     <t>the expiring-limit is 5000.</t>
                  </list>
               </t>
               <t>Request:</t>
               <figure>
                  <sourcecode type="http-message">
GET /items/123 HTTP/1.1
Host: api.example

</sourcecode>
               </figure>
               <t>Response:</t>
               <figure>
                  <sourcecode type="http-message">
HTTP/1.1 200 OK
Content-Type: application/json
RateLimit-Limit: 5000
RateLimit-Policy: 1000;w=3600, 5000;w=86400
RateLimit-Remaining: 100
RateLimit-Reset: 36000

{"hello": "world"}
</sourcecode>
               </figure>
            </section>
         </section>
      </section>
      <section anchor="faq" numbered="false" removeInRFC="true">
         <name>FAQ</name>
         <t>
            <list style="numbers">
               <t>Why defining standard fields for throttling? <vspace blankLines="1"/> To simplify enforcement of throttling policies.</t>
               <t>Can I use RateLimit fields in throttled responses (eg with status code 429)? <vspace blankLines="1"/> Yes, you can.</t>
               <t>Are those specs tied to RFC 6585? <vspace blankLines="1"/> No. <xref target="RFC6585"/> defines the <spanx style="verb">429</spanx> status code and we use it just as an example of a throttled request, that could instead use even <spanx style="verb">403</spanx> or whatever status code. The goal of this specification is to standardize the name and semantic of three ratelimit 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.</t>
               <t>Why don't pass the throttling scope as a parameter? <vspace blankLines="1"/> 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 <xref target="goals"/>), and that we rely only on <xref target="HTTP"/>, in <xref target="goals"/> we defined "scope" in terms of URL. <vspace blankLines="1"/> Since clients are not required to process quota policies (see <xref target="receiving-fields"/>), we could add a new "RateLimit-Scope" field to this spec. See this discussion on a <eref target="https://github.com/httpwg/http-core/pull/317#issuecomment-585868767">similar thread</eref>
                  <vspace blankLines="1"/> Specific ecosystems can still bake their own prefixed parameters, such as <spanx style="verb">acme-auth-scope</spanx> or <spanx style="verb">acme-url-scope</spanx> and ensure that clients process them. This behavior cannot be relied upon when communicating between different ecosystems. <vspace blankLines="1"/> We are open to suggestions: comment on <eref target="https://github.com/ioggstream/draft-polli-ratelimit-headers/issues/70">this issue</eref>
               </t>
               <t>Why using delay-seconds instead of a UNIX Timestamp? Why not using subsecond precision? <vspace blankLines="1"/> Using delay-seconds aligns with Retry-After, which is returned in similar contexts, eg on 429 responses. <vspace blankLines="1"/> Timestamps require a clock synchronization protocol (see <xref section="5.6.7" sectionFormat="of" target="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 <eref target="https://un5kw2gk1a5eweqevv1dykgw1eja2.julianrbryant.com/t/another-ntp-client-failure-story/1014/">Another NTP client failure story</eref>
                  <vspace blankLines="1"/> We did not use subsecond precision because: <list style="symbols">
                     <t>that is more subject to system clock correction like the one implemented via the adjtimex() Linux system call;</t>
                     <t>response-time latency may not make it worth. A brief discussion on the subject is on the <eref target="https://un5xruhmgkj46tygt32g.julianrbryant.com/Archives/Public/ietf-http-wg/2019JulSep/0202.html">httpwg ml</eref>
                     </t>
                     <t>almost all rate-limit headers implementations do not use it.</t>
                  </list>
               </t>
               <t>Why not support multiple quota remaining? <vspace blankLines="1"/> 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.</t>
               <t>Shouldn't I limit concurrency instead of request rate? <vspace blankLines="1"/> 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. <vspace blankLines="1"/> 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. <vspace blankLines="1"/> 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.</t>
               <t>Do a positive value of RateLimit-Remaining field imply any service guarantee for my future requests to be served? <vspace blankLines="1"/> No. FAQ integrated in <xref target="ratelimit-remaining-field"/>.</t>
               <t>Is the quota-policy definition <xref target="quota-policy"/> too complex? <vspace blankLines="1"/> You can always return the simplest form of the 3 fields</t>
            </list>
         </t>
         <figure>
            <sourcecode type="example">
RateLimit-Limit: 100
RateLimit-Remaining: 50
RateLimit-Reset: 60
</sourcecode>
         </figure>
         <t>The key runtime value is the first element of the list: <spanx style="verb">expiring-limit</spanx>, the others quota-policy are informative. So for the following field:</t>
         <figure>
            <sourcecode type="example">
RateLimit-Limit: 100
RateLimit-Policy: 100;w=60;burst=1000;comment="sliding window", 5000;w=3600;burst=0;comment="fixed window"
</sourcecode>
         </figure>
         <t>the key value is the one referencing the lowest limit: <spanx style="verb">100</spanx>
         </t>
         <t>
            <list style="numbers">
               <t>Can we use shorter names? Why don't put everything in one field?</t>
            </list>
         </t>
         <t>The most common syntax we found on the web is <spanx style="verb">X-RateLimit-*</spanx> and when starting this I-D <eref target="https://github.com/ioggstream/draft-polli-ratelimit-headers/issues/34#issuecomment-519366481">we opted for it</eref>
         </t>
         <t>The basic form of those fields is easily parseable, even by implementers processing responses using technologies like dynamic interpreter with limited syntax.</t>
         <t>Using a single field complicates parsing and takes a significantly different approach from the existing ones: this can limit adoption.</t>
         <t>
            <list style="numbers">
               <t>Why don't mention connections? <vspace blankLines="1"/> Beware of the term "connection": ￼ ￼ - it is just <em>one</em> possible saturation cause. Once you go that path ￼ you will expose other infrastructural details (bandwidth, CPU, .. see <xref target="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 <xref target="sec-throttling-does-not-prevent"/>). ￼ ￼ RateLimit fields enable sending <em>on the same connection</em> different limit values ￼ on each response, depending on the policy scope (e.g. per-user, per-custom-key, ..) ￼</t>
               <t>Can intermediaries alter RateLimit fields? <vspace blankLines="1"/> Generally, they should not because it might result in unserviced requests. There are reasonable use cases for intermediaries mangling RateLimit 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.</t>
               <t>Why the <spanx style="verb">w</spanx> parameter is just informative? Could it be used by a client to determine the request rate? <vspace blankLines="1"/> A non-informative <spanx style="verb">w</spanx> 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 <spanx style="verb">w</spanx> as an informational parameter and only rely on RateLimit-Limit, RateLimit-Remaining field and RateLimit-Reset field for defining the throttling behavior.</t>
            </list>
         </t>
      </section>
      <section anchor="ratelimit-fields-currently-used-on-the-web"
                numbered="false"
                removeInRFC="true">
         <name>RateLimit fields currently used on the web</name>
         <t>Commonly used header field names are:</t>
         <t>
            <list style="symbols">
               <t>
                  <spanx style="verb">X-RateLimit-Limit</spanx>, <spanx style="verb">X-RateLimit-Remaining</spanx>, <spanx style="verb">X-RateLimit-Reset</spanx>;</t>
               <t>
                  <spanx style="verb">X-Rate-Limit-Limit</spanx>, <spanx style="verb">X-Rate-Limit-Remaining</spanx>, <spanx style="verb">X-Rate-Limit-Reset</spanx>.</t>
            </list>
         </t>
         <t>There are variants too, where the window is specified in the header field name, eg:</t>
         <t>
            <list style="symbols">
               <t>
                  <spanx style="verb">x-ratelimit-limit-minute</spanx>, <spanx style="verb">x-ratelimit-limit-hour</spanx>, <spanx style="verb">x-ratelimit-limit-day</spanx>
               </t>
               <t>
                  <spanx style="verb">x-ratelimit-remaining-minute</spanx>, <spanx style="verb">x-ratelimit-remaining-hour</spanx>, <spanx style="verb">x-ratelimit-remaining-day</spanx>
               </t>
            </list>
         </t>
         <t>Here are some interoperability issues:</t>
         <t>
            <list style="symbols">
               <t>
                  <spanx style="verb">X-RateLimit-Remaining</spanx> references different values, depending on the implementation: <list style="symbols">
                     <t>seconds remaining to the window expiration</t>
                     <t>milliseconds remaining to the window expiration</t>
                     <t>seconds since UTC, in UNIX Timestamp <xref target="UNIX"/>
                     </t>
                     <t>a datetime, either <spanx style="verb">IMF-fixdate</spanx>
                        <xref target="HTTP"/> or <xref target="RFC3339"/>
                     </t>
                  </list>
               </t>
               <t>different headers, with the same semantic, are used by different implementers: <list style="symbols">
                     <t>X-RateLimit-Limit and X-Rate-Limit-Limit</t>
                     <t>X-RateLimit-Remaining and X-Rate-Limit-Remaining</t>
                     <t>X-RateLimit-Reset and X-Rate-Limit-Reset</t>
                  </list>
               </t>
            </list>
         </t>
         <t>The semantic of RateLimit-Remaining depends on the windowing algorithm. A sliding window policy for example may result in having a RateLimit-Remaining field value related to the ratio between the current and the maximum throughput. e.g.</t>
         <figure>
            <sourcecode type="example">
RateLimit-Limit: 12
RateLimit-Policy: 12;w=1
RateLimit-Remaining: 6          ; using 50% of throughput, that is 6 units/s
RateLimit-Reset: 1
</sourcecode>
         </figure>
         <t>If this is the case, the optimal solution is to achieve</t>
         <figure>
            <sourcecode type="example">
RateLimit-Limit: 12
RateLimit-Policy: 12;w=1
RateLimit-Remaining: 1          ; using 100% of throughput, that is 12 units/s
RateLimit-Reset: 1
</sourcecode>
         </figure>
         <t>At this point you should stop increasing your request rate.</t>
      </section>
      <section anchor="acknowledgements" numbered="false">
         <name>Acknowledgements</name>
         <t>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.</t>
         <t>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.</t>
      </section>
      <section anchor="changes" numbered="false" removeInRFC="true">
         <name>Changes</name>
         <section anchor="since-draft-ietf-httpapi-ratelimit-headers-03"
                   numbered="false"
                   removeInRFC="true">
            <name>Since draft-ietf-httpapi-ratelimit-headers-03</name>
            <t>
               <list style="symbols">
                  <t>Split policy informatio in RateLimit-Policy #81</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-httpapi-ratelimit-headers-02"
                   numbered="false"
                   removeInRFC="true">
            <name>Since draft-ietf-httpapi-ratelimit-headers-02</name>
            <t>
               <list style="symbols">
                  <t>Address throttling scope #83</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-httpapi-ratelimit-headers-01"
                   numbered="false"
                   removeInRFC="true">
            <name>Since draft-ietf-httpapi-ratelimit-headers-01</name>
            <t>
               <list style="symbols">
                  <t>Update IANA considerations #60</t>
                  <t>Use Structured fields #58</t>
                  <t>Reorganize document #67</t>
               </list>
            </t>
         </section>
         <section anchor="since-draft-ietf-httpapi-ratelimit-headers-00"
                   numbered="false"
                   removeInRFC="true">
            <name>Since draft-ietf-httpapi-ratelimit-headers-00</name>
            <t>
               <list style="symbols">
                  <t>Use I-D.httpbis-semantics, which includes referencing delay-seconds instead of delta-seconds. #5</t>
               </list>
            </t>
         </section>
      </section>
   </back>
</rfc>
