Bird
Raised Fist0
DynamoDBquery~10 mins

Item size limits and considerations in DynamoDB - Step-by-Step Execution

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Concept Flow - Item size limits and considerations
Start: Create/Update Item
Calculate Item Size
Is size <= 400 KB?
NoReject Item: Too Large
Yes
Store Item in Table
Item Stored Successfully
When adding or updating an item, DynamoDB calculates its size. If the size is more than 400 KB, the item is rejected. Otherwise, it is stored successfully.
Execution Sample
DynamoDB
PutItem {"id": "123", "data": "...large string..."}
Calculate size of item
If size > 400 KB reject
Else store item
This simulates adding an item and checking if its size is within the 400 KB limit before storing.
Execution Table
StepActionItem Size (KB)ConditionResult
1Receive item with id and dataN/AN/AProceed to size calculation
2Calculate item size350350 <= 400?Yes, proceed to store
3Store item in table350N/AItem stored successfully
4Receive item with id and dataN/AN/AProceed to size calculation
5Calculate item size450450 <= 400?No, reject item
6Reject item450N/AItem rejected due to size limit
💡 Execution stops when item size exceeds 400 KB and item is rejected.
Variable Tracker
VariableStartAfter Step 2After Step 3 or 6
item_size_kbN/A350350 (stored)
item_size_kbN/A450450 (rejected)
Key Moments - 2 Insights
Why is the item rejected even though it has valid data?
Because the item size exceeds 400 KB as shown in execution_table row 5, DynamoDB rejects it to enforce the size limit.
Does DynamoDB count only attribute values for size or the whole item?
DynamoDB counts the entire item size including attribute names and values, as implied in step 2 where total item size is calculated.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the item size at step 2 for the first item?
A400 KB
B350 KB
C450 KB
DN/A
💡 Hint
Check the 'Item Size (KB)' column at step 2 in the execution_table.
At which step does the item get rejected due to size?
AStep 6
BStep 5
CStep 3
DStep 2
💡 Hint
Look for the row where the result says 'Item rejected due to size limit' in execution_table.
If the item size was exactly 400 KB, what would happen according to the flow?
AItem would be rejected
BItem size is recalculated
CItem would be stored
DItem is partially stored
💡 Hint
Refer to the condition 'Is size <= 400 KB?' in concept_flow and execution_table step 2.
Concept Snapshot
DynamoDB items must be 400 KB or less in size.
Item size includes attribute names and values.
If item size > 400 KB, DynamoDB rejects the item.
Check item size before storing to avoid errors.
This limit applies to each individual item stored.
Full Transcript
When you add or update an item in DynamoDB, it calculates the total size of that item including all attribute names and values. If the size is more than 400 KB, DynamoDB will reject the item and not store it. If the size is 400 KB or less, the item is stored successfully. This ensures that items do not exceed the maximum allowed size. For example, if an item has a size of 350 KB, it will be stored. But if it has 450 KB, it will be rejected. Always check your item size before storing to avoid errors.

Practice

(1/5)
1. What is the maximum size allowed for a single item in DynamoDB, including attribute names and values?
easy
A. 400 KB
B. 1 MB
C. 100 KB
D. 10 MB

Solution

  1. Step 1: Understand DynamoDB item size limit

    DynamoDB limits each item to a maximum size of 400 KB, which includes both attribute names and values.
  2. Step 2: Compare options with the known limit

    Among the options, only 400 KB matches the official DynamoDB item size limit.
  3. Final Answer:

    400 KB -> Option A
  4. Quick Check:

    Item size limit = 400 KB [OK]
Hint: Remember DynamoDB item max size is 400 KB total [OK]
Common Mistakes:
  • Confusing item size with partition size
  • Thinking 1 MB is allowed per item
  • Ignoring attribute names in size calculation
2. Which of the following is the correct way to store a large file in DynamoDB considering item size limits?
easy
A. Store the entire file as a single attribute in one item
B. Split the file into chunks and store each chunk in separate items
C. Store the file outside DynamoDB and save only a reference in the item
D. Compress the file and store it in a single attribute without splitting

Solution

  1. Step 1: Consider item size limits for large files

    Since DynamoDB items have a 400 KB size limit, storing large files directly is not practical.
  2. Step 2: Evaluate storage options

    Storing large files outside DynamoDB (like in S3) and saving a reference inside DynamoDB is the recommended approach to handle large data efficiently.
  3. Final Answer:

    Store the file outside DynamoDB and save only a reference in the item -> Option C
  4. Quick Check:

    Large files stored externally with references = C [OK]
Hint: Use external storage for large files, keep references in DynamoDB [OK]
Common Mistakes:
  • Trying to store large files directly in one item
  • Splitting files into many items without external storage
  • Ignoring size limits and compressing without splitting
3. Given a DynamoDB item with attributes: {"id": "123", "name": "Alice", "bio": "A" repeated 300000 times}, what will happen when you try to insert this item?
medium
A. The operation will fail due to item size exceeding 400 KB
B. The item will be inserted successfully
C. Only the "id" and "name" attributes will be stored
D. The "bio" attribute will be truncated automatically

Solution

  1. Step 1: Calculate approximate item size

    The "bio" attribute contains 300,000 characters. Each character is roughly 1 byte, so bio alone is about 300 KB. Adding attribute names and other attributes likely exceeds 400 KB.
  2. Step 2: Understand DynamoDB behavior on size limit breach

    DynamoDB rejects items that exceed the 400 KB limit; it does not truncate or partially store attributes.
  3. Final Answer:

    The operation will fail due to item size exceeding 400 KB -> Option A
  4. Quick Check:

    Item size > 400 KB causes failure = B [OK]
Hint: Check total size; over 400 KB items fail insert [OK]
Common Mistakes:
  • Assuming DynamoDB truncates large attributes
  • Thinking partial attributes are stored
  • Ignoring attribute name size in total
4. You wrote code to insert an item with a large attribute but get a validation error. What is the most likely cause?
medium
A. The network connection timed out
B. The attribute name contains invalid characters
C. The table does not have a primary key defined
D. The item size exceeds DynamoDB's 400 KB limit

Solution

  1. Step 1: Identify common causes of validation errors

    Validation errors often occur when the item violates DynamoDB constraints, such as size limits.
  2. Step 2: Match error cause with large attribute insertion

    Inserting a large attribute likely caused the item size to exceed 400 KB, triggering the validation error.
  3. Final Answer:

    The item size exceeds DynamoDB's 400 KB limit -> Option D
  4. Quick Check:

    Validation error from size limit breach = A [OK]
Hint: Validation errors often mean item too large [OK]
Common Mistakes:
  • Assuming network or key errors cause validation error
  • Ignoring item size in error diagnosis
  • Not checking attribute name rules
5. You need to store user profiles with a photo and detailed bio in DynamoDB. The photo is 1 MB and the bio is 300 KB. How should you design your data to respect DynamoDB item size limits?
hard
A. Store the photo and bio together in one item, compressing both to fit under 400 KB
B. Store the photo in Amazon S3 and save the S3 URL and bio in DynamoDB item
C. Split the photo into multiple items and store the bio in a separate item
D. Store only the photo in DynamoDB and omit the bio

Solution

  1. Step 1: Analyze size constraints for photo and bio

    The photo is 1 MB, which exceeds DynamoDB's 400 KB item limit. The bio is 300 KB, close to the limit alone.
  2. Step 2: Choose a design respecting limits and best practices

    Storing large files like photos in Amazon S3 and saving only the reference (URL) along with the bio in DynamoDB is the recommended approach.
  3. Final Answer:

    Store the photo in Amazon S3 and save the S3 URL and bio in DynamoDB item -> Option B
  4. Quick Check:

    Large files in S3, references in DynamoDB = A [OK]
Hint: Put big files in S3, keep metadata in DynamoDB [OK]
Common Mistakes:
  • Trying to compress large files to fit in one item
  • Splitting large files into multiple items unnecessarily
  • Omitting important data like bio