How to handle an access pattern in which you need to "list values of all partions with some`userid` pk"

0

In DynamoDB, how do you handle an access pattern in which you need to get a list of partition values?

For instance, say the partition-key is userid, and the attributes are firstname and lastname for the sake of simplicity (but in reality there is a lot more attributes). How do I then get a list of all the value pairs [(uiserid_1-firstname, uiserid_1-lastname), (uiserid_2-firstname, uiserid_2-lastname), ...]? Obviously, doing a scan or a query for each partition will consume too many read requests.

So far, I think the best option would be to create a composite key: The pk is a random number prefixed with, say, list-users- to use as a partition-key; The sk is the userid. Then, all the items in these partitions are going to be the value of the userid partition duplicated. (I hope this makes sense, if not I can create a visualisation to better convey the idea). Doing it this way, you only need to perform one query on that random numbered partition-key; hence much more efficient.

  • Is this the correct dynamodb-way of handling this access-pattern?
  • How would you handle this access pattern?
  • It's unclear exactly what you want to achieve. It's also not obvious yet why a scan is wrong. Perhaps you can clarify?

asked 2 years ago211 views
1 Answer
0

You're saying that doing a scan in your scenario will consume more RCUs than what you expect for reading the data you require. Is this due to a large item size, multiple sk per pk, or something else?

If this is due to your large item size, consider using indexes and projecting attributes carefully: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-indexes-general.html#bp-indexes-general-efficiency

If this is due to multiple items per pk, you could leverage a sparse index design pattern. https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-indexes-general-sparse-indexes.html

Hope this helps.

AWS
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions