Currently I am moving data from Cassandra database to amazon dynamoDB. When I was going through concepts of dynamoDB implemnetation I have some questions regarding counters update in dynamoDB.
Question 1 :
In Cassandra usually, we use store_id, store_id+date,campaign_id,campaign_id+date combinations to update the counter.
In amazon dynamoDB we have HASHKEY and RANGEKEY. We can use only HASHKEY or HASHKEY with RANGEKEY. Here I have two options.
Option 1 :
Placing store_id/campaign_id on HASHKEY and date on RANGEKEY.
Option 2 :
Like Cassandra structure, Can I use store_id, store_id+date, campaign_id, campaign_id+date as HASHKEY (No Range key).
Which option is good for best practises?
When we read the values from dynamoDB I need total counter values of store_id and campaign_id and range given by the user.
Question 2 :
I want to calculate number of campaign loads for particular store. We will load the campaign when user visits the store. For example, if "alpha" user visits the store and we showed the campaign then increment campaign load counter.
I need to calculate campaign loads based on user given time period. In Cassandra, I have implemented in following structure.
campaign_id - loads - 10 (10 users have seen this campaign)
campaign_id + 20160403 - loads - 4 (4 users have seen this campaign on this data)
How can I implement the same concept in Amazon dynamoDB.
I have noticed that using dynamoDB we can't able to use batch update to update attributes(Counter) in multiple items (Keys). In this case we will have more number of writes than Cassandra.
Example:
campaign_load counter :
Using hector api we can update campaign_load counter at a time using following combinations. store_id, store_id + datekey, campaign_id, campaign_id + datekey.
(4 keys with one write ) - I am using hector API for connecting with Cassandra Node.
But in amazon dynamoDB we need to make 4 writes. Each attribute in the item update separately. (4 keys with 4 writes)
Writebatch concept not useful here. Becuase it will override the existing items and not update the counters.
If counters are increasing the number of writes also increases.
In my application I am using more counters. Can any suggest about hwo to update the counters?