Prev Next

Database / YugabyteDB Interview questions

Last updated

1. What is YugabyteDB? 2. What are the APIs supported by YugabyteDB? 3. What is YSQL in YugabyteDB? 4. What is YCQL in YugabyteDB? 5. What is the role of YB-Master? 6. What is the role of YB-TServer? 7. What is DocDB in YugabyteDB? 8. What is a tablet in YugabyteDB? 9. What is a universe in YugabyteDB? 10. What is the replication factor in YugabyteDB? 11. What are the types of sharding in YugabyteDB? 12. What is yugabyted? 13. What are the default ports used by YugabyteDB? 14. What is YugabyteDB Aeon? 15. What is a colocated table in YugabyteDB? 16. What is the purpose of Raft in YugabyteDB? 17. What is xCluster replication in YugabyteDB? 18. What is the difference between YSQL and YCQL? 19. How does YugabyteDB achieve high availability? 20. How does hash sharding differ from range sharding? 21. How is YugabyteDB different from PostgreSQL? 22. What is the difference between YugabyteDB and CockroachDB? 23. How does YugabyteDB handle distributed transactions? 24. Which isolation levels does YugabyteDB support? 25. Why does YugabyteDB use hybrid logical clocks? 26. How does leader election work in YugabyteDB? 27. What happens when a YB-TServer node fails? 28. What happens when the YB-Master leader fails? 29. How is data stored internally in DocDB? 30. How does tablet splitting work in YugabyteDB? 31. Why do sequential primary keys cause hot spots in YugabyteDB? 32. How do secondary indexes work in YSQL? 33. When should you use colocated tables? 34. How does YugabyteDB scale horizontally when you add nodes? 35. Explain the lifecycle of a YSQL read or write request? 36. Explain the execution flow of a distributed transaction? 37. What is the difference between follower reads and read replicas? 38. How does row-level geo-partitioning work in YugabyteDB? 39. How do you take backups and point-in-time recovery in YugabyteDB? 40. How do you troubleshoot slow queries in YugabyteDB? 41. How do you handle transaction conflicts and retries in YugabyteDB? 42. What is a read restart error and how do you avoid it? 43. When would you choose xCluster over a multi-region universe? 44. How does MVCC garbage collection work in DocDB? 45. How does remote bootstrap work in YugabyteDB? 46. How do you secure a YugabyteDB cluster? 47. How do smart drivers improve connection load balancing? 48. How can you optimize write-heavy workloads in YugabyteDB? 49. How does YugabyteDB support change data capture (CDC)? 50. How do you decommission a node in YugabyteDB?

1. What is YugabyteDB?

YugabyteDB is an open source, distributed SQL database built for cloud-native applications that need horizontal scale, strong consistency and survival of node, zone or region failures. The core is released under the Apache 2.0 license.

It has two layers. The query layer (YQL) exposes YSQL (PostgreSQL-compatible) and YCQL (Cassandra-compatible). Below it, the storage layer DocDB splits data into tablets and replicates every tablet with the Raft protocol.

In practice you write normal PostgreSQL-style SQL, while sharding, synchronous replication and failover are handled by the database.

Take quiz
Which protocol does YugabyteDB use to replicate each tablet?
Gossip-based eventual sync
Chain replication
Raft consensus
Asynchronous log shipping only
What is the name of YugabyteDB's storage layer?
YQL
YB-Master
WiredTiger
DocDB

2. What are the APIs supported by YugabyteDB?

YugabyteDB offers two production APIs on top of the same DocDB storage layer: YSQL and YCQL.

API Compatible with Default port Best for
YSQL PostgreSQL 5433 Relational workloads: joins, foreign keys, ACID transactions
YCQL Apache Cassandra (CQL) 9042 Semi-relational, high-volume key-based access, TTL

Older releases also shipped a Redis-compatible YEDIS API, which has since been deprecated and removed, so don't count it in new designs.

Take quiz
Which YugabyteDB API is compatible with PostgreSQL?
YCQL
YEDIS
YB-Admin API
YSQL
Which API listens on port 9042 by default?
YCQL
YSQL
The yugabyted UI
YB-Master RPC

3. What is YSQL in YugabyteDB?

YSQL is the PostgreSQL-compatible API of YugabyteDB. It reuses PostgreSQL's own parser, planner and executor code, which is why most PostgreSQL syntax, drivers, functions and many extensions work without changes.

The difference is underneath: instead of PostgreSQL's heap storage, YSQL reads and writes through DocDB, so tables are automatically sharded and replicated across nodes.

ysqlsh -h 127.0.0.1 -p 5433 -U yugabyte

CREATE TABLE users (id INT PRIMARY KEY, name TEXT);
INSERT INTO users VALUES (1, 'Asha');

It listens on port 5433 by default, not 5432.

Take quiz
What is the default YSQL port?
5433
5432
9042
7100
What does YSQL reuse from PostgreSQL?
The heap storage engine
The parser, planner and executor code
The single-node WAL
The autovacuum process for tablets

4. What is YCQL in YugabyteDB?

YCQL is the Cassandra Query Language compatible API. Data is organised in keyspaces and tables, and clients can use existing CQL drivers on port 9042.

It's semi-relational: no joins, but it supports consistent secondary indexes, JSON columns, per-row TTL, and distributed ACID transactions when you enable them on a table.

CREATE TABLE shop.orders (
  id int PRIMARY KEY, total decimal
) WITH transactions = { 'enabled' : true };

Unlike Apache Cassandra, YCQL is strongly consistent because it sits on Raft-replicated DocDB.

Take quiz
Which YCQL feature has no direct native equivalent in YSQL?
Primary keys
Per-row TTL
Secondary indexes
ACID transactions
How do you enable multi-row transactions on a YCQL table?
SET ISOLATION LEVEL SERIALIZABLE
ALTER TABLE ... ENABLE RAFT
WITH transactions = { 'enabled' : true }
Use CONSISTENCY ALL on every query

5. What is the role of YB-Master?

YB-Master is the metadata and coordination process of a universe. It stores the system catalog, knows which tablet lives on which tablet server, and coordinates DDL such as create, alter and drop table.

It also runs the cluster load balancer, tracks tablet server heartbeats, and kicks off tablet splits and re-replication of under-replicated tablets.

Masters form their own Raft group (one per replica, so 3 for RF=3) with a single leader. They are not in the normal read/write path: clients cache tablet locations, so a short master outage does not stop DML. Web UI is on 7000 and RPC on 7100.

Take quiz
Is YB-Master involved in every row read or write?
Yes, it routes every request
Yes, it is the only node that commits writes
No, clients cache tablet locations
Only for SELECT queries
How many YB-Master processes does a universe with RF=3 normally run?
1
2
6
3

6. What is the role of YB-TServer?

YB-TServer (tablet server) is the process that actually serves data. It hosts tablet peers, runs the YSQL and YCQL query layers, and executes reads and writes against DocDB.

Each TServer takes part in Raft groups for the tablets it hosts, acting as leader for some and follower for others. It sends heartbeats to the YB-Master so the master can balance load and detect failures.

YB-Master YB-TServer
Holds Catalog and tablet metadata Tablet data and WAL
Handles DDL, balancing, failure detection Client queries and Raft replication
Ports 7000 (web), 7100 (RPC) 9000 (web), 9100 (RPC)

Take quiz
Which process hosts the tablet peers?
YB-Master
yugabyted
ysqlsh
YB-TServer
Which RPC port does YB-TServer use by default?
9100
7100
5433
9042

7. What is DocDB in YugabyteDB?

DocDB is the distributed, transactional storage engine underneath YSQL and YCQL. Each tablet is stored in its own instance of a heavily customised RocksDB (an LSM-tree store).

DocDB handles sharding, Raft replication, MVCC using hybrid timestamps, and the transaction machinery. Rows are stored as encoded keys: hash code, primary key columns, column id, and a timestamp that orders versions.

Because the Raft log already acts as the write-ahead log, DocDB skips the RocksDB WAL to avoid writing every change twice.

Take quiz
What storage engine is DocDB built on?
A customised RocksDB (LSM tree)
A B-tree heap like PostgreSQL
Apache Lucene
InnoDB
Why does DocDB disable the RocksDB WAL?
WALs are not supported on SSDs
The Raft log already serves as the WAL
Writes are kept only in memory
The YB-Master stores the log instead

8. What is a tablet in YugabyteDB?

A tablet is a shard: a contiguous slice of a table's (or index's) key space. It is the basic unit of replication, load balancing and splitting.

Every tablet has as many replicas (peers) as the replication factor, and those peers form a Raft group with one leader serving writes and strongly consistent reads.

You can control the initial tablet count at table creation:

CREATE TABLE events (id INT PRIMARY KEY, payload TEXT)
SPLIT INTO 6 TABLETS;

Take quiz
What is the unit of replication in YugabyteDB?
A whole database
A tablet
A single column
A TServer process
What does SPLIT INTO 6 TABLETS control?
The number of YB-Masters
The replication factor
The initial number of shards for the table
The number of Raft heartbeats per second

9. What is a universe in YugabyteDB?

A universe is what other databases call a cluster: the full set of YB-Master and YB-TServer nodes that together serve one database deployment, possibly spread across zones, regions and clouds.

It has one primary cluster that takes part in synchronous Raft replication, and can optionally have read replica clusters that receive data asynchronously. Placement is described as cloud.region.zone, and the universe is identified by a UUID.

Two universes are independent unless you link them with xCluster replication.

Take quiz
What do you call a full YugabyteDB deployment of master and tserver nodes?
A tablet group
A keyspace
A universe
A tablespace
Which cluster type receives data asynchronously within a universe?
Primary cluster
Master cluster
Raft cluster
Read replica cluster

10. What is the replication factor in YugabyteDB?

The replication factor (RF) is the number of copies kept of each tablet. A write commits once a majority of those copies acknowledge it, so tolerance follows the formula 2f + 1 for f failures.

RF Majority needed Failures tolerated
1 1 0
3 2 1
5 3 2
7 4 3

RF=3 is the common choice, usually one replica per zone. Use an odd RF; an even number costs more without raising fault tolerance.

Take quiz
How many node failures can an RF=5 universe tolerate?
1
3
4
2
With RF=3, how many replicas must acknowledge a write?
2 (a majority)
All 3
Only the leader
1 follower plus a read replica

11. What are the types of sharding in YugabyteDB?

YugabyteDB supports hash sharding and range sharding.

With hash sharding, the first key column is hashed into a 16-bit space (0 to 65535) and that space is divided among tablets. It spreads load evenly and is ideal for point lookups. Range sharding keeps rows ordered by key, which suits range scans and ORDER BY on the key.

-- hash on id, ordered within each id by ts
CREATE TABLE a (id INT, ts TIMESTAMP, PRIMARY KEY (id HASH, ts ASC));

-- range sharded on ts
CREATE TABLE b (ts TIMESTAMP, v INT, PRIMARY KEY (ts ASC));

In YSQL the default for the first primary key column is HASH (range in colocated databases).

Take quiz
What range of hash codes does YugabyteDB use for hash sharding?
0 to 65535
0 to 255
0 to 4 billion
-1 to 1
Which sharding method keeps rows physically ordered by primary key?
Hash sharding
Range sharding
Round-robin sharding
Random sharding

12. What is yugabyted?

yugabyted is the command line utility that makes it easy to start and manage YugabyteDB. It launches the YB-Master and YB-TServer processes for you, so a local cluster is one command.

./bin/yugabyted start
./bin/yugabyted start --join=10.0.0.1   # add a node

It also serves a built-in admin UI on port 15433 and supports multi-node and multi-region setups through flags such as --cloud_location and --fault_tolerance. For fully manual control, teams still start yb-master and yb-tserver directly.

Take quiz
Which port serves the yugabyted admin UI?
7000
15433
5433
9000
What does ./bin/yugabyted start do?
Runs a backup
Opens a ysqlsh session only
Starts the master and tserver processes for a node
Upgrades the cluster

13. What are the default ports used by YugabyteDB?

Knowing the ports saves a lot of time during firewall setup and troubleshooting.

Service Port
YB-Master RPC / web UI 7100 / 7000
YB-TServer RPC / web UI 9100 / 9000
YSQL client / YSQL web 5433 / 13000
YCQL client / YCQL web 9042 / 12000
yugabyted UI 15433

Nodes must reach each other on the RPC ports (7100 and 9100); clients usually only need 5433 or 9042.

Take quiz
What is the default web UI port of YB-Master?
9000
7100
7000
13000
Which two ports must nodes use to talk to each other?
5433 and 9042
7000 and 9000
13000 and 12000
7100 and 9100

14. What is YugabyteDB Aeon?

YugabyteDB Aeon (formerly Yugabyte Managed) is the fully managed database-as-a-service for YugabyteDB, available on AWS, Google Cloud and Azure. The vendor runs provisioning, backups, upgrades, scaling and monitoring for you.

Aeon YugabyteDB Anywhere
Fully managed SaaS Self-managed control plane in your account
Vendor operates the universes Your team operates it
Fastest to start More control over network and infrastructure

Take quiz
What does YugabyteDB Aeon provide?
A Cassandra migration tool
A local development CLI
A PostgreSQL extension
A managed DBaaS for YugabyteDB
Which product is the self-managed control plane?
YugabyteDB Anywhere
YugabyteDB Aeon
yugabyted
ysqlsh

15. What is a colocated table in YugabyteDB?

Normally every table is split into its own tablets, which is wasteful for dozens of small tables. In a colocated database, all tables share a single tablet (per tablespace), so metadata and Raft overhead stay low.

CREATE DATABASE app WITH COLOCATION = true;

-- opt a big table out
CREATE TABLE logs (id INT PRIMARY KEY, msg TEXT)
WITH (COLOCATION = false);

Colocated tables default to range sharding, and joins between them stay on one tablet.

Take quiz
How do colocated tables store their data?
In a shared single tablet
One tablet per row
In memory only
On the YB-Master
How do you keep a large table out of a colocated database's shared tablet?
SET shard_count = 0
WITH (COLOCATION = false)
ALTER DATABASE ... DISABLE RAFT
PARTITION BY HASH

16. What is the purpose of Raft in YugabyteDB?

Raft is the consensus protocol that keeps the replicas of a tablet identical. Each tablet's peers elect a leader; the leader appends writes to its log and sends them to followers.

A write is committed once a majority has persisted it. If the leader dies, the survivors elect a new one, so there is no data loss and no manual failover.

This is what lets YugabyteDB offer strong consistency and high availability together, with a recovery time of a few seconds by default.

Take quiz
When is a write committed in a Raft group?
After the leader writes locally
After a majority of peers persist it
After all peers acknowledge
After the next checkpoint
What happens in Raft when a tablet leader fails?
The YB-Master rewrites the data
The tablet becomes read-only forever
The remaining peers elect a new leader
An admin must promote a follower

17. What is xCluster replication in YugabyteDB?

xCluster is asynchronous replication between two separate universes, either one-way (active-standby) or two-way (active-active). It's used for disaster recovery and for keeping data close to users in different regions.

Because it's asynchronous, writes don't wait for the other universe, so latency stays low, but the RPO is not zero. In transactional mode on the standby, reads see a consistent point in time, which is what you want for failover.

Take quiz
Is xCluster replication synchronous or asynchronous?
Synchronous
Quorum-based per row
Asynchronous
Two-phase commit
Which is a typical use case of xCluster?
Splitting a single tablet
Running the YSQL parser
Compacting SSTables
Disaster recovery between universes

18. What is the difference between YSQL and YCQL?

Both sit on DocDB and are strongly consistent, but they model data very differently. YSQL is fully relational; YCQL is a Cassandra-style, key-oriented API.

Aspect YSQL YCQL
Compatibility PostgreSQL Cassandra CQL
Joins and foreign keys Supported Not supported
Transactions Always ACID Opt-in per table
Per-row TTL No native support Supported
Typical fit OLTP, ORMs, complex queries Large key-value or time-series access

Pick YSQL by default; choose YCQL when migrating a CQL app or when TTL-based expiry is central to the design.

Take quiz
Which API supports joins and foreign keys?
YCQL
Both equally
Neither
YSQL
For an application that relies on automatic row expiry, which API fits better?
YCQL, because of native TTL
YSQL, because of autovacuum
YSQL, because of triggers only
Neither can expire rows

19. How does YugabyteDB achieve high availability?

Every tablet is replicated synchronously with Raft across fault domains. With RF=3 and replicas placed in three zones, losing a whole zone still leaves a majority for every tablet.

When a leader disappears, followers detect it through missed heartbeats and elect a new leader, typically within about 3 seconds by default. Clients retry against the new leader and the write RPO inside the universe is zero.

You tell the cluster where nodes live with placement flags:

yb-tserver --placement_cloud aws \
           --placement_region us-east-1 \
           --placement_zone us-east-1a

The master's load balancer then spreads replicas across zones, so no single zone holds a majority.

Take quiz
What is the write RPO inside a single YugabyteDB universe with Raft?
Zero
About 15 minutes
One hour
Depends on the backup schedule
Why should RF=3 replicas be spread across zones?
To make queries slower on purpose
So losing one zone still leaves a majority
To avoid using the master
To disable leader election

20. How does hash sharding differ from range sharding?

The difference is how a key maps to a tablet, and that drives which queries are fast.

Hash sharding Range sharding
Key is hashed; rows land by hash code Rows kept in sorted key order
Even spread, few hot spots Risk of hot spots on sequential keys
Fast point lookups Fast range scans and ordered reads
Range scans on the hash column touch many tablets Starts as one tablet unless pre-split

A common pattern is a composite key: hash on a tenant or device id, range on a timestamp. You get even distribution across devices and ordered scans within each device.

Take quiz
Which sharding method is more prone to hot spots on sequential keys?
Hash sharding
Range sharding
Neither
Both exactly the same
What does a key of (device_id HASH, ts ASC) give you?
A single tablet for the whole table
Random ordering of timestamps
Even spread by device and ordered scans per device
No ability to look up by device

21. How is YugabyteDB different from PostgreSQL?

YSQL looks like PostgreSQL to the client, but the storage and replication model are completely different.

Area PostgreSQL YugabyteDB (YSQL)
Scale Vertical, read replicas Horizontal, automatic sharding
Storage Heap and B-tree LSM-based DocDB, table clustered by primary key
Replication Async or sync streaming, single writer Raft per tablet, multi-node writes
Failover External tooling needed Automatic via leader election
Cleanup VACUUM for dead tuples Compaction removes old versions

Not every PostgreSQL feature or extension is supported, and queries that scan huge ranges cost more because data is spread across nodes. Check compatibility before migrating.

Take quiz
How does YugabyteDB handle failover compared with a single-node PostgreSQL?
It requires pg_failover scripts
It does not support failover
Automatically through Raft leader election
Only through manual backups
How is a YSQL table physically organised?
As an unordered heap
As a flat text file per row
In one tablet per column
Clustered by its primary key in DocDB

22. What is the difference between YugabyteDB and CockroachDB?

Both are distributed SQL databases inspired by Google Spanner, but they differ in how they get PostgreSQL compatibility and in their licensing.

Aspect YugabyteDB CockroachDB
PostgreSQL compatibility Reuses PostgreSQL query layer code Own SQL engine speaking the PG wire protocol
Storage engine DocDB (RocksDB fork) Pebble
APIs YSQL and YCQL SQL only
License Apache 2.0 core Source-available proprietary license

Reusing PostgreSQL code usually means better coverage of features like triggers, stored procedures and extensions. Validate your own workload on either before deciding.

Take quiz
How does YSQL achieve PostgreSQL compatibility?
By translating SQL to CQL
By running a PostgreSQL server per node
By supporting only the wire protocol
By reusing PostgreSQL's query layer code
Which storage engine does DocDB customise?
RocksDB
Pebble
LevelDB's Go port
SQLite

23. How does YugabyteDB handle distributed transactions?

Transactions that touch several tablets use a lock-free, two-phase-style commit built on a transaction status table.

  1. The transaction gets a hybrid-time start and a record in a status tablet marked pending.
  2. Writes go to each participant tablet as provisional records (intents), replicated by Raft.
  3. On commit, a single atomic update flips the status record to committed; that is the commit point.
  4. Participants then asynchronously convert intents into regular records and clean up.

Single-row operations skip this machinery and use a faster single-tablet path, so they stay cheap.

Take quiz
What marks the commit point of a distributed transaction?
Updating the record in the transaction status tablet
The last intent being written
The next compaction
A YB-Master restart
What are provisional records?
Backup copies in S3
Uncommitted intents written to participant tablets
Cached query plans
Index statistics

24. Which isolation levels does YugabyteDB support?

YSQL supports three real isolation levels:

Level Behaviour
Serializable Strictest; conflicting transactions abort with a serialization error
Snapshot (Repeatable Read) Whole transaction reads one consistent snapshot
Read Committed Each statement sees a fresh snapshot; conflicts are retried transparently

Read Uncommitted is treated as Read Committed. Depending on your release, Read Committed may need to be enabled with the yb_enable_read_committed_isolation flag, so check the docs for your version.

Serializable and Repeatable Read can throw 40001 errors that the application should retry; Read Committed removes most of that burden.

Take quiz
In YSQL, which level makes a whole transaction read one consistent snapshot?
Read Committed
Snapshot (Repeatable Read)
Read Uncommitted
None of them
What does YSQL do with Read Uncommitted?
Allows dirty reads
Rejects the statement
Treats it as Read Committed
Treats it as Serializable

25. Why does YugabyteDB use hybrid logical clocks?

Distributed nodes cannot share a perfect clock, but MVCC and transactions need a consistent ordering of events. A hybrid logical clock (HLC) combines a physical timestamp with a logical counter, giving timestamps that are close to wall-clock time yet still respect causality.

Whenever nodes exchange messages, they push their clock to at least the sender's value, so a later event always gets a larger timestamp. Unlike Google Spanner's TrueTime, it needs no atomic clocks or GPS hardware, only reasonably synced NTP.

The trade-off is a bounded clock skew (500 ms by default) that can cause read restarts.

Take quiz
What does a hybrid logical clock combine?
Two GPS signals
A random UUID and a node name
A physical time and a logical counter
Only an incrementing integer
What hardware does YugabyteDB require for its clock, compared with Spanner TrueTime?
Atomic clocks
GPS receivers
FPGA timing cards
None special, just synced NTP

26. How does leader election work in YugabyteDB?

Every tablet runs its own Raft election, so leaders are spread across nodes rather than concentrated on one.

  1. Followers expect a heartbeat from the leader (every 500 ms by default).
  2. After about six missed heartbeats (around 3 seconds), a follower becomes a candidate and requests votes.
  3. A candidate that gets a majority becomes the new leader.
  4. The new leader waits for the old leader's lease to expire before serving strongly consistent reads, which prevents stale reads from a deposed leader.

You can use preferred leader placement to pin leaders to a region closest to your users.

Take quiz
Why does a new leader wait for the old leader's lease to expire?
To rebuild the index
To flush the memtable
To re-register with the YB-Master
To avoid stale reads from the old leader
What do followers monitor to detect leader failure?
Missed heartbeats
Disk usage
SQL query counts
The YB-Master web UI

27. What happens when a YB-TServer node fails?

Tablets whose leader lived on that node briefly stall, then their remaining peers elect new leaders in a few seconds. Reads and writes resume without admin action.

The master doesn't re-replicate immediately. If the node stays down longer than follower_unavailable_considered_failed_sec (900 seconds by default), it is considered failed and the master recreates the lost replicas on other nodes using remote bootstrap.

If the node returns sooner, it simply catches up from the Raft log, which avoids needless data copying after a quick reboot.

Take quiz
After about how long does the master treat a down tserver's replicas as failed by default?
15 minutes (900 seconds)
5 seconds
1 hour
Never
What happens to tablets that had their leader on the failed node?
They are deleted
Remaining peers elect new leaders
They become read-only until reboot
The client elects them manually

28. What happens when the YB-Master leader fails?

The masters are a Raft group, so the remaining masters elect a new leader, usually within seconds.

Normal reads and writes are mostly unaffected because tablet servers and clients cache tablet locations. What pauses briefly is anything needing the master: DDL, tablet splits, and load-balancing decisions.

Tablet servers heartbeat to all masters, so the new leader quickly rebuilds its view of the cluster. With 3 masters you can lose 1; with 5 you can lose 2.

Take quiz
Which operations are paused briefly when the master leader fails?
All SELECT queries
DDL and load balancing
Raft replication on tablets
Client authentication only
How many masters can you lose with 5 masters?
1
3
2
5

29. How is data stored internally in DocDB?

Each tablet is a RocksDB instance, an LSM tree. Writes are first applied to an in-memory memtable, which is flushed to immutable SSTable files, and background compaction merges them.

A row is encoded into keys of the form: hash code, primary key columns, column id, and a hybrid timestamp stored in descending order so the newest version is found first. That makes MVCC reads natural.

Durability comes from the Raft log, so DocDB skips RocksDB's own WAL. Bloom filters and a block cache keep point lookups fast despite multiple SSTables.

Take quiz
Why is the timestamp stored in descending order inside a DocDB key?
To reduce disk space
To sort by node name
So the newest version is found first
To hide old data
What is the in-memory write buffer in an LSM tree called?
Heap page
Redo buffer
Undo segment
Memtable

30. How does tablet splitting work in YugabyteDB?

Tablets can be split in three ways: pre-splitting at creation, automatic splitting when a tablet crosses a size threshold, and manual splitting.

-- pre-split a range table
CREATE TABLE t (id INT, PRIMARY KEY (id ASC))
SPLIT AT VALUES ((1000), (2000));

yb-admin -master_addresses ... split_tablet <tablet_id>

A split is cheap: the tablet's SSTables are hard-linked into two child tablets, so no data is copied up front. Later compaction removes data outside each child's range. Auto-split thresholds are phased by cluster size and are tunable.

Take quiz
Why is a tablet split fast?
The data is deleted first
The cluster is taken offline
Rows are re-hashed one by one
SSTable files are hard-linked, not copied
Which option pre-splits a range-sharded table at given key values?
SPLIT AT VALUES
SPLIT INTO ROWS
PARTITION BY SIZE
SHARD EVENLY

31. Why do sequential primary keys cause hot spots in YugabyteDB?

With range sharding, a monotonically increasing key such as a timestamp or serial id sends every new insert to the last tablet. One leader does all the work while other nodes sit idle.

Ways to fix it:

  • Use hash sharding on the key (or a UUID).
  • Add a bucket column: PRIMARY KEY ((bucket, ts) HASH) or (bucket HASH, ts ASC).
  • Create a hash-sharded index: CREATE INDEX idx ON events (ts HASH);
  • Pre-split range tables if ordering matters.

Trade-off: hashing spreads writes but makes ordered range scans more expensive.

Take quiz
Where do new rows land with a range-sharded, increasing key?
In the last tablet
Evenly across all tablets
On a random node
In the YB-Master
Which change spreads writes of a timestamp index?
Add ASC to ts
Create the index with ts HASH
Increase the replication factor
Disable compaction

32. How do secondary indexes work in YSQL?

A secondary index is a separate DocDB table, sharded independently of the base table. Its keys are the indexed columns plus the base table's primary key.

Writes update the base row and the index in the same distributed transaction, so they stay consistent. Reads use the index then fetch the row, unless the index covers the query:

CREATE INDEX idx_orders_cust
ON orders (customer_id) INCLUDE (total);

That allows an index-only scan. Unique, partial and expression indexes are supported, and builds are online. The cost is write amplification: every extra index adds a write.

Take quiz
What does INCLUDE (total) enable in the index?
Automatic sharding of the base table
Index-only scans for queries using total
Faster Raft elections
Disabling transactions
Why can secondary indexes slow down writes?
They lock the YB-Master
They disable compaction
Each index adds an extra write per row change
They force RF to increase

33. When should you use colocated tables?

Use colocation when you have many small tables that would otherwise create hundreds of tiny tablets, for example multi-tenant schemas or per-microservice databases with modest data.

Avoid it for large or fast-growing tables, since a colocated tablet is limited to the capacity of one set of replicas. Tables that outgrow it can be opted out with COLOCATION = false.

If you only want some tables to share a tablet in a non-colocated database, use a tablegroup:

CREATE TABLEGROUP small_tables;
CREATE TABLE ref (id INT PRIMARY KEY) TABLEGROUP small_tables;

Take quiz
When is colocation a good fit?
A single multi-terabyte table
A table needing hundreds of tablets
Many small tables in one database
A write-heavy event log
What lets some tables share a tablet without colocating the whole database?
A tablespace
A read replica
A snapshot schedule
A tablegroup

34. How does YugabyteDB scale horizontally when you add nodes?

You start a new yb-tserver pointing at the existing masters. No downtime or manual resharding is needed.

  1. The new TServer registers with the YB-Master and sends heartbeats.
  2. The master's load balancer sees the imbalance and moves some tablet replicas to the new node.
  3. Each move uses remote bootstrap to copy data from a current peer, then the Raft config is updated.
  4. Tablet leaders are also rebalanced so the new node takes a fair share of traffic.
  5. If tablets are too few or too large, tablet splitting creates more units to move.

The balancer is throttled so moves don't starve production traffic.

Take quiz
What moves tablet replicas onto a newly added node?
The client driver
A cron job on the new node
The Raft heartbeat
The master's load balancer
Why can scale-out need tablet splitting?
Too few tablets means too little to spread across nodes
Splits reduce replication factor
Splits remove the need for a master
Splits encrypt data

35. Explain the lifecycle of a YSQL read or write request?

A client connects to any TServer's YSQL port, where a PostgreSQL backend process parses and plans the query. The plan's reads and writes are handed to the DocDB layer, which finds the right tablet leaders.

sequenceDiagram
  participant C as Client
  participant Y as YSQL backend (any TServer)
  participant L as Tablet leader
  participant F as Followers
  C->>Y: SQL statement
  Y->>Y: Parse and plan
  Y->>L: Read or write RPC (cached tablet location)
  L->>F: Replicate via Raft (writes only)
  F-->>L: Majority ack
  L-->>Y: Result
  Y-->>C: Response

Reads go to the leader and need no replication round trip. Writes commit after a majority of followers acknowledge. If the tablet location cache is stale, the client refreshes it from the master.

Take quiz
Where does a write request wait for acknowledgement from a majority?
At the tablet leader's Raft group
At the YB-Master
At the client driver
At the PostgreSQL planner
Which component parses and plans a YSQL query?
The YB-Master
The PostgreSQL backend on the TServer
DocDB
yb-admin

36. Explain the execution flow of a distributed transaction?

Here is what happens for a transaction updating rows in two tablets:

sequenceDiagram
  participant C as Client
  participant Co as Transaction coordinator
  participant S as Status tablet
  participant T1 as Tablet A
  participant T2 as Tablet B
  C->>Co: BEGIN, UPDATEs
  Co->>S: Create txn record (PENDING)
  Co->>T1: Write intents
  Co->>T2: Write intents
  C->>Co: COMMIT
  Co->>S: Set status COMMITTED
  S-->>C: Commit ack
  S-)T1: Apply intents (async)
  S-)T2: Apply intents (async)

Intents are replicated by Raft like any write, and conflicts with other transactions are detected when intents are written. The single status update is the atomic commit point, and the final apply step happens in the background.

Take quiz
Which step makes the transaction durable and visible?
Writing the first intent
Setting the status record to COMMITTED
Creating the PENDING record
The background apply to tablets
When are intents converted into regular records?
Before BEGIN
Only at the next backup
Asynchronously after commit
Never

37. What is the difference between follower reads and read replicas?

Both reduce read latency for far-away clients by serving data from a nearby copy, but they are different mechanisms.

Aspect Follower reads Read replicas
Where data lives Existing Raft followers in the primary cluster Separate cluster outside the quorum
Replication Synchronous part of the Raft group Asynchronous
Effect on write latency Followers count toward the quorum None
Staleness Bounded (30 s by default) Replication lag

SET yb_read_from_followers = true;
SET yb_follower_read_staleness_ms = 5000;
START TRANSACTION READ ONLY;

Follower reads work only in read-only transactions or statements.

Take quiz
Do read replicas participate in the write quorum?
Yes, always
Yes, but only the first one
No
Only during failover
What is required to use follower reads?
A separate universe
Serializable writes
Disabling Raft
Read-only transactions or statements

38. How does row-level geo-partitioning work in YugabyteDB?

You partition a table by a region column and attach each partition to a tablespace that pins its replicas to specific zones. Rows for EU users then physically stay in EU zones, which helps with latency and data-residency rules.

CREATE TABLESPACE eu_ts WITH (replica_placement=
 '{"num_replicas":3,"placement_blocks":[
  {"cloud":"aws","region":"eu-west-1","zone":"eu-west-1a","min_num_replicas":1},
  {"cloud":"aws","region":"eu-west-1","zone":"eu-west-1b","min_num_replicas":1},
  {"cloud":"aws","region":"eu-west-1","zone":"eu-west-1c","min_num_replicas":1}]}');

CREATE TABLE users (id INT, geo TEXT, name TEXT,
  PRIMARY KEY (id, geo)) PARTITION BY LIST (geo);
CREATE TABLE users_eu PARTITION OF users
  FOR VALUES IN ('EU') TABLESPACE eu_ts;

The partition key must be part of the primary key.

Take quiz
What pins a partition's replicas to specific zones?
A read replica cluster
A snapshot schedule
A hash index
A tablespace with replica_placement
What must the partition column be part of?
The primary key
The YB-Master config
A materialized view
The tablet ID

39. How do you take backups and point-in-time recovery in YugabyteDB?

YugabyteDB takes distributed snapshots: a consistent copy created per tablet using hard links, so it's fast and cheap. YugabyteDB Anywhere and Aeon schedule these and ship them to S3, GCS, Azure Blob or NFS.

For PITR you create a snapshot schedule, then restore to any timestamp within the retention window:

yb-admin -master_addresses $MASTERS \
  create_snapshot_schedule 1440 10080 ysql.mydb

yb-admin -master_addresses $MASTERS \
  restore_snapshot_schedule <schedule_id> "2026-11-10 14:30:00"

The numbers are the interval and retention in minutes. A logical backup with ysql_dump is also available for smaller datasets and migrations.

Take quiz
What do the numbers 1440 and 10080 mean in create_snapshot_schedule?
Interval and retention in minutes
Tablet counts
Port numbers
RF and node count
What makes distributed snapshots fast?
Copying every row by SQL
Hard links to SSTable files
Stopping the cluster
Exporting to CSV

40. How do you troubleshoot slow queries in YugabyteDB?

Work from the query outward:

  1. Run EXPLAIN (ANALYZE, DIST) to see rows read, RPC counts and storage time.
  2. Check pg_stat_statements for the heaviest queries.
  3. Look for missing indexes or full scans, and for filters that cannot be pushed down.
  4. Check the tserver tablets page for hot tablets or leaders concentrated on one node.
  5. Look for conflicts and retries in logs (40001 errors).
  6. Check cross-region latency, clock skew, disk I/O and compaction backlog in Prometheus metrics.

Most slowness comes from too many round trips to storage, so fewer, larger batched statements help.

Take quiz
Which command shows distributed storage metrics for a query?
SHOW TABLETS
EXPLAIN (ANALYZE, DIST)
VACUUM VERBOSE
ANALYZE TABLET
What does a hot tablet usually indicate?
A broken YB-Master
Too many read replicas
Skewed traffic on one key range or leader
Disabled TLS

41. How do you handle transaction conflicts and retries in YugabyteDB?

When two transactions touch the same row, one fails with SQLSTATE 40001. YugabyteDB offers two conflict modes: fail-on-conflict (abort quickly) and wait-on-conflict (queue behind the blocker, closer to PostgreSQL behaviour). Read Committed retries statements for you; stricter levels expect the app to retry.

for attempt in range(5):
    try:
        run_transaction()
        break
    except SerializationFailure:
        sleep(0.05 * 2 ** attempt)   # backoff

Keep transactions short, access rows in a consistent order, and use SELECT ... FOR UPDATE when you know you will modify the rows.

Take quiz
Which SQLSTATE signals a serialization or conflict failure?
23505
42P01
40001
08006
What should an app do on a 40001 error?
Restart the YB-Master
Disable Raft
Switch to YCQL
Retry the transaction with backoff

42. What is a read restart error and how do you avoid it?

Because clocks are only synchronised within a bound (500 ms by default), a read may find a value written just after its snapshot time but inside that uncertainty window. The database can't tell whether it should be visible, so it asks the read to restart at a later time.

If no results have been sent to the client yet, YugabyteDB retries transparently. Otherwise the client sees a 40001 "restart read required" error.

To reduce them: keep clocks tight with chrony or NTP, use Read Committed where acceptable, and keep result sets small so restarts happen before data is returned. Newer releases also add options to relax read-after-commit visibility, so check the release notes for your version.

Take quiz
What causes a read restart?
A full disk
A missing index
A dropped tablet
A write inside the clock uncertainty window
Which practice reduces read restarts?
Keeping node clocks tightly synchronised
Increasing the replication factor
Disabling compactions
Using more tablets per table

43. When would you choose xCluster over a multi-region universe?

Choose by what you value more: zero data loss or low write latency.

Factor Multi-region universe xCluster (two universes)
Replication Synchronous Raft Asynchronous
RPO Zero Greater than zero
Write latency Includes cross-region round trip Local only
Failure handling Automatic, no failover step Failover procedure needed
Fit Strict consistency, a few nearby regions DR, distant regions, latency-sensitive writes

A stretched universe works well for regions within tens of milliseconds. For continents apart, or when some data loss is acceptable for faster writes, xCluster usually wins.

Take quiz
Which option guarantees zero RPO?
A multi-region universe with synchronous Raft
xCluster in async mode
A nightly logical backup
A read replica
When does xCluster fit better?
When zero data loss is mandatory
Regions far apart with latency-sensitive writes
When you have one node
When you need Raft quorum across oceans

44. How does MVCC garbage collection work in DocDB?

DocDB keeps many versions of a row so readers don't block writers. Old versions and delete tombstones are removed during compaction, not by a separate VACUUM process.

A compaction filter drops versions older than the history retention cutoff, controlled by timestamp_history_retention_interval_sec (900 seconds by default). Snapshot schedules for PITR extend that retention so older timestamps stay readable.

A transaction that reads beyond the retained history fails with a snapshot-too-old style error, so very long-running readers need care.

Take quiz
What removes old row versions in DocDB?
VACUUM FULL
Compaction with a history cutoff
Raft log truncation
The YB-Master
What happens if a read needs data older than the retention window?
It reads from the YB-Master
It waits forever
It fails because the history was garbage collected
It returns NULL

45. How does remote bootstrap work in YugabyteDB?

Remote bootstrap is how a new or far-behind replica gets a full copy of a tablet.

  1. The master decides a peer is needed (re-replication, a new node, or a peer behind the retained WAL).
  2. The destination TServer asks the leader (or a healthy peer) for a checkpoint of the tablet's RocksDB files and recent log.
  3. Files are streamed across and the tablet is opened locally.
  4. The peer replays the remaining Raft log entries and joins the group as a voting follower.

Transfer speed is capped by remote_bootstrap_rate_limit_bytes_per_sec so foreground traffic isn't starved.

Take quiz
Which node is usually the source for a remote bootstrap?
The YB-Master
The client
The tablet leader or a healthy peer
A backup bucket only
What caps remote bootstrap transfer speed?
max_clock_skew_usec
ysql_max_connections
tablet_split_size
remote_bootstrap_rate_limit_bytes_per_sec

46. How do you secure a YugabyteDB cluster?

Security is layered, and each layer is configured separately.

  • Encryption in transit: TLS for node-to-node and client-to-node traffic.
  • Encryption at rest: universe keys, optionally managed through a cloud KMS.
  • Authentication: password with SCRAM-SHA-256, LDAP, and similar.
  • Authorization: roles and GRANT, plus row-level security in YSQL.
  • Network: firewall rules so only clients reach 5433 or 9042, and only nodes reach RPC ports.
  • Auditing: pgAudit for YSQL activity.

Turn authentication on from day one; the default dev setup is open.

Take quiz
Which ports should be limited to cluster nodes only?
5433
9042
15433
RPC ports 7100 and 9100
Which mechanism protects stored data on disk?
Encryption at rest
Raft heartbeats
Tablet splitting
Follower reads

47. How do smart drivers improve connection load balancing?

A normal PostgreSQL driver talks to one host. YugabyteDB smart drivers discover every node through the cluster and spread connections across them, so one node doesn't become a bottleneck.

They are cluster-aware (uniform load balancing) and topology-aware (prefer nodes in given regions or zones), and fail over to other nodes if one goes down.

jdbc:yugabytedb://host1:5433/yugabyte?load-balance=true
  &topology-keys=aws.us-east-1.us-east-1a

Without a smart driver, you need an external load balancer in front of port 5433.

Take quiz
What does topology-aware mean for a smart driver?
It prefers nodes in specified regions or zones
It rewrites SQL for each zone
It disables Raft
It changes the primary key
What is the alternative if you do not use a smart driver?
Using only YCQL
An external load balancer on port 5433
Disabling TLS
Running a single node

48. How can you optimize write-heavy workloads in YugabyteDB?

Most gains come from cutting round trips and write amplification.

  • Batch: multi-row INSERT, prepared statements, or COPY rather than one row per call.
  • Keys: use hash sharding or UUIDs to avoid a single hot tablet.
  • Indexes: drop unused ones, since each index doubles part of the write path.
  • Sequences: use a larger sequence cache.
  • Tablets: pre-split large tables so all nodes take load from the start.
  • Placement: use preferred leaders close to the writers so quorum latency stays low.

Measure with EXPLAIN (ANALYZE, DIST) before and after each change.

Take quiz
Why does removing unused indexes help write throughput?
Indexes block Raft elections
Each index adds writes to the transaction
Indexes lower the replication factor
Indexes disable batching
Which technique cuts round trips for bulk loads?
One INSERT per connection
Using a smaller RF
Batching rows with COPY or multi-row INSERT
Turning off TLS

49. How does YugabyteDB support change data capture (CDC)?

CDC streams row-level changes out of DocDB so downstream systems like Kafka, search or analytics can follow along.

The main routes are the Debezium-based gRPC connector, which reads from tablet WAL through CDC streams, and, in newer releases, the PostgreSQL logical replication model with publications and replication slots. Both can feed Kafka Connect.

Changes are emitted per tablet and ordered by commit time. Pick the approach your version documents as supported, because the connector options have evolved quickly.

Take quiz
Which tool is commonly used to stream YugabyteDB changes to Kafka?
pgBouncer
yb-ctl
Debezium
pg_basebackup only
What source does the gRPC CDC connector read changes from?
The YB-Master UI
Client logs
Application caches
The tablet WAL through CDC streams

50. How do you decommission a node in YugabyteDB?

The aim is to move all replicas off the node before it is stopped, so redundancy never drops.

  1. Blacklist the tserver so the balancer drains it:
    yb-admin -master_addresses $MASTERS \
      change_blacklist ADD 10.0.0.7:9100
    

  2. Wait until get_load_move_completion reports 100%.
  3. If the node ran a master, remove it:
    yb-admin -master_addresses $MASTERS \
      change_master_config REMOVE_SERVER 10.0.0.7 7100
    

  4. Stop the yb-tserver and yb-master processes and release the node.

In YugabyteDB Anywhere, the Remove Node action does all of this for you.

Take quiz
What is the first step to drain a node?
Delete its data directory
Stop the YB-Master leader
Drop the table
Add it to the blacklist
What does get_load_move_completion tell you?
How much of the replica draining is complete
The current Raft term
The size of the WAL
The number of clients
«
»

Comments & Discussions