Skip to content

fix(leaderboard): preserve snapshot consistency during rank recompute (#1932) - #2086

Open
huangji6693-max wants to merge 1 commit into
Arena1X:mainfrom
huangji6693-max:fix/leaderboard-snapshot-consistency-1932
Open

huangji6693-max wants to merge 1 commit into
Arena1X:mainfrom
huangji6693-max:fix/leaderboard-snapshot-consistency-1932

Conversation

@huangji6693-max

Copy link
Copy Markdown

Closes #1932

Summary

  • Captures and freezes a complete prior global leaderboard snapshot before recalculateRanks() begins mutating entries.
  • Serves concurrent reads (getLeaderboard, getTopN, getLeaderboardCursor, getUserRank) from the frozen prior snapshot while recomputation is in flight so readers never observe partially updated ranks or mixed scores.
  • Swaps the active snapshot reference atomically only after all rank updates have been computed and the database transaction has committed; preserves the prior snapshot if recomputation fails mid-transaction.

Files Modified

  • backend/src/leaderboard/leaderboard.service.ts
  • backend/src/leaderboard/leaderboard.service.spec.ts

Verification

  • npx jest src/leaderboard/: 4/4 test suites passed, 79/79 tests passed (including tests verifying reads during recompute return the complete prior snapshot, reads after recompute return the new snapshot, atomic swap across step-by-step writes with zero partial state, and rollback safety).

@vercel

vercel Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
insight-arena-4rll Error Error Oct 26, 2026 6:10pm UTC

This branch had an error being deployed

1 failed deployment
Preview — 3c05f3c4 Deployed Oct 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backend] — Leaderboard Snapshot Consistency During Recompute

1 participant