Why Are There Multiple Leaders in a YugabyteDB Cluster?

Distributed SQL Tips and Tricks Series
Marko Rajcevic

In YugabyteDB, there are two main services: YB-TServer service and YB-Master service. More specifically, the former is the data layer responsible for all database-level operations. The latter makes up the control layer and is responsible for propagating cluster-level operations, as well as storing database metadata—such as the PostgreSQL catalog—throughout the cluster.

The tables and indexes in both services are split into tablets (i.e. shards). Each tablet is replicated based on the cluster-level value set for the replication factor (RF). With its replicants, these tablets make up what is referred to as a RAFT group. Therefore, each RAFT group has a single leader and multiple followers dependent on that RF value.

Examining the YB-Master Service

As an example and to clarify, let’s look at the YB-Master service, which—as stated above—is responsible for maintaining YugabyteDB cluster consistency. A YB-Master server has master-leaders and master-followers, which receive, apply, and acknowledge the master-leader changes. As replicants, they also serve the purpose of maintaining high availability. If anything were to happen to the master-leader, one master-follower would be selected as the new leader. All tables are at the YB-TServer level and will typically host more than one tablet-leader as well as tablet-followers for the table data.

Explore the YB-Master Server in-depth>>>

Explore the YB-TServer in-depth>>>

Although a cluster will only have a certain number of YB-Master servers, based on its RF, every node will have a YB-TServer since it controls the actual data. As mentioned above, all tables are split into a certain amount of shards/tablets, which is defined by the configuration flag (ysql_num_shards_per_tserver for YSQL or yb_num_shards_per_tserver for YCQL). These flags can be overridden and explicitly set during the CREATE TABLE step by calling out the clause SPLIT INTO. Therefore, each of these tablets will be a RAFT group with a number of copies. And once split, each RAFT group will be equally distributed across the available nodes on the cluster. In sum, we have a single master-leader for the YB-Master service, and a tablet-leader for every shard/tablet in the YB-TServer.

For more information, check out What Is the Best Way to Control the Total Number of Shards in My YugabyteDB Cluster ?

Discover More Tips and Tricks

Explore our library of distributed SQL tips and tricks and general “how to” information on the YugabyteDB blog and on our DEV Community Blogs.

Events and Training

Check out the upcoming YugabyteDB events, including all training sessions, conferences, in-person and virtual events, and YugabyteDB Friday Tech Talks (designed for engineers by engineers).

In addition, there is some extremely popular “how to” content on the YugabyteDB YouTube channel.

If You Have Questions About YugabyteDB and Distributed SQL

If you have questions, ask them on the YugabyteDB Slack channel, Forum, GitHub, or Stack Overflow.

Ready To Start Exploring YugabyteDB Features?

You have some great options to get started. Run the database locally on your laptop (Quick Start), deploy it to your favorite cloud provider (Multi-node Cluster Deployment), sign up for a free YugabyteDB Managed cluster, or request a full-featured trial. It’s easy! Get started today!

Marko Rajcevic

Related Posts

Explore Distributed SQL and YugabyteDB in Depth

Discover the future of data management.
Learn at Yugabyte University
Get Started
Browse Yugabyte Docs
Explore docs
PostgreSQL For Cloud Native World
Read for Free