UUID Use Case
UUID Shard Key
A shard key decides which partition a row lives on. Random UUIDs distribute writes uniformly; time-ordered ones can pile recent writes onto one shard.
Even spreadv4 recommendedAvoids hotspots
Generated locally with the Web Crypto API — nothing leaves your browser.
What Is UUID Shard Key?
- For sharding you usually want a key with no temporal pattern, so new rows land on every shard instead of accumulating on the 'newest' one.
- That is the opposite of the primary-key advice: a random v4 is ideal for the shard key even when the primary key is a v7.
How to generate
- Use v4 for the shard/distribution key.
- Hash the UUID or use it directly as the partition discriminant.
- Monitor per-shard size to confirm an even split.
Use Cases
- Multi-tenant storage where tenants must not share a hot shard.
- Time-series ingestion fanned out across nodes.
- Kafka / queue partitioning by message key.
Code Examples
JavaScript
const id = crypto.randomUUID();Python
import uuid
id = uuid.uuid4()Frequently Asked Questions
Why use v4, not v7, for a shard key?
v7's timestamp makes consecutive IDs land on nearby partitions, creating hotspots. v4's randomness spreads load evenly.
Can I shard by a v7 primary key?
You can, but expect recent rows to concentrate on one shard. Keep a separate v4 distribution key if write spread matters.
Related tools
UUID v1 GeneratorUUID v3 GeneratorUUID v4 GeneratorUUID v5 GeneratorUUID v6 GeneratorUUID v7 GeneratorUUID v8 GeneratorBulk UUID GeneratorShort UUID GeneratorUUID ValidatorUUID FormatterUUID as a Primary KeyUUID Database IDUUID Foreign KeyUUID Shard KeyUUID Partition KeyUUID in a Composite KeyUUID Surrogate KeyUUID API KeyUUID Session TokenUUID Access TokenUUID Refresh TokenUUID Idempotency KeyUUID Request IDUUID Correlation IDUUID Trace IDUUID CSRF TokenUUID NonceUUID FilenameUUID Object KeyUUID S3 KeyUUID Upload IDUUID Cache KeyUUID Blob NameUUID Temp FileUUID User IDUUID Account IDUUID Customer IDUUID Device IDUUID Tenant IDUUID Client IDUUID Anonymous IDUUID Member IDUUID Message IDUUID Event IDUUID Job IDUUID Task IDUUID Queue Message IDUUID Transaction IDUUID Order IDUUID Invoice IDUUID Payment IDUUID Reset TokenUUID Verification TokenUUID Invite CodeUUID API SecretUUID Share LinkUUID Magic LinkUUID Node IDUUID Worker IDUUID Lock IDUUID Cluster IDUUID Test DataUUID Seed DataUUID FixtureUUID Mock IDUUID Placeholder IDUUID Sample ID