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?

已提問 2 年前檢視次數 214 次
1 個回答
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
已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南