Skip to content

(SP: 1) [Backend] Redis Cache for Quiz Questions #291

Closed

Description

@LesiaUKR

Goal

Eliminate 2 DB queries per quiz page load by caching quiz questions in Redis.

Scope

  • Create types/quiz.ts with shared quiz types (QuizQuestion, QuizAnswer, QuizQuestionWithAnswers)
  • Add getOrCreateQuestionsCache(quizId, locale) to lib/quiz/quiz-answers-redis.ts
  • Integrate cache into getQuizQuestions() in db/queries/quiz.ts
  • Cache key: quiz:questions:{quizId}:{locale}
  • Fallback to DB if Redis not configured

Expected impact

  • Performance: ~5x faster quiz page load on cache hit (354ms → 65ms)
  • DB load: 2 fewer queries per quiz page view
  • Scalability: Popular quizzes served from Redis, not DB

Out of scope

  • TTL configuration (cache persists until manual clear or Redis eviction)
  • Cache invalidation on quiz content update (future admin feature)
  • Leaderboard caching (users want instant rank updates)

Files changed

  • frontend/types/quiz.ts (new)
  • frontend/lib/quiz/quiz-answers-redis.ts (modified)
  • frontend/db/queries/quiz.ts (modified)

Activity

  1. added
    performancePerformance and efficiency optimizations without functional changes.
    on Feb 7, 2026
  2. changed the title [-](SP: 3) [Backend] Redis Cache for Quiz Questions[/-] [+](SP: 1) [Backend] Redis Cache for Quiz Questions[/+] on Feb 7, 2026
  3. self-assigned this
    on Feb 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

performancePerformance and efficiency optimizations without functional changes.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions