<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Apache Kvrocks on Medium]]></title>
        <description><![CDATA[Stories by Apache Kvrocks on Medium]]></description>
        <link>https://medium.com/@kvrocks?source=rss-5c76b7a47c86------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*DHYYmMUsCloZUnIQiCebfw.jpeg</url>
            <title>Stories by Apache Kvrocks on Medium</title>
            <link>https://medium.com/@kvrocks?source=rss-5c76b7a47c86------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 18 Apr 2026 18:23:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kvrocks/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Apache Kvrocks Cluster Introduction]]></title>
            <link>https://kvrocks.medium.com/kvrocks-cluster-introduction-d07e416df539?source=rss-5c76b7a47c86------2</link>
            <guid isPermaLink="false">https://medium.com/p/d07e416df539</guid>
            <dc:creator><![CDATA[Apache Kvrocks]]></dc:creator>
            <pubDate>Sun, 13 Feb 2022 14:24:54 GMT</pubDate>
            <atom:updated>2023-04-13T10:14:21.316Z</atom:updated>
            <content:encoded><![CDATA[<p>Before releasing the cluster mode of Kvrocks, we usually used the pre-sharding way to scale out the capacity like sharding with Twemproxy, and used Redis Sentinel to guarantee the availability. Although it works well in most scenes since the capacity of Kvrocks was far larger than Redis, it’s still trivial to scale-out in-flight, so we decided to implement the cluster mode to make it easier.</p><p>There’re two main types of Redis cluster solutions in the industry:</p><ul><li>Redis cluster decentralized solution</li><li>Codis centralized solution</li></ul><p>For Redis cluster, the biggest advantage was NOT needing to depend on other components, but the shortcoming was also obvious that it’s hard to write the right implementation and not easy to maintain the cluster topo. Another big issue was Gossip protocol would limit the cluster size. For Codis solution, we need to import the proxy and centralized storage to keep the metadata, the proxy also added extra network communication cost and delay.</p><p>In Kvrocks cluster design, we want to integrate advantages between those solutions, can access Kvrocks without the proxy, and scale-out easily.</p><h3>Internal Design</h3><p>Each Kvrocks node can act as Redis node which can offer the cluster topo directly, and the Redis cluster client can also work on Kvrocks cluster without any modifications. The topo was managed by the other control panel component which can avoid the complexity of the Gossip protocol(Redis community takes many years to complete the Gossip on cluster solution).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/0*1d4jfW76pP_K3jAf.png" /></figure><h3>Topo Management</h3><p>Kvrocks uses the <a href="https://github.com/KvrocksLabs/kvrocks/pull/302">Clusterx SetNodes</a> command to set up the cluster topo, be careful that we should apply the entire topo information to all nodes since nodes didn’t communicate with each other. The command is like below:</p><p>CLUSTERX SETNODES $ALL_NODES_INFO $VERSION FORCE</p><ul><li>$ALL_NODES_INFO: was the cluster topo information, format: : $node_id $ip $port $role $master_node_id $slot_range</li><li>$node_id: 40 chars string, it represents as the unique id in the cluster</li><li>$ip and $port : the node IP address and the listening port</li><li>$role: node&#39;s role, should be one of master or slave</li><li>$master_node_id: set it to the master node id when the current node&#39;s role was a slave and set - if it&#39;s master</li><li>slot_range: slots were served by current node, the format can be the range or single value, like 0-100 200 205 which means slots 0 to 100, 200 and 205 were served by this node</li><li>$VERSION: the topo information version is used to control update the order, the topo information can be updated iff the version is newer than the current version</li><li>FORCE: force update the topo information without verifying the version, we can use this flag when the topo information was totally broken</li></ul><p>Example:</p><pre>CLUSTERX SETNODES<br>  &quot;67ed2db8d677e59ec4a4cefb06858cf2a1a89fa1 127.0.0.1 30002 master - 5461-10922 16380 16383<br>    07c37dfeb235213a872192d90877d0cd55635b91 127.0.0.1 30004 slave 67ed2db8d677e59ec4a4cefb06858cf2a1a89fa1&quot;<br>  1</pre><p>Although Kvrocks can recognize the node id by comparing the ip:port pair then find out the serving slots, but users may set the IP address to 0.0.0.0 so that we can&#39;t match the right topo information. So Kvrocks gives the extra command <a href="https://github.com/KvrocksLabs/kvrocks/pull/302">CLUSTERX SETNODEID</a> to set the id. The format is like:</p><pre>CLUSTERX SETNODEID $NODE_ID</pre><p>$NODE_ID: should be 40 chars unique id in cluster</p><h3>Node Management</h3><p>Kvrocks cluster can be set up as simple as using those cluster commands, we even can write a script to watch and apply cluster changes. Those commands can be integrated into those companies which have their own cluster solution. Kvrocks also offers the CLUSTERX VERSION command to inspect current cluster topo information, the controller can force to update topo information when the version was out of date or wrong.</p><p>For a complete cluster solution, we need to depend on another controller to manage the topo information, failure detection, and failover. Kvrocks team was also developing the official controller to make the cluster manage and operate easier. But at the time the manual resource was a bottleneck, welcome anyone who was interested in this project to build together.</p><h3>Client Access</h3><p>Users can use Redis Cluster SDK to access the Kvrocks cluster since it’s compatible with the Redis cluster solution(Kvrocks supported CLUSTER NODES and CLUSETER SLOTS command to respond to the cluster topo). Kvrocks also responds MOVED $slot_id $ip:$port to redirect the target node when the slot was NOT served by the current node. You can also use the Redis Cluster Proxy redis-cluster-proxy to hide the cluster topo.</p><h3>Deploy And Operate</h3><p>Users need to self-manage the cluster topo information since Kvrocks controller was still under development. The deployment steps were below:</p><ol><li>Deploy Kvrocks nodes</li><li>Design the kvrocks topo which was mentioned at #Topo Management</li><li>Set node unique id for each node by using CLUSTER SETNODEID command</li><li>Apply the topo information to all nodes by using CLUSTER NODES command</li></ol><p>Kvrocks would auto-setup the master-slave replication after receiving the setup topo command, and repeats steps 2–4 when we want to switch the node role or number.</p><p>Currently, Kvrocks topo modification was based on full state, that’s we need to sync the full topo information to each node, which may cause high network and CPU cost but it can guarantee the correctness of the cluster. Also, the version-based modification can help us to achieve the increment modification if we want to do that, we would offer a way to add, update and delete noes to make operation easier.</p><p>Cluster Command And Safty</p><p>To guarantee the correctness of client SDK, we rename the CLUSTER command to CLUSTERX to prevent the topo can being modified casually, but we can still use the CLUSTER command to fetch the cluster topo information.</p><h3>Cluster Scaling</h3><p>Kvrocks data migration was based on the slot instead of the key-based like Reids, we can migrate one slot to another node at once. Kvrocks storage was based on disk instead of memory, so the key migration may be time cost. Now, the controller o DBA can use the CLUSTER MIGRATE command to migrate the slot. For more information can see PR <a href="https://github.com/KvrocksLabs/kvrocks/pull/430">#430</a>.</p><p>Migrate Command</p><p>CLUSTERX SETSLOT $slot NODE $node_id $new_version</p><ul><li>$slot: assign which slot to be migrated</li><li>NODE:same as the Redis cluster setslot</li><li>$dest_nodeid: which node of the slot is to be migrated</li><li>$new_version: the version of the topo information, noted that the version MUST be newer than the old version, or the node would refuse to apply the modification.</li></ul><p>We need to use CLUSTERX MIGRATE command to migrate the slot then use CLUSTER SETSLOT to modify the topo information.</p><h3>Summary</h3><p>Kvrocks cluster implementation was compatible with Redis cluster, in which users can use the Redis cluster client to access the Kvrocks cluster, also didn’t have the extra proxy latency like the Codis solution. By the way, Kvrocks cluster topo management and scaling have already finished from the latest version 2.0.6. We will continue improving the visibility, operation, and cluster management, to make the cluster better and easier.</p><p>For Kvrocks controller, the community was building the official <a href="https://github.com/KvrocksLabs/kvrocks_controller/tree/develop">controller</a> to make cluster management easier. Welcome anyone who was interested.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d07e416df539" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>