eric6685
eric6685

Reputation: 95

How to organize low cardinality data in DynamoDB

What is the best way to structure a table with low cardinality and high scale in DynamoDB? For example, suppose I have an application where a user can create posts and other users can view these posts. What should I use for partition key and sort key? I could have a PK of posts and SK of a Unix timestamp, which would allow me to query the most recent posts globally. Note that I want to view all posts and not just the posts for a specific user.

If I take this approach I would be consistently reading from the same partition, which could slow my performance and potentially hit the RCU or WCU limits for the partition.

Can this be mitigated with DAX?

Upvotes: 1

Views: 1097

Answers (1)

Seth Geoghegan
Seth Geoghegan

Reputation: 5747

One technique is write-sharding. This is when you store your data across partitions to make more efficient use of the database. For example, you may choose to divide posts into partitions based on the month the post was written. If you decided to store blog posts monthly, you could store all posts in November 2020 in a partition with key POSTS#2020-11-01.

AWS has documentation about write sharding that goes into greater depth.

You should check out the AWS DynamoDB Office Hours series on Twitch/Youtube. Rick Houlihan, a DynamoDB wizard, walks through all sorts of data modeling examples. In this episode, he modeled a Wordpress blog in DynamoDB. I've found walkthroughs like this to be extremely helpful.

Upvotes: 2

Related Questions