Collect user purchase history
Page Views Tracking
Click Tracking
Like or dislike for each product
Tracking products user click like and dislike
Track search history
Track user wishlist
Compare other users has purchased and like most common products. Recommend their other purchases to each other.
Scalability: plenty of data of user activities increasing in each user everyday. Database management should be scalable.
Maintainable: Multiple tables mapping are complex. Data table Sharding and decoupling must be important to data engineers narrow down the scope.
Supporting func:
purchased[] getPurchaseHistory(userId)
void addClickedItem(userId, itemId)
itemId[] getClickedItems(userId)
void addLikeOrDislike(userId, itemId, attitude)
Map
void addSearchHistory(userId, keyword)
itemId[] getSearchHistory(userId)
void addWishList(userId)
wishlist[] getWishList(userId)
userId[] getTopKUserPurchasedMostCommonItem(userId)
ItemId[] getTopKPurchasedItemsByTopKCommonUsers(userId:[])
RESTful API
// Combine all these API above in this API and ranking the different algorithm's by weight
GET /getRecommendations(userId, topK)
return itemId[]
// add new user activity in log, action is for action type eg: search, clicked, like/dislike, etc, keyword use for search action, attitude for like/dislike
POST /logUserActivity(userId, action, itemId, keyword, attitude)
// get user activity profiles
GET /userActivityProfile(userId)
Here are tables: the key end with "At" means the timestamp action took
Purchased:
[userId, itemId, purchasedAt]
Attitude:
[userId, itemId, attitude, createdAt]
Clicked:
[userId, itemId, clickedAt]
Search:
[userId, keyword, searchAt]
WishList:
[userId, itemId, wishAt]
Recommendation //list all recommended items for each user
[userId, itemId:[], confidence]
*Please check my Sequence diagram!
RecommendationService: Here are some strategies we use: All these return should be stored in data structure temporily.(eg: HashMaps and Graphs)
itemId, name, category, featuresList
0001,Burberry shirt, men clothes, [Burberry, men shirt]
Then search in ActivityHistoryDatabase for the items which have the most same features products items and return
We use the weight of similar products other user purchased return> Get purchased return > Get wishlist return > get liked return > get search history return. Sort the final recommendation lists by this weight order then return top K.
Message queue: Apache Kafka since we can choose different topic to consumer by partitions.
ActivityHistoryDatabase: It's a write heavy database, read by RecommendationServices(we can use WebSocket connection to client and UserActivityService, if activity is not search we need real time recommendation, if activity is search, we better to trigger recommendationService once an hour, which means RecommendationService won't read ActivityHistoryDatabase frequently if activity is search, (mostly they're search) ) So As a write Heavy Database, we need low latency and high availability but not high requirement on consistence because we don't RecommendationService might not read ActivityHistoryDatabase immediately. Apache Cassandra is a good choice.
RecommendationDatabase: RecommendationService triggered write in read-time if activity is not search. if it's search we don't update RecommendationDatabase immediately. So it's a little read heavy Database. MongoDB can be a good choice.
LoadBalancer: ngnix is good. Since UserActivityService might be stateful service, level 7 ngnix might be required. We also might user ZooKeeper to manage server nodes topology.
Try to discuss as many failure scenarios/bottlenecks as possible.
Add WebSocket Connector between UserActivityService and Load balancer to trigger read time update
Add Zookeeper for managing server nodes topology.
Add monitoring and alert system to track user activity distribution