<?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.7.20 (Ruby 3.3.5) -->


<!DOCTYPE rfc  [
  <!ENTITY nbsp    "&#160;">
  <!ENTITY zwsp   "&#8203;">
  <!ENTITY nbhy   "&#8209;">
  <!ENTITY wj     "&#8288;">

]>


<rfc ipr="trust200902" docName="draft-kerr-everybodys-shuffling-00" category="info" submissionType="independent">
  <front>
    <title>DNS Servers MUST Shuffle Answers</title>

    <author initials="" surname="Shane Kerr" fullname="Shane Kerr">
      <organization>IBM</organization>
      <address>
        <postal>
          <street>Johan Huizingalaan 765</street>
          <city>Amsterdam</city>
          <code>1066 VH</code>
          <country>Netherlands</country>
        </postal>
        <email>shane.kerr@ibm.com</email>
      </address>
    </author>

    <date year="2024" month="November" day="04"/>

    
    
    

    <abstract>


<?line 27?>

<t>DNS Resource Records (DNS RR) are often used in the order that they
are returned. This means that if there are more than one RR in a RR
set, then they should be returned in a random order, to reduce bias in
how the answers are used.</t>



    </abstract>



  </front>

  <middle>


<?line 34?>

<section anchor="introduction"><name>Introduction</name>

<t>Answers returned by DNS servers in a consistent order cause
applications to use answers that appear first more often. To avoid
this, DNS RRset should be randomized.</t>

<section anchor="requirements-notation"><name>Requirements Notation</name>

<t>The key words "<bcp14>MUST</bcp14>", "<bcp14>MUST NOT</bcp14>", "<bcp14>REQUIRED</bcp14>", "<bcp14>SHALL</bcp14>", "<bcp14>SHALL
NOT</bcp14>", "<bcp14>SHOULD</bcp14>", "<bcp14>SHOULD NOT</bcp14>", "<bcp14>RECOMMENDED</bcp14>", "<bcp14>NOT RECOMMENDED</bcp14>",
"<bcp14>MAY</bcp14>", and "<bcp14>OPTIONAL</bcp14>" 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>

<?line -18?>

</section>
</section>
<section anchor="recommendations"><name>Recommendations</name>

<section anchor="authoritative-servers"><name>Authoritative Servers</name>

<t>DNS Authoritative servers <bcp14>SHOULD</bcp14> return RR within an RRset in random
order. They <bcp14>MAY</bcp14> use a fixed order for records returned for
delegations, such as DS records, NS records, and associated glue
records returned for delegations.</t>

</section>
<section anchor="recursive-resolvers"><name>Recursive Resolvers</name>

<t>DNS Recursive Resolvers <bcp14>MUST</bcp14> return RR within an RRset in random
order.</t>

</section>
<section anchor="stub-resolvers"><name>Stub Resolvers</name>

<t>DNS Stub Resolvers <bcp14>SHOULD</bcp14> return RR within an RRset in random order.</t>

</section>
<section anchor="applications"><name>Applications</name>

<t>Applications <bcp14>SHOULD</bcp14> use RR within an RRset in random order.</t>

</section>
</section>
<section anchor="discussion"><name>Discussion</name>

<t>RRsets are sets in the mathematical sense, meaning that they are
unordered, and that a given value can only appear in the set once.
However, when an RRset is represented in presentation format (how it
appears in zone files) or in message format (also known as "wire
format") then the RR have an order.</t>

<t>For example, a DNS answer may have:</t>

<figure><artwork><![CDATA[
foo.example.    60  IN  AAAA 2001:db8::aaaa
foo.example.    60  IN  AAAA 2001:db8::bbbb
]]></artwork></figure>

<t>This is exactly the same RRset as:</t>

<figure><artwork><![CDATA[
foo.example.    60  IN  AAAA 2001:db8::bbbb
foo.example.    60  IN  AAAA 2001:db8::aaaa
]]></artwork></figure>

<t>However, an application may treat the second differently than the
first, usually by sending traffic to <spanx style="verb">2001:db8::bbbb</spanx> instead of
<spanx style="verb">2001:db8::aaaa</spanx>.</t>

<t>A common pattern for services is to publish multiple addresses in the
DNS in order to provide a sort of simple load-balancing for services.
However, this only works if the addresses are all used at similar
rates.</t>

<section anchor="caching"><name>Caching</name>

<t>The most important place to randomize results is in components that
cache RRset. This is because these RRset are used many times, so
if they are not randomized then any bias will be amplified. Resolvers
cache RRset, so it is very important that they randomize order in
replies.</t>

<t>RRset may also be cached in other places, such as in stub resolvers.
These stub resolvers can reside in several places, including the
operating system, or within software libraries. If these cache RRset,
then they should also randomize.</t>

<t>Applications themselves may also "cache" RR. This may be actual
caching of RRsets using TTL from the DNS protocol, or it may as simple
as the application doing a DNS lookup once and then using the result
until it exits. Whether or not an application stores results is less
important than how the application <em>uses</em> the results. A sophisticated
application may use several of the IP addresses for a given name
concurrently, for example using Happy Eyeballs <xref target="RFC8305"/>. However a
naive application may simply pick the first IP address that it gets
back from the DNS; such applications will benefit from using a
resolver that randomizes answers.</t>

</section>
<section anchor="response-chains"><name>Response Chains</name>

<t>DNS responses mostly originate at authoritative servers, and then
proceed to recursive resolvers, and then make their way to
applications.</t>

<t>If we have applications that use results in the order returned, then
resolvers can help by randomizing their results. Since they return
answers from cache, resolvers are probably the most critical.</t>

<t>However, not all resolvers randomize the order of results, so it is
helpful for authoritative servers to randomize the order as well.</t>

</section>
<section anchor="possible-issues"><name>Possible Issues</name>

<section anchor="shuffling-versus-rotating"><name>Shuffling versus Rotating</name>

<t>One approach to changing the order may be rotating through the
answers. So, with these answers:</t>

<figure><artwork><![CDATA[
bar.example.    60  CNAME a0.example.
bar.example.    60  CNAME b1.example.
bar.example.    60  CNAME c2.example.
]]></artwork></figure>

<t>One approach could be returning <spanx style="verb">a0/b1/c2</spanx>, then <spanx style="verb">b1/c2/a0</spanx>, then
<spanx style="verb">c2/a0/b1</spanx>. The problem with this is that if one of the values does
not work, a resolver going in order will just go to the next one, so
load will shift to the next one in order rather than splitting across
the working servers.</t>

<t>Any software returning in a random order <bcp14>SHOULD</bcp14> fully shuffle the
results rather than just rotating through them.</t>

</section>
</section>
<section anchor="answers-from-authority-servers-versus-answers-from-cache"><name>Answers from Authority Servers versus Answers from Cache</name>

<t>One approach is to shuffle answers return by a recursive resolver when
taken from cache. This is mostly reasonable, since we expect that the
majority of answers are read from cache. However, for RRsets with low
TTL or low query rates they will be returning answers that cannot be
read from the cache. This may result in a significant portion of
answers that are returned in the same order.</t>

</section>
<section anchor="motivations-for-ordered-results"><name>Motivations for Ordered Results</name>

<t>The main motivation for returning ordered results is probably to save
CPU time on the server. A server may pre-build or remember the answer
and have most of it ready for replies, whereas shuffling answers means
having to build the response for every query.</t>

<t>In some cases, a server may deliberately wish to bias traffic. This is
possible when supported, for example by using the "weight" field of
the SRV record type <xref target="RFC2782"/>.</t>

<t>However, if using a record type that does not have something like
"weight", there is no guarantee that traffic will prefer the first
answers returned. In other words, sending results in a specific order
cannot help, but it can do harm.</t>

</section>
</section>
<section anchor="security-considerations"><name>Security Considerations</name>

<t>The algorithm chosen to randomize the order of results does not have
to be cryptographically-secure.</t>

</section>
<section anchor="iana-considerations"><name>IANA Considerations</name>

<t>None.</t>

</section>


  </middle>

  <back>


<references title='References' anchor="sec-combined-references">

    <references title='Normative References' anchor="sec-normative-references">



<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"/>
    <abstract>
      <t>In many standards track documents several words are used to signify the requirements in the specification. These words are often capitalized. This document defines these words as they should be interpreted in IETF documents. This document specifies an Internet Best Current Practices for the Internet Community, and requests discussion and suggestions for improvements.</t>
    </abstract>
  </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"/>
    <abstract>
      <t>RFC 2119 specifies common key words that may be used in protocol specifications. This document aims to reduce the ambiguity by clarifying that only UPPERCASE usage of the key words have the defined special meanings.</t>
    </abstract>
  </front>
  <seriesInfo name="BCP" value="14"/>
  <seriesInfo name="RFC" value="8174"/>
  <seriesInfo name="DOI" value="10.17487/RFC8174"/>
</reference>



    </references>

    <references title='Informative References' anchor="sec-informative-references">



<reference anchor="RFC2782">
  <front>
    <title>A DNS RR for specifying the location of services (DNS SRV)</title>
    <author fullname="A. Gulbrandsen" initials="A." surname="Gulbrandsen"/>
    <author fullname="P. Vixie" initials="P." surname="Vixie"/>
    <author fullname="L. Esibov" initials="L." surname="Esibov"/>
    <date month="February" year="2000"/>
    <abstract>
      <t>This document describes a DNS RR which specifies the location of the server(s) for a specific protocol and domain. [STANDARDS-TRACK]</t>
    </abstract>
  </front>
  <seriesInfo name="RFC" value="2782"/>
  <seriesInfo name="DOI" value="10.17487/RFC2782"/>
</reference>
<reference anchor="RFC8305">
  <front>
    <title>Happy Eyeballs Version 2: Better Connectivity Using Concurrency</title>
    <author fullname="D. Schinazi" initials="D." surname="Schinazi"/>
    <author fullname="T. Pauly" initials="T." surname="Pauly"/>
    <date month="December" year="2017"/>
    <abstract>
      <t>Many communication protocols operating over the modern Internet use hostnames. These often resolve to multiple IP addresses, each of which may have different performance and connectivity characteristics. Since specific addresses or address families (IPv4 or IPv6) may be blocked, broken, or sub-optimal on a network, clients that attempt multiple connections in parallel have a chance of establishing a connection more quickly. This document specifies requirements for algorithms that reduce this user-visible delay and provides an example algorithm, referred to as "Happy Eyeballs". This document obsoletes the original algorithm description in RFC 6555.</t>
    </abstract>
  </front>
  <seriesInfo name="RFC" value="8305"/>
  <seriesInfo name="DOI" value="10.17487/RFC8305"/>
</reference>



    </references>

</references>



  </back>

<!-- ##markdown-source:
H4sIAAAAAAAAA5VY73LcthH/jqfYyl+Szt1ZchPHuWaSXmVnrNaS3JOcTqbT
iZbk8ogIBBgA1PniUZ6lz9In6+wCPPJkTcf5dCQOXOzf3/4W8/lcla7SdrOE
PtbzF0pFHQ0t4eXFFVyRvyMf4Pzd1TVcNX1dG4KVDVvyQVWutNjSEiqPdZzf
kvdzuiO/K1y1C/Mg27XdzI+P1ZMSI22c3y0hxEqNb9rWTqkQ0VY/oXGWlhB9
TypET9jy/xV1ZCuyUenOy78hPjs+/vr4mVLYx8b5pQLQNizhqkFL8HfyXgEk
3Q6WnN8s4eyv5wqA5VNcwt9cgxZe9/pXbTdoEC189fxLBVDquFvCqg2RfIUt
r7iKlnBy/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