Skip to content
Menu
Portfolio
  • Artificial Intelligence
  • Personal Projects
  • Assignments
  • Algorithms
  • Notes
  • Home
Portfolio

TechPi Forum

Posted on July 12, 2025July 14, 2025

User activity ranking system

In TechPi, a user activity leaderboard is provided. While a blog community would usually rank authors, we chose to highlight user activity to encourage greater participation. We provide daily and monthly leaderboard variants.

User activity score calculation rules:

  • Visiting a new page: +1 point
  • Liking or bookmarking an article: +2 points
    Canceling a like/bookmark: −2 points
  • Commenting on an article: +3 points
  • Publishing an approved article: +10 points

Design

The leaderboard business logic is relatively straightforward, making data structure design simple as well.

Data model for a leaderboard entry:

long userId; // user identifier
long rank;   // user's rank in the leaderboard
long score;  // user's accumulated activity score

Initial data structure consideration:
A LinkedList was considered since rankings are continuous and changes in position don’t require costly array copying. However, it has several downsides:

Problems with LinkedList

  1. Retrieving a user’s rank is inefficient (O(n))—random access is slow.
  2. Concurrency issues arise when multiple users update scores simultaneously.

Rather than building a custom structure from scratch, Redis provides an elegant and efficient solution using its ZSet (sorted set).

Redis-Based Approach

Redis’s ZSet (Sorted Set) is perfect for this use case:

  • Ensures uniqueness of elements (users)
  • Each element (user) has a score (activity)
  • Maintains elements sorted by score

By using ZSet, we store user scores directly, and Redis handles the ranking automatically.

Leaderboard Implementation

    Pages: 1 2 3 4 5

    CATEGORIES

    • Artificial Intelligence
    • Personal Projects
    • Notes
    • Algorithms

    • University of Maryland
    • CMSC426 - Computer Vision
    • CMSC320 - Introduction to Data Science
    • CMSC330 - Organization of Programming Languages
    • CMSC216 - Introduction to Computer Systems
    ©2025 Portfolio | WordPress Theme by Superbthemes.com