enitihas
enitihas

Reputation: 915

Storing JSON as string in DynamoDB vs List/Map types

I am using DynamoDB for storage. I need to store a Java object in one attribute within a table. I see two approaches:

  1. One to convert the object to JSON using Jackson on the client side, and then store the JSON string in the attribute.
  2. Another way is to use DynamoDB List/Map types to store my object.

What are the pros and cons of each (In terms of item size, flexibility in Dynamo DB queries)?

Upvotes: 33

Views: 55799

Answers (2)

Junaid Rahman
Junaid Rahman

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

Ivan Mushketyk
Ivan Mushketyk

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

Related Questions