Tables, Items & Keys

Partition keys, sort keys, and why choosing them is the most important design decision.

1 min read
  • Table: a collection of items, like notesnap-summaries.
  • Item: one record, like a row. Up to 400 KB.
  • Attribute: a field on an item. Items in the same table can have different attributes, so there's no fixed schema beyond the key.

The primary key

Every item needs a unique primary key, in one of two shapes:

  1. Partition key only, e.g. noteId. Simple lookups: "get note abc123".
  2. Partition key + sort key, e.g. userId + createdAt. Groups related items together and keeps them sorted: "get all of Sam's notes from this week, newest first".
userId (partition key)createdAt (sort key)summary
sam2026-11-17T09:00ZGrocery list for the week
sam2026-11-18T14:30ZNotes from team standup
ana2026-11-18T08:10ZFlight details for Friday
Tip

Choose a partition key with many distinct values that spread traffic evenly, such as user IDs or order IDs. A key like country with three values would crowd most traffic onto a few partitions.

Secondary indexes

Need to look items up by something other than the primary key? A Global Secondary Index (GSI) is a second copy of the data keyed differently, for example by email. DynamoDB keeps it in sync for you.

Key takeaways

  • Items are schemaless apart from the primary key, and each one can be up to 400 KB.
  • Primary key = partition key, optionally plus a sort key to group and order related items.
  • Use GSIs to look up data by other attributes.

Check your understanding

Pick an answer to see the explanation.

  1. 1. You want "all orders for a customer, newest first". Which key design fits?

  2. 2. What's the maximum size of a single DynamoDB item?