Sharding into tablets

User tables are implicitly managed as multiple shards by DocDB. These shards are referred to astablets. The primary key for each row in the table uniquely determines the tablet the row lives in. This is shown in the figure below.

Sharding a table into tablets

Hash sharding

The hash space for hash-sharded YugabyteDB tables is the 2-byte range from 0x0000 to 0xFFFF. Sucha table may therefore have at most 64K tablets. We expect this to be sufficient in practice even forvery large data sets or cluster sizes.

As an example, for a table with 16 tablets the overall hash space [0x0000 to 0xFFFF) is divided into16 sub-ranges, one for each tablet: [0x0000, 0x1000), [0x1000, 0x2000), … , [0xF000, 0xFFFF].

tablet_overview

Read and write operations are processed by converting the primary key into an internal key and its hashvalue, and determining what tablet the operation should be routed to.

The figure below illustrates this.

tablet_hash

NoteFor every given key, there is exactly one tablet that owns it.

The insert/update/upsert by the end user is processed by serializing and hashing the primary key into byte-sequences and determining the tablet they belong to. Let us assume that the user is trying to insert a key k with a value v into a table T. The figure below illustrates how the tablet owning the key for the above table is determined.

tablet_hash_2

Range sharding