<?xml version="1.0" encoding="US-ASCII"?>
  <?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?>


<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
]>

<?rfc toc="yes"?>
<?rfc tocompact="yes"?>
<?rfc tocdepth="3"?>
<?rfc tocindent="yes"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc strict="no"?>
<?rfc compact="no"?>
<?rfc subcompact="no"?>

<rfc number="8516" submissionType="IETF" consensus="yes" ipr="trust200902" category="std">

  <front>
    <title abbrev="&#34;Too Many Requests&#34; Response Code for CoAP">"Too Many Requests" Response Code for the&nbsp;Constrained&nbsp;Application&nbsp;Protocol</title>

    <author initials="A." surname="Keranen" fullname="Ari Keranen">
      <organization>Ericsson</organization>
      <address>
       <postal>
         <street>Hirsalantie 11</street>
         <city>02420 Jorvas</city>
         <region></region>
         <code></code>
         <country>Finland</country>
       </postal>

        <email>ari.keranen@ericsson.com</email>
      </address>
    </author>

    <date month="January" year="2019"/>
    

<!--
 [rfced] Please insert any keywords (beyond those that appear in 
the title) for use on https://www.rfc-editor.org/search.
-->
    <keyword>example</keyword>

    <abstract>
<t>A Constrained Application Protocol (CoAP) server can experience
temporary overload because one or more clients are sending requests to
the server at a higher rate than the server is capable or willing to
handle. This document defines a new CoAP response code for a server
to indicate that a client should reduce the rate of requests.</t>
    </abstract>

  </front>

  <middle>


<section anchor="introduction" title="Introduction">

<t>The Constrained Application Protocol (CoAP) <xref target="RFC7252"/> response codes
are used by a CoAP server to indicate the result of an attempt to
understand and satisfy a request sent by a client.</t>

<t>CoAP response codes are similar to the HTTP <xref target="RFC7230"/> status codes,
and many codes are shared with similar semantics by both CoAP and
HTTP. HTTP has the code "429" registered for "Too Many Requests"
<xref target="RFC6585"/>.  This document registers a CoAP response code "4.29" for
similar purposes and uses the Max-Age option (see Section 5.10.5 of
<xref target="RFC7252"/>) to indicate a back-off period after which a client can
try the request again.</t>

<t>While a server may not be able to respond to one kind of request, it
may be able to respond to a request of a different kind, even from the
same client. Therefore, the back-off period applies only to similar
requests. For the purpose of this response code, a request is similar
if it has the same method and Request-URI. Also, if a client is sending
a sequence of requests that are part of the same series (e.g., a set
of measurements to be processed by the server), they can be considered
similar even if request URIs are different. Because request
similarity is context-dependent, it is up to the application logic to
decide how the similarity of the requests should be evaluated.</t>

<t>The 4.29 code is similar to the 5.03 "Service Unavailable" <xref target="RFC7252"/>
code in that the 5.03 code can also be used by a server to
signal an overload situation. The 5.03 code also uses the Max-Age
option to indicate the time after which a client can retry. However,
the 4.29 code indicates that the too-frequent requests from the
requesting client are the reason for the overload.</t>

</section>
<section anchor="terminology" title="Terminology">

        <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&nbsp;14 <xref target="RFC2119"/> <xref target="RFC8174"/> 
    when, and only when, they appear in all capitals, as shown here.
        </t>


<t>Readers should also be familiar with the terms and concepts discussed
in <xref target="RFC7252"/>.</t>

</section>
<section anchor="coap-server-behavior" title="CoAP Server Behavior">

<t>If a CoAP server is unable to serve a client that is sending
CoAP request messages more often than the server is capable or willing
to handle, the server SHOULD respond to the request(s) with the
response code 4.29, "Too Many Requests". The Max-Age option is used
to indicate the number of seconds after which the server assumes it is
OK for the client to retry the request.</t>

<t>An action result payload (see Section 5.5.1 of <xref target="RFC7252"/>) can be
sent by the server to give more guidance to the client, e.g., details of the overload situation.</t>

<t>The 4.29 response code is only returned to the client(s) sending
requests too frequently; if other clients are sending requests that
cannot be served due to server overload, the 5.03 response code is
more appropriate.</t>

<t>If a client repeats a request that was answered with 4.29 before Max-
Age time has passed, it is possible that the client sent multiple
requests before receiving the first answer or that the client did not
recognize the response code. To slow down clients that do not
recognize the 4.29 code, the server MAY respond with a more generic
error code (e.g., 5.03). The server SHOULD rate-limit 4.29 replies
taking into account its usual load-shedding policies. However, any
such method that adds per-client state to the server may be
counterproductive to reducing the load.</t>

</section>
<section anchor="coap-client-behavior" title="CoAP Client Behavior">

<t>If a client receives the 4.29 response code from a CoAP server to a
request, it SHOULD NOT send a similar request to the server before the
time indicated in the Max-Age option has passed. If the 4.29 response
does not contain a Max-Age option, the default value (60 seconds, as
defined in Section 5.10.5 of <xref target="RFC7252"/>) is assumed.</t>

<t>Note that a client may receive a 4.29 response code on a first
request to a server. This can happen, for example, if there is a proxy
on the path and the server replies based on the load from multiple
clients aggregated by the proxy, or if a client has restarted recently
and does not remember its recent requests.</t>

<t>A client should not rely on a server being able to send the 4.29
response code in an overload situation because an overloaded server
may not be able to reply at all to some requests.</t>

</section>
<section anchor="SecurityConsiderations" title="Security Considerations">

<t>Security considerations of <xref target="RFC7252"/> apply to this response
code also.</t>

<t>Replying to CoAP requests with a response code consumes resources from
a server. For a server under attack, it may be more appropriate to
simply drop requests without responding at all. However, dropping
requests is also likely to cause well-behaving clients to simply
retry the requests.</t>

<t>As with any other CoAP reply, a client should trust this response
code only to the extent that it trusts the underlying security mechanisms
(e.g., DTLS <xref target="RFC6347"/>) for authentication and freshness. If a CoAP
reply with the "Too Many Requests" response code is not authenticated
and integrity protected, an attacker can attempt to spoof a reply and
make the client wait for an extended period of time before trying
again.</t>

<t>If the response code is sent without encryption, it may leak
information about the server overload situation and client traffic
patterns.</t>

</section>
<section anchor="iana" title="IANA Considerations">

<t>IANA has registered the following response code in the "CoAP Response
Codes" subregistry within the "Constrained RESTful Environments (CoRE)
Parameters" registry:</t>  

<t><list style="symbols">
  <t>Response Code: 4.29</t>
  <t>Description: Too Many Requests</t>
  <t>Reference: RFC 8516</t>
</list></t>

<t>IANA has added this document as an additional reference for
the Max-Age option in the "CoAP Option Numbers" subregistry.</t>

</section>

  </middle>

  <back>

    <references title='Normative References'>

<?rfc include="reference.RFC.2119" ?>
<?rfc include="reference.RFC.7252" ?>
<?rfc include="reference.RFC.8174" ?>

    </references>


    <references title='Informative References'>



<!-- draft-ietf-core-coap-pubsub-06: I-D Exists -->
<reference anchor='CoAP-BROKER'>
<front>
<title>Publish-Subscribe Broker for the Constrained Application Protocol (CoAP)</title>

<author initials='M' surname='Koster' fullname='Michael Koster'>
    <organization>SmartThings</organization>
</author>
<author initials='A' surname='Keranen' fullname='Ari Keranen'>
    <organization>Ericsson</organization>
</author>
<author initials='J' surname='Jimenez' fullname='Jaime Jimenez'>
    <organization>Ericsson</organization>
</author>
<date month='January' year='2019' />
</front>
<seriesInfo name='Work in Progress,' value='draft-ietf-core-coap-pubsub-06' />
</reference>

<?rfc include="reference.RFC.6585" ?>
<?rfc include="reference.RFC.7230" ?>
<?rfc include="reference.RFC.6347" ?>

    </references>

<section anchor="acks" title="Acknowledgements" numbered="no">

<t>This response code definition was originally part of the "Publish-
Subscribe Broker for CoAP" document <xref target="CoAP-BROKER"/>.
The author would like to thank Abhijan Bhattacharyya, Carsten Bormann,
Daniel Migault, Gyorgy Rethy, Jana Iyengar, Jim Schaad, Klaus Hartke,
Mohit Sethi, and Sandor Katona for their contributions and reviews.</t>

</section>

  </back>

</rfc>

