How to design a Real-Time ranking system

Source: Internet
Author: User
Now we are going to make a game product that involves scoring rankings. Simple ranking can be done with redis sortset. But how should we design dynamic ranking? For example, the monthly ranking is actually the ranking from the current time to the past 30 days, because time is time changing, so the time dimension... now I want to build a game product that involves scoring rankings,
Simple ranking can be completed using redis's sort set,
But how should we design dynamic rankings?
For example, the monthly ranking is actually the ranking from the current time to the past 30 days,
Because time is time changing, the time dimension changes every second.
Answer the question from lan Hao.
It is a game. It generally takes 10-40 seconds to play a game,
When the game is finished, there will be a score,
Now, monthly ranking is required (from now till 30*24*3600 seconds ago ),
If a person plays for multiple times, the best score is used for statistics.

Reply content:

Now I want to build a game product that involves scoring rankings,
Simple ranking can be completed using redis's sort set,
But how should we design dynamic rankings?
For example, the monthly ranking is actually the ranking from the current time to the past 30 days,
Because time is time changing, the time dimension changes every second.
Answer the question from lan Hao.
It is a game. It generally takes 10-40 seconds to play a game,
When the game is finished, there will be a score,
Now, monthly ranking is required (from now till 30*24*3600 seconds ago ),
If a person plays for multiple times, the best score is used for statistics.

Let me help you.

Also usedZSETFor example, adding points to a user's victory:

Zincrby day: 20150113 60 KavlezZINCRBY DAY: 20150113 80 dance qianxun

Like this, it is a ZSET every day.
However, if you count up to 30 days, it will always be 30.DELOne.

Update ZSET every day (or several minutes) for the last 30 days:

ZUNIONSTORE LAST30 2 LAST30 DAY:20150113

Top 10:

ZREVRANGE LAST30 0 10 WITHSCORES

Try it.socket.ioThis is to maintain a persistent connection. With a persistent connection, everything can be done 〜

Suitable for mongodb

Each score is counted as a record (document), added with a timestamp, saved
Aggregate takes care of the Score list

Since it is a real-time list, you can update it in real time.ZSETOfSCOREYou can.

As for your ranking over the last 30 days, I think you are talking about the ranking over the last 30 days of point growth.

Product logic referencesegmentfault"List", The implementation method is to useZSETRecord the growth of user points every day, so that weekly, monthly, quarterly, and annual lists can be usedZUNIONSTORE.

I have made several game rankings and explained my ideas.

Rankings are divided by Time:

  1. Historical ranking. The so-called historical ranking indicates that the Score data has been solidified and the data cannot be changed again. For example, monthly or weekly ranking.
  2. Real-time ranking. The latest ranking of data is still changing.

Players generally have two concerns:

  1. Data of the First N names, for example, data of the first 100.
  2. Your ranking and the number of players with the top N or bottom ranking.

Based on the 2.1 above, the ranking data will be divided into two parts:

  1. The first N data is stored in a single table. The data in this table is small, frequently updated, and the data is very real-time.
  2. Converts a score to a stage, for example, 10 points for a stage. Record the number of people in each stage and the first N people in each stage.

I don't know.

Try it.MeteorFramework is based onnodejsAndmongodbOfWebAppFramework, throughDDPProtocol to process real-time communication. Real-Time Code Update. After the server code is updated, the client does not need user intervention. In addition, there is a delayed synchronization mechanism. The user submits real-time data feedback on the screen. If the data submission fails due to network reasons, the data will be uploaded after the network reconnects.
Meteor Official Website

What about density? First, we need to clarify your ranking.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.