dynobase-icon
Dynobase

Question: Can I use a UUID as a DynamoDB partition key?

Rafal Wilinski

Answered by Rafal Wilinski

Last updated: October 23rd, 2026

Answer

Yes. A UUID makes a good partition key. Random UUIDs provide many distinct partition key values, helping distribute items. They do not prevent a hot item if many requests target the same UUID. Store it as a String, or as 16 bytes of Binary if you want smaller items and keys.

What to plan for:

  • You can only look items up by exact ID. With a UUID as the whole primary key, GetItem by ID is the only efficient read. You can't list, range-query or sort by a random value, so add a global secondary index for each other access pattern, such as "orders by customer".
  • The partition key doesn't have to be unique. It must be unique only when it's the entire primary key. With a composite key, many items can share one UUID partition key and differ by sort key, for example all line items of one order.
  • Time-ordered IDs sort; random ones don't. UUID v4 is fully random. UUID v7, ULID and KSUID start with a timestamp, so they sort by creation time, which makes them useful as sort keys. As partition keys they still distribute well, because DynamoDB hashes the partition key value.

DynamoDB doesn't generate IDs, so create them in your code:

import { randomUUID } from "node:crypto"; import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient, PutCommand } from "@aws-sdk/lib-dynamodb"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); await ddb.send( new PutCommand({ TableName: "Orders", Item: { orderId: randomUUID(), total: 42 }, ConditionExpression: "attribute_not_exists(orderId)", }) );

The condition makes the write fail, instead of silently replacing an item, if the ID somehow already exists. The DynamoDB UUID generator creates v4, v7, ULID and KSUID values and shows which of them sort by time.

Source: AWS DynamoDB documentation.

Dynobase is a Professional GUI Client for DynamoDB

Start your 7-day free trial today

Product Features

Download
/
Pricing
/
Member Portal
/
Privacy
/
EULA
/
Twitter
© 2026 Dynobase
+
Still using AWS DynamoDB Console?
Try Dynobase to accelerate your DynamoDB workflow. Start your 7-day free trial today.