Reputation: 915
I am using DynamoDB for storage. I need to store a Java object in one attribute within a table. I see two approaches:
What are the pros and cons of each (In terms of item size, flexibility in Dynamo DB queries)?
Upvotes: 33
Views: 55799
Reputation: 15
DynamoDB provides more query flexibility. First of all you can specify query expressions that will use fields in you maps/lists. Second you will be able to project attributes from DynamoDB data structures
Upvotes: 0
Reputation: 8285
First approach
The benefit here is that you can store arbitrary data and should not care if DynamoDB supports it. You don't even need to care if this is a valid JSON. If you are storing DynamoDB List/Maps all attributes should be of types that DynamoDB supports.
You can push this approach even further and use compression and your item will occupy less space and save you some RCUs/WCUs in the process.
The first drawback is that it is harder to work with code like this. Simply because you need to convert data back and forth and this will make your code and operations more complicated.
The second drawback, DynamoDB won't know anything about your data and won't be able to access it. For example you will not be able to use document paths feature.
Second approach
I think this is a preferred approach unless you have a good reason to stick to the first one (e.g. unusual data or size constraints).
The benefit here is that it is easier to work with, you can access all DynamoDB features and if you are using DynamoDBMapper it is really easy to implement.
Upvotes: 40