I am relatively new to DynamoDB, and we are designing a free-form search GUI for one of our application. The primary data store we are using is traditional relational database, we are planning to use DynamoDB as a persistent "cache" layer on top of database for search only.
In our case, we have 3 keys to determine a customer .
we store the customer as combination of above 3 ids as follow:
- billingAccountNumber + customerId
- billingAccountNumber + InstanceId
- customerId
- InstanceId
Each Item in DynamoDB represents a event happens to customer at certain time.
what's the best way to design this pattern in DynamoDB. The query will something like
- events for certain billingAccountNumber for period of time.
- events for certain customerId for period of time
- events for certain instanceId for period of time.
etc.
Currently, I am using BillingAccountNumber as the partition key, since this will evenly distribute the load, and timestamp as the sort key, so that we can get result for a given range.
I am debating on if I can use customerId or instanceId as the sort key, and timestamp as a filter, so that i can do a query with filterExpression on the timestamp.
which way is more efficient in terms of the performance and cost?