Skip to content

feat: add idempotency and duplicate-submission protection - #650

Merged
A6dulmalik merged 2 commits into
MindBlockLabs:mainfrom
m-hajjo:feat/idempo
Aug 24, 2026
Merged

feat: add idempotency and duplicate-submission protection#650
A6dulmalik merged 2 commits into
MindBlockLabs:mainfrom
m-hajjo:feat/idempo

Conversation

@m-hajjo

@m-hajjo m-hajjo commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Problem

Players could submit the same answer multiple times (double-clicks, network retries, browser refreshes, or malicious requests), causing duplicate XP awards, double session advancement, and duplicate reward eligibility.

Solution

Introduced a Redis-backed IdempotencyService using SETNX-based lock + result caching. Every write path now wraps its core logic in idempotency.execute(key, fn), which guarantees the function runs at most once per key within a configurable TTL (default 24h).

Protocol:

  1. Check for a cached result → if found, return it (duplicate: true)
  2. Attempt to acquire a Redis lock (SETNX, 60s TTL) → if acquired, run fn, store the result, release the lock
  3. If the lock is held by a concurrent request → poll until the result appears or the lock expires, then force-acquire

Closes #626

@vercel

vercel Bot commented Aug 22, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
mind-block-app-frontend Skipped Skipped Aug 24, 2026 10:57am

@phertyameen

Copy link
Copy Markdown
Member

@m-hajjo can you please resolve conflict?

@vercel

vercel Bot commented Aug 24, 2026

Copy link
Copy Markdown

@m-hajjo is attempting to deploy a commit to the aminubabafatima8-gmailcom's projects Team on Vercel.

A member of the Team first needs to authorize it.

@A6dulmalik
A6dulmalik merged commit b2f6e83 into MindBlockLabs:main Aug 24, 2026
6 of 7 checks passed
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.

Add idempotency and duplicate-submission protection

3 participants