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
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠