I have a news site with many topics. There may be millions of users following topics. I support sorting for each user to download news related to the ones they follow. When the article is added or updated, I will write this article in the list of user users. In particular, the pseudo-code is as follows:
if a article is added/updated
get all topics that the article belong (each article may belong to many topics)
for each topic: get all topic followers
update_user_news_list(userId, articleId)
This is java code with jedis:
static final int LIMIT_BATCH = 1000;
static void addToUserHomeFeed(int index, Jedis jd) {
int range_limit = index + LIMIT_BATCH - 1;
Set<String> list = jd.zrange("Follower:Topic:Id", index, range_limit);
if (list.isEmpty()) return;
Iterator<String> it = list.iterator();
while (it.hasNext()) {
}
addToUserHomeFeed(range_limit + 1, jd);
}
The problem is that there are currently about 1 million users on my site, some popular topics followed by about 800,000 users, and sometimes the system generates buffer overflow errors. Am I doing something wrong or are there better approaches? I am using redis 2.4