vtctldclient is your command-line interface to the Vitess cluster’s control plane. It lets you interact with vtctld, the master process responsible for managing the Vitess topology, shard rebalancing, and other administrative tasks. Think of it as the kubectl for Vitess.

Let’s see it in action. Imagine you have a keyspace named commerce and you want to see its current sharding configuration.

vtctldclient --server vtctld-0.vtctld-headless.my-namespace.svc.cluster.local:15999 GetSVTablespaces commerce

This command, when executed against a running Vitess cluster, would output something like this:

{
  "svt_tablespaces": [
    {
      "name": "commerce",
      "shards": [
        {
          "name": "0",
          "tablet_types": [
            "PRIMARY",
            "REPLICA",
            "RDONLY"
          ],
          "master_tablet": "cell:vt-0000000000,alias:vt-0000000000",
          "replica_tablets": [
            "cell:vt-0000000001,alias:vt-0000000001",
            "cell:vt-0000000002,alias:vt-0000000002"
          ],
          "rdonly_tablets": [
            "cell:vt-0000000003,alias:vt-0000000003"
          ]
        },
        {
          "name": "1",
          "tablet_types": [
            "PRIMARY",
            "REPLICA",
            "RDONLY"
          ],
          "master_tablet": "cell:vt-0000000004,alias:vt-0000000004",
          "replica_tablets": [
            "cell:vt-0000000005,alias:vt-0000000005",
            "cell:vt-0000000006,alias:vt-0000000006"
          ],
          "rdonly_tablets": [
            "cell:vt-0000000007,alias:vt-0000000007"
          ]
        }
      ]
    }
  ]
}

Here, vtctldclient is talking to the vtctld service on port 15999 in the my-namespace Kubernetes cluster. The GetSVTablespaces command retrieves information about the commerce keyspace, detailing its shards (0 and 1 in this case) and the tablets serving each shard with their respective roles (PRIMARY, REPLICA, RDONLY).

The core problem Vitess solves is managing massive relational databases that exceed the capacity of a single server. Sharding, the process of splitting a database across multiple servers, is the key. However, managing shards, their topology, and ensuring consistent operations becomes incredibly complex at scale. Vitess provides a layer that sits above your MySQL instances, handling this sharding logic transparently to your application.

vtctld is the brain of this operation. It maintains the Vitess topology, which is essentially a map of all your keyspaces, shards, and tablets. This topology is typically stored in etcd or Zookeeper. When you execute a vtctldclient command, it’s sending a gRPC request to vtctld, which then queries its topology information and directs actions to the appropriate tablets.

For example, if you wanted to initiate a reshard operation for the commerce keyspace, you’d use vtctldclient to tell vtctld to start the process. vtctld would then orchestrate the complex steps, involving cloning data from source shards to destination shards, migrating traffic, and updating the topology.

The vtctldclient tool provides commands for a wide range of administrative tasks:

  • Topology Management: GetKeyspaces, GetSVTablespaces, GetTablets, GetShard
  • Schema Management: GetSchema, ApplySchema
  • Resharding and Shard Management: Migrate (for resharding), SplitClone, SplitDiff, SplitMoveTables
  • Health and Status: GetHealth, GetVersion
  • Workflows: ListWorkflows, CancelWorkflow

Understanding the relationship between vtctld and vtctldclient is crucial. vtctld is the active manager, constantly aware of the cluster state, while vtctldclient is your way to query that state and issue commands.

Most users interact with vtctldclient through its CLI, but it’s also a gRPC client, meaning you can programmatically interact with vtctld from your applications or custom scripts. This allows for automation of complex operational tasks.

One of the less obvious, but incredibly powerful, aspects of vtctldclient is its ability to directly interact with the underlying tablet processes. For instance, commands like VtctlCommand allow you to execute arbitrary Vitess commands on specific tablets, bypassing the higher-level abstractions for deep debugging or advanced operations. This is akin to SSHing directly into a database server, but within the Vitess framework, ensuring that the command is executed in the correct context and with appropriate permissions.

As you delve deeper into Vitess operations, you’ll find yourself using vtctldclient to manage complex schema changes, rebalancing shards for performance, and ensuring the overall health and availability of your distributed database.

The next logical step after mastering vtctldclient is understanding the underlying gRPC API and how to build custom automation around Vitess operations.

Want structured learning?

Take the full Vitess course →