Skip to content
Tutorials Center
My learning

Topics

Lesson 9 of 37 ยท Data Model and Keys

Item Size and Service Limits

Learn how DynamoDB measures item size, the 400 KB item limit, key and attribute name rules, request limits, and patterns for storing data that does not fit.

DynamoDB is generous but not unlimited. A handful of limits shape how you design items: the maximum item size, the size of keys, how deep you can nest, and how many items one request can carry. Hitting one in production usually means a redesign, so learn them while the design is still on paper. This lesson also shows how size is measured, because it affects both limits and cost.

Limits change over time and some can be raised through AWS Support. The numbers below are the defaults at the time of writing. Always check the current "Service, account and table quotas" page of the AWS documentation before depending on an exact value.

Item size: 400 KB

An item can be at most 400 KB, counting both attribute names and attribute values. Long attribute names are therefore not free: if every item stores customerShippingAddressLine1, you pay those bytes in every item, and in every read and write.

How size is counted, roughly:

Content Size
String Length in UTF-8 bytes
Binary Length in bytes
Number Up to about 21 bytes, depending on the digits
Boolean, null 1 byte
List or map 3 bytes of overhead, plus 1 byte per element, plus the sizes of contents
Attribute name Length in UTF-8 bytes

You do not need to compute this by hand, but you should know that it is the stored size of the whole item that counts, including every index projection copy.

Key limits

  • Partition key value: 1 to 2,048 bytes.
  • Sort key value: 1 to 1,024 bytes.
  • Attribute name: up to 64 KB for ordinary attributes, but only 255 bytes for names used as key or index attributes.
  • Key and index attribute types: string, number or binary only.

Nesting and expressions

  • Lists and maps may nest to 32 levels.
  • An expression (condition, filter, update, projection) can be at most 4 KB, with limits on the number of operands and functions.
  • You cannot use reserved words (Name, Status, Date, Size, and many more) directly in expressions. You alias them with #name placeholders, covered in the lesson on conditional expressions.

Request and result limits

Item Limit
Query and Scan page size 1 MB of data read per call (before filters), then pagination
BatchGetItem 100 items or 16 MB per call
BatchWriteItem 25 put/delete requests or 16 MB per call
TransactWriteItems and TransactGetItems 100 items per call
Local secondary indexes 5 per table
Global secondary indexes 20 per table by default
Item collection with a local secondary index 10 GB

The 1 MB page size is the one most people meet first: a query that matches 5 MB of items returns the first megabyte and a LastEvaluatedKey, and your code has to ask again. Pagination is covered later in this chapter.

Calculating item size in practice

A rough size estimate is useful for capacity planning, because read and write costs depend on item size, rounded up to 4 KB for reads and 1 KB for writes. This stand-in approximates sizes using the rules above, on plain Python values.

Python Stand-in: estimate an item's size in bytes

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The first two items carry the same data, and the second is larger purely because of attribute names. The third shows how an unbounded list outgrows the limit, which is the classic way people hit 400 KB.

Capacity units depend on size

Capacity is charged in units rounded up by size, so size has a direct price. This model computes the units for an item.

Python Stand-in: read and write units by item size

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A 1,500-byte item costs 2 write units, not 1.5. Trimming items just under a boundary (1 KB for writes, 4 KB for reads) can cut cost noticeably at scale.

What to do when data does not fit

  • Large blobs (images, documents, JSON over a few KB): store the object in Amazon S3 and keep its key, size and checksum in the item.
  • Unbounded lists (comments, events, log lines): make each element its own item under the same partition key, so you read them with Query and paginate.
  • Wide items read in part: split the rarely used attributes into a second item with a different sort key, so common reads stay small.
  • Long attribute names: use short names (ts, qty) in the stored item and map them to readable names in your code.
  • Large text: compress with gzip and store as binary if reading it is infrequent.
Python Stand-in: move a growing list into separate items

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is counted toward the 400 KB item size limit?

    Both names and values count, so very long attribute names add up across millions of items.
  2. 2. How much data does a single Query or Scan call read before it paginates?

    Each call evaluates at most 1 MB of data, then returns LastEvaluatedKey so you can continue.
  3. 3. What is the best way to store an unbounded list of comments for a post?

    A growing list will hit 400 KB and makes every read and write bigger. Separate items can be queried and paginated.
  4. 4. A 1,500-byte item is written. How many write capacity units does it consume?

    Write units are charged per 1 KB, rounded up, so 1,500 bytes costs 2 units.

Summary

  • Items are limited to 400 KB, counting attribute names and values; keys have their own byte limits.
  • Query and Scan read at most 1 MB per call; batch and transaction calls cap at 25 to 100 items.
  • Item size, rounded up to 1 KB for writes and 4 KB for reads, determines cost.
  • Keep attribute names short and move large or unbounded data into S3 or separate items.
  • Check the current quota page before relying on exact numbers.

Next: PutItem and GetItem