Skip to content

Add Redis caching for leaderboard API queries #964

@Anuoluwapo25

Description

@Anuoluwapo25

Summary

The leaderboard query aggregates token balances across all learners and is one of the most expensive database queries. Caching the result in Redis with a short TTL (60 s) would dramatically reduce DB load.

Proposed Approach

  1. On request, check Redis for a leaderboard:top100 key
  2. Cache hit → return cached JSON immediately
  3. Cache miss → run DB query, store result with 60 s TTL, return

Acceptance Criteria

  • Redis client configured in server/src/lib/
  • Cache-aside pattern applied to the leaderboard controller
  • Cache is invalidated (or TTL respected) when token balances change
  • REDIS_URL added to server/.env.example
  • Unit test mocks Redis and verifies cache hit/miss paths

Files

  • server/src/controllers/
  • server/src/lib/

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendAPI/database/infrastructureenhancementNew feature or requestperformancePerformance optimization

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions