Q: Are the top seller broken down by entire web or category?
A: It should broken down by category, even sub category
Q: How often do the system need to update the top-seller?
A: If you are a customer, how will you think about it?
Q: Maybe... one times a day is enough, but when some activity open, I want to see it upadte few times per day.
Q: And, how to define the top seller? Is the time period two week enough?
A: do you think it is enougth? Is it a general sense?
Q: Well, we can set a threshold, let the sell amout touch this amout.
Q: How about the scale?
A: we want to set it in every category and main page, well we are taliking about 1k qps here.
User well see these result many times, and it is not always updated. So we can use cache service to store the result.
user - > cache -> database
We don't want to effect the online system, when we compute the top seller, so the database of order need to copy by online system and because is not related to transaction, we can use noSql DB to do it
user -> cahce ->database(nosql)
And we need a queue service or a task management service is better to management our cron job.
user > cache <- task management servie <-database (nosql)
then talk about the alg of top seller,
we can let the amount that bought recent mounth have the weight 1
and every past two mounth have the weight 2^-n times
example
last mounth sell 10 book
previous two month ago sell 10 book
the scroe is 10 * 1 + 10 * 2^-1 = 15
we can talk about alg first,we wamt to surface new trends quickly.
e^-at
a is the decay that is a constant in system
t is the time
we need to divid it with our system
we can divide it by category on s3 or other place to do it
we can use apache spark as our job to do it
spark can help us categoty each data.
puchases database -> apache spark -> database
And use cahce can helper user to read it well
puchases database -> apache spark -> database ->redis
題外話... 當週末有些個人事務要處理時
想到今天份的課程還沒看 題目還沒寫
實在令人喪志...
算了 QQ 還剩一兩個禮拜 應該下週就要跟HR來確認on site時間了
就努力能撐多少撐多少吧~
Q: https://leetcode.com/problems/rotate-array/description/
class Solution {
public void rotate(int[] nums, int k) {
k = k % nums.length;
int count = 0;
for (int start = 0; count < nums.length; start++) {
int current = start;
int prev = nums[start];
do {
int next = (current + k) % nums.length;
int temp = nums[next];
nums[next] = prev;
prev = temp;
current = next;
count++;
} while (start != current);
}
}
}