No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xep-0362.xml 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?xml version='1.0' encoding='UTF-8'?>
  2. <!DOCTYPE xep SYSTEM 'xep.dtd' [
  3. <!ENTITY % ents SYSTEM 'xep.ent'>
  4. %ents;
  5. ]>
  6. <?xml-stylesheet type='text/xsl' href='xep.xsl'?>
  7. <xep>
  8. <header>
  9. <title>Raft over XMPP</title>
  10. <abstract>This specification provides a means for transporting messages from the Raft consensus algorithm over XMPP.</abstract>
  11. &LEGALNOTICE;
  12. <number>0362</number>
  13. <status>Deferred</status>
  14. <type>Standards Track</type>
  15. <sig>Standards</sig>
  16. <approver>Council</approver>
  17. <dependencies>
  18. <spec>XMPP Core</spec>
  19. <spec>XEP-0001</spec>
  20. <spec>Etc.</spec>
  21. </dependencies>
  22. <supersedes/>
  23. <supersededby/>
  24. <shortname>NOT_YET_ASSIGNED</shortname>
  25. <author>
  26. <firstname>Peter</firstname>
  27. <surname>Membrey</surname>
  28. <email>peter@membrey.hk</email>
  29. <jid>peter@membrey.hk</jid>
  30. </author>
  31. <revision>
  32. <version>0.2</version>
  33. <date>2017-09-11</date>
  34. <initials>XEP Editor (jwi)</initials>
  35. <remark>Defer due to lack of activity.</remark>
  36. </revision>
  37. <revision>
  38. <version>0.1</version>
  39. <date>2015-08-11</date>
  40. <initials>XEP Editor (mam)</initials>
  41. <remark><p>Initial published version approved by the XMPP Council.</p></remark>
  42. </revision>
  43. <revision>
  44. <version>0.0.3</version>
  45. <date>2015-07-28</date>
  46. <initials>pm</initials>
  47. <remark><p>Removed references to SHOULD/MUST.</p></remark>
  48. </revision>
  49. <revision>
  50. <version>0.0.2</version>
  51. <date>2015-07-22</date>
  52. <initials>pm</initials>
  53. <remark><p>Updates based on list and council feedback.</p></remark>
  54. </revision>
  55. <revision>
  56. <version>0.0.1</version>
  57. <date>2015-07-20</date>
  58. <initials>pm</initials>
  59. <remark><p>First draft.</p></remark>
  60. </revision>
  61. </header>
  62. <section1 topic='Introduction' anchor='intro'>
  63. <p>This XEP does not attempt to implement Raft. Rather, based on the message exchanges defined in the <link url="https://ramcloud.stanford.edu/raft.pdf">Raft paper</link>, it defines a complementary set of &MESSAGE; stanza elements to allow Raft messages to be transported cleanly over XMPP. The messages for Node to Node communication are well documented in the <link url="https://ramcloud.stanford.edu/raft.pdf">Raft paper</link> and are reproduced here with minor additions to leverage the benefits of XMPP. However Client to Node communication is only hinted at and, as it does not use Raft natively it is outside the scope of this XEP.</p>
  64. <p>Raft is a consensus algorithm that is easy to understand and implement. When you want to keep a distributed system consistent, you will need some form of consensus algorithm. Raft was developed at Stanford University as an alternative to the incumbent consensus algorithm PAXOS. PAXOS is claimed to be very complex, hard to teach and even harder to implement. All of these are discussed in a paper <link url="https://ramcloud.stanford.edu/raft.pdf">here</link> and additional information (including a graphical simulation of a cluster) can be found on the project's website: <link url="https://raftconsensus.github.io/">https://raftconsensus.github.io/</link>.</p>
  65. <p>Raft defines a set of core messages needed to implement the protocol. However, it does not specify the transport layer for this protocol. Most implementations have chosen to use vanilla TCP due to its simplicity. However if you want to run a cluster over the Internet, you are likely going to want more than what vanilla TCP provides. This is where XMPP would really shine as a transport layer for Raft. XMPP offers:</p>
  66. <ol>
  67. <li> Encrypted transport (TLS) </li>
  68. <li> Authenticated Endpoints </li>
  69. <li> Ability to use JIDs to identify cluster nodes </li>
  70. <li> Re-use XMPP if the application is already XMPP enabled </li>
  71. </ol>
  72. <p>These are all things that would traditionally have to be re-engineered each time somebody wanted to use Raft across the public Internet. By supporting Raft in XMPP, developers looking to use Raft would have a transport layer that's as easy to use and understand as the Raft protocol itself. As Raft does not offer its own transport protocol and has deliberately left that to the developer, there is no conflict in standardizing an XMPP based transport layer.</p>
  73. <section2 topic='Why &MESSAGE; and not &IQ;'>
  74. <p>The Raft algorithm can be categorized as a request-response protocol. Normally this would make it a prime candidate for using &IQ; stanzas to handle the communication. However because Raft is designed to cope with message loss, it intrinsically supports automatic recovery. There is no need for the transport layer to report errors as even if the transport layer provided them (such as an &IQ; 'error' response), the Raft implementation cannot use it.</p>
  75. <p>This has a number of benefits. First, it makes Raft adaptable to lossy transport layers where packets can (and do) get lost. Raft is able to automatically recover in this scenario because the next message the Leader sends will allow a Follower to detect that it has missed a message and ask for it to be sent again. The Leader has no way to deal with an error condition caused by sending a message to a Follower.</p>
  76. <p>Second, when it comes to implementing Raft over XMPP, using &MESSAGE; instead of &IQ; greatly simplifies the implementation. As &IQ; stanzas require a reply, the implementation would need to handle detecting and reporting errors conditions back to the sender. This could mean adding arbitrary timers to try to determine if a Follower has 'timed out'. This adds complexity and uncertainty to the system, and given that Raft itself cannot make use of this information, using &IQ; does not add any value to the Raft over XMPP protocol.</p>
  77. </section2>
  78. <section2 topic='Example Usecase'>
  79. <p>Making databases or datastores available over the Internet has been the norm for many years. Databases containing PGP keys, certificates or other information can be found hosted by many different organizations. The problem with these systems is that as they become more critical to users, the impact of a server failing increases dramatically. For example, a server that provides a spam database that clients can verify email against, must be operational for those clients to be able to filter spam. Having a single server in this scenario is not acceptable; to provide redundancy there must be multiple servers.</p>
  80. <p>The problem then becomes how to keep the servers in sync. Raft partly solves this problem by providing the means to ensure the cluster maintains consensus i.e. maintains a consistent view of the data. As mentioned previously, it does not however provide a means for the nodes in the cluster to actually communicate with each other or clients.</p>
  81. <p>This is where being able to use Raft over XMPP would be highly beneficial. As it stands now, developers must implement their own transport and security, which although certainly possible, is not ideal. First, most developers are not security experts and a wealth of knowledge and experience is needed to properly design a secure system. Second, even with the required expertise, it takes a considerable amount of time and effort to actually implement and test any new implementation. Third, this extra work takes developers' focus away from the problem that they were trying to solve in the first place.</p>
  82. <p>So how could Raft over XMPP be applied in this instance? First, XMPP has an excellent history when it comes to security. Considerable time and effort was spent ensuring that XMPP was secure when XMPP Core was being standardized. By using XMPP, this hard work and battle tested approach can be leveraged by Raft. This means developers do not need to concern themselves with securing Raft messages, rather they now only need to concern themselves with using XMPP appropriately.</p>
  83. <p>Raft over XMPP further simplifies things by allowing developers to think at a higher level of abstraction. Nodes in the cluster can be communicated with simply by knowing their JID. It would not be necessary to know a node's IP address (which could change) or what TCP port the node is running on. In addition developers would not need to worry about which node connects to which, managing multiple TCP sockets and how to multiplex data across them.</p>
  84. <p>Lastly, integrating a Raft implementation with Raft over XMPP, would be relatively straight forward as Raft over XMPP defines and uses the same names as those provided by the <link url="https://ramcloud.stanford.edu/raft.pdf">Raft paper</link> with few additions. This means that it could be much easier to get a Raft implementation up and running using Raft over XMPP than it would be to do so even with pure vanilla sockets.</p>
  85. </section2>
  86. </section1>
  87. <section1 topic='Requirements' anchor='reqs'>
  88. <p>The author has designed Raft over XMPP with the following requirements in mind:</p>
  89. <ol>
  90. <li> The protocol needs to support all messages as defined in the <link url="https://ramcloud.stanford.edu/raft.pdf">Raft paper</link> </li>
  91. <li> The protocol ought to leverage the benefits of using XMPP as the transport layer </li>
  92. <li> Client to Node interaction is out of scope for this XEP</li>
  93. </ol>
  94. </section1>
  95. <section1 topic='Glossary' anchor='glossary'>
  96. <dl>
  97. <di><dt>Raft</dt><dd>A distributed consensus algorithm designed at Stanford University to be simple and easy to implement. It aims to replace PAXOS as the conensus algorithm of choice for real world use and teaching. The Raft website is <link url="https://raftconsensus.github.io/">https://raftconsensus.github.io/</link></dd></di>
  98. <di><dt>Log Replication</dt><dd>Log replication is how Raft exchanges commands with the rest of the cluster.</dd></di>
  99. <di><dt>Follower</dt><dd>The default state of a cluster member. It receives and applies updates from the Leader</dd></di>
  100. <di><dt>Candidate</dt><dd>When a Follower has not seen a heartbeat from the Leader for a period of time, it will assume the leader has failed and will look to become the Leader itself.</dd></di>
  101. <di><dt>Leader</dt><dd>The Leader of the cluster is responsible for making all changes to the log and sending them to the other members of the cluster</dd></di>
  102. <di><dt>VoteRequest</dt><dd>A VoteRequest message is sent by a Candidate in order to solicit votes to become the Leader of a cluster</dd></di>
  103. <di><dt>AppendEntries</dt><dd>An AppendEntries message is sent by a Leader to other nodes in the cluster when it has updates that it needs to replicate.</dd></di>
  104. </dl>
  105. </section1>
  106. <section1 topic='Protocol' anchor='protocol'>
  107. <p>This XEP defines a transport layer for Raft and not an actual implementation. That is, it does not seek to implement the Raft consensus algorithm within XMPP, but instead to simply define the means for Raft messages to be transported over XMPP. To facilitate this, both the message name used in the Raft spec (shown in camel case) and the corresponding element name are mentioned together where appropriate.</p>
  108. <p>Node to Node communication is the back-bone of a Raft cluster. In operation, only the Leader or a Candidate will send messages. In all other cases, nodes will only reply to messages received. The two messages are AppendEntries and RequestVote.</p>
  109. <section2 topic="RequestVote">
  110. <p>When a Follower has not received a heartbeat from the Leader for a given period of time, it will determine that the Leader has failed and will seek to replace it. To do this it needs the support of the majority of nodes in the cluster. It can solicit support from other nodes by declaring itself a Candidate and sending a 'request-vote' (RequestVote) message to all nodes in the cluster:</p>
  111. <example caption="Duncan is soliciting votes to become leader of the cluster"><![CDATA[
  112. <message from="duncan@inverness.lit/castle" to="macbeth@cawdor.lit/castle">
  113. <request-vote xmlns="urn:xmpp:raft" term="1" last-log-term="1" last-log-index="1" cluster="scotland"/>
  114. </message>
  115. ]]></example>
  116. <p>A node will respond with a 'vote' (RequestVoteResponse) message:</p>
  117. <example caption="Macbeth votes for Duncan to become the next leader"><![CDATA[
  118. <message from="macbeth@cawdor.lit/castle" to="duncan@inverness.lit/castle">
  119. <vote xmlns="urn:xmpp:raft" term="1" vote-granted="true" cluster="scotland"/>
  120. </message>
  121. ]]></example>
  122. <p> A node can either vote for a given Candidate (vote-granted="true") or against a Candidate (vote-granted="false").</p>
  123. <p>If a node does not receive a reply, no special handling is required.</p>
  124. </section2>
  125. <section2 topic="AppendEntries">
  126. <p>The 'append' (AppendEntries) message is used by the Leader to tell Followers that they should append a new entry (or entries) to their logs. It contains additional information to allow a Follower to determine which log entries have been executed and committed on the Leader and also if it has dropped any messages. These features are implemented in Raft directly.</p>
  127. <example caption="Duncan sends an append message to his followers"><![CDATA[
  128. <message from="duncan@inverness.lit/castle" to="macbeth@cawdor.lit/castle">
  129. <append xmlns="urn:xmpp:raft" term="1" prev-log-index="1" leader-commit="1" cluster="scotland">
  130. <entry xmlns="urn:xmpp:raft" encoded="false">
  131. SET X = 1
  132. </entry>
  133. <entry xmlns="urn:xmpp:raft" encoded="true">
  134. U0VUIFggPSAx
  135. </entry>
  136. </append>
  137. </message>
  138. ]]></example>
  139. <p>The AppendEntries message is described as a simple array in the <link url="https://ramcloud.stanford.edu/raft.pdf">Raft paper</link> and this has been expanded on in XMPP to take advantage of structured XML. In addition, Raft is designed to be able to replicate any form of command and this could be binary data rather than textual data. To accommodate this, an attribute has been added to the 'append-entries' element to allow a sender to flag when the receiver needs to decode the Entry before passing it to the Raft implementation. The data is encoded using base64.</p>
  140. <p>When followers receive this message, they send a single 'append-response' (AppendEntriesResponse) in reply as follows:</p>
  141. <example caption="Macbeth sends an append-response message to Duncan"><![CDATA[
  142. <message from="macbeth@cawdor.lit/castle" to="duncan@inverness.lit/castle">
  143. <append-response xmlns="urn:xmpp:raft" term="1" success="true" cluster="scotland"/>
  144. </message>
  145. ]]></example>
  146. <p>As before, if a message is missed in either direction, the transport layer does not need to take action.</p>
  147. </section2>
  148. </section1>
  149. <section1 topic='Security Considerations' anchor='security'>
  150. <section2 topic='Checking cluster membership'>
  151. <p>It is not the responsibility of the transport layer to determine whether a node is a member of a cluster or not before delivering messages to the Raft implementation. The Raft implementation should ignore messages that it receives from nodes that aren't part of the cluster.</p>
  152. </section2>
  153. </section1>
  154. <section1 topic='IANA Considerations' anchor='iana'>
  155. <p>This document requires no interaction with the Internet Assigned Numbers Authority (IANA).</p>
  156. </section1>
  157. <section1 topic='XMPP Registrar Considerations' anchor='registrar'>
  158. <section2 topic='Protocol Namespaces' anchor='registrar-ns'>
  159. <p>The &REGISTRAR; includes 'urn:xmpp:raft' in its registry of protocol namespaces.</p>
  160. </section2>
  161. </section1>
  162. <section1 topic='XML Schema' anchor='schema'>
  163. <p>REQUIRED for protocol specifications.</p>
  164. </section1>
  165. </xep>