Home > Net >  How to store large arrays in DynamoDB
How to store large arrays in DynamoDB

Time:06-18

I am new to DynamoDB and I am curious what is the best way to store potentially large arrays.

I have a user object that looks like this:

UserId: String
Watching: Card[]
Listings: Card[]

I am aware there is a limit to the size of objects in Dynamo - I think 1MB? Therefore I think if a user had many listings it might go past this limit. What would be the best practice to store potential large arrays like this? Would it be to maybe store an array of CardIds and then do a second query to get cards from this? Any help would be great - thanks!

CodePudding user response:

The limit of an object in DynamoDB is 400 KB, see DynamoDB Quotas.

For larger attribute values AWS suggests compressing of the attribute in formats such as GZIP, and store it in binary in DynamoDB. Other option would be to store the item in JSON format in S3 and store the key of this file in DynamoDB.

See: Best Practices for Storing Large Items and Attributes

Probably, a third option would be to split your array somehow, and create multiple entries in DynamoDB. Or try to create separate tables for separate attributes, obviously this wont solve the issue if for example Listings array's size is larger than the object limit itself.

CodePudding user response:

The table in dynamoDB, every row in the table is object.

The item in a row view it in json object format.

The row cannot support json array.

Split into 2 table. Store listing in table A and another in table B. Design the primary key and sort key correctly so that it can identified the records belong to particular user.

  • Related