DynamoDB Primary Key and Index Table Design

I am trying to wrap my head around how I should create a table in DynamoDB. I need a table Subscriptionthat stores the items for each subscription the company has. Therefore, I planned the following attributes.

  • SubscriptionId
  • Companyid
  • Startdate
  • Endate
  • Productid

I read a lot about how indexing works in DynamoDB with respect to secondary indexes, but I'm really struggling to figure it all out. It seems that the more I read, the more confused. I understand the basic concepts of global secondary indexes and local secondary indexes, as well as the hash key + range key. The problem is to put it all together and develop a table that supports my query requirements.

I currently have the following query requirements:

  • The ability to request active subscribers for this company. That is, a request CompanyIDand a comparison StartDateand EndDatea predetermined date
  • The same as above, except for the request, to find out if this company has an active subscription for a certain ProductID

In the future (or now) I would like to be able to request all active subscriptions for this ProductID. My initial plan was to use SubscriptionIDboth a hash key and CompanyIDas a range key for efficient requests for a given company subscription. However, I'm not sure if it is even possible to request a range key? I know that the combination of a hash key and a range key is unique (composite key), but is it always necessary to include a hash key when performing a search for a range key?

StartDate EndDate, , , , ( )? , , .

, , - / , / /. , . , - , , , , .

, , . , - . :, , ?

+4
1

, :

  • ,
  • ,
  • , (, Julian Day Number).

:

  • hash key: SubscriptionID
  • CompanyID: S, StartDate: N, EndDate: N, ProductID: S

:

  • ProductID-StartDate-Index: ProductID, StartDate
  • CompanyID-ProductID-index: hash on CompanyID, ProductID
  • CompanyID-StartDate-index: hash on CompanyID, StartDate

  • : CompanyID-StartDate-index, query CompanyID = :companyid, StartDate <= :date, EndDate >= :date

  • : CompanyID-ProductID-index, query CompanyID = :companyid, ProductID = :productid, StartDate <= :date, EndDate >= :date

  • : ProductID-StartDate-index, query ProductID = :productid, StartDate <= :date, EndDate >= :date

AWS DynamoDB. - , , .

enter image description here

+6

Source: https://habr.com/ru/post/1613489/


All Articles