Reputation: 15760
Folks, How would you model the following data in Apache Cassandra?
Customers (customerID), can purchase many items (itemID) and hold them in their shopping cart. Also a timestamp should be kept to keep track of when things were placed in the shopping cart.
Requirements:
Fetch a specific customerID's shopping cart.
Fetch customers that currently have itemID
in their cart.
Knee jerk thought would be having 2 tables. One would map customerId to an array of itemIDs. Not sure how to fill the second requirement.
Question is specific to Cassandra, and maybe Dynamo. Please no relations db suggestions.
Upvotes: 0
Views: 83
Reputation: 9475
For Cassandra it sounds like two tables to me. One partitioned by customerID with itemID as a clustering column and timestamp as a non-key field. The second table would be partitioned by itemID with customerID as a clustering column.
If you can wait for Cassandra 3.0, then the second table could be defined as a materialized view of the first table. Then Cassandra would take care of updating the second table automatically. Otherwise you'll have to keep both tables consistent in your application.
Upvotes: 1