Help Center/ Key-Value Storage Service/ FAQs/ KVS Concepts/ What Are the Differences Between Shard Keys and Sort Keys?
Updated on 2025-04-14 GMT+08:00

What Are the Differences Between Shard Keys and Sort Keys?

Table 1 shows the comparison between shard keys and sort keys.

Table 1 Comparison between shard keys and sort keys

Dimension

Shard Key

Sort Key

Scenario

A shard key determines in which shard a KV item is stored. In a user table, for example, you can specify the username field as the shard key. KVS then stores KV items with the same username in the same shard.

KV items with the same shard key are stored by sort key. You can query data by sort key.

Primary keys supported

Simple primary key (shard key) and composite primary key (shard key and sort key).

Composite primary key (shard key and sort key).