Search code examples
amazon-dynamodbdynamodb-queries

cost efficiently use the DynamoDB in cases of Duplicate partition keys


How to cost efficiently use the DynamoDB in cases of Duplicate partition keys ?

In our scenario, This is how our data looks Customer ID - partition Key UUID - Sort Key State etc.

and we have lot of events for the given customer id. Example events:

  1. Before Rent
  2. Request for Rent
  3. Accept Rent
  4. Negotiate Rent
  5. Rent modification etc.

etc. we have 32 such events per Customer ID.

Also, the same customer can come again and we will have same set of records. (Pattern same customer would visit again in 2 months) **

  • Issue facing:

** Using ondemand Dynamo Db provisoning . More reads which thereby increases cost.

  • Lots of read queries happening on demand for each customer about the customer before inserting next event -

We are assuming the pattern creates, hot keys (skew) there by increassing the cost.

Our requirement also need us to Query based on Customer ID - so we understand the events of the customer.

Is the current data model the right one ?


Solution

  • We are assuming the pattern creates, hot keys (skew) there by increassing the cost.

    You are not creating a hot key, 32 events per customer would not be enough to cause a hot key unless your items are 32kb and all events are writes that occur in the same second.

    As for cost, data skew (which you don't have) does not increase costs.

    Your model looks correct to me, if you would like to reduce cost I suggest using provisioned capacity mode instead of OnDemand.