New from O’Reilly: The memory architecture behind adaptive AI agents

Read the report
For developersHow to build a Real-Time Leaderboard app Using Redis
Ajeet Raina
Ajeet Raina

The concept of a leaderboard—a scoreboard showing the ranked names and current scores (or other data points) of the leading competitors—is essential to the world of computer gaming, but leaderboards are now about more than just games. They are about gamification, a broader implementation that can include any group of people with a common goal (coworkers, students, sales groups, fitness groups, volunteers, and so on).

Leaderboards can encourage healthy competition in a group by openly displaying the current ranking of each group member. They also provide a clear way to view the ongoing achievements of the entire team as members move towards a goal. Gamification of tasks and goals via leaderboards is a great way to motivate people by providing them with constant feedback of where they rank in comparison to other group members. Done well, this can lead to healthy competition that builds group cohesion.

Image

Step 1. Install the below software

Step 2. Clone the repository

Step 3. Run docker compose

Step 4. Verifying if containers are up and running

Step 5. Copy .env.example to create .env

Provide the values for environment variables (if needed)

If you're using Redis Cloud, you must supply DB endpoint, password, port and the name of the database. In case of local system, the entries look like as shown below:

Step 6. Run the backend

  • Install gradle

Follow the following link https://gradle.org/install/ for your MacOS

  • Install JDK

Follow the following link https://docs.oracle.com/javase/10/install/installation-jdk-and-jre-macos.htm for your MacOS

Step 7. Run the wrapper task

To use Wrapper, we need to generate some particular files. We'll generate these files using the built-in Gradle task called wrapper. Note that we need to generate these files only once.

Now, let's run the wrapper task in our project directory:

It should show the below results:

Step 8. Perform the build task

The Gradle Wrapper is now available for building your project. It's time to run the wrapper script to perform the build task.

Step 9. Run your application

Step 10. Access the leaderboard application

Image

How it works?

How the data is stored:

The AAPL's details - market cap of 2.6 triillions and USA origin - are stored in a hash like below:

The Ranks of AAPL of 2.6 trillions are stored in a ZSET.

How the data is accessed:

Top 10 companies:

All companies:

Bottom 10 companies:

Between rank 10 and 15:

Show ranks of AAPL, FB and TSLA:

Adding 1 billion to market cap of FB company:

Reducing 1 billion of market cap of FB company:

Companies between 500 billion and 1 trillion:

Companies over a Trillion:

References