Skip to content

[Backend] Idempotency keys for prediction submission & other write endpoints#1241

Merged
Olowodarey merged 1 commit into
Arena1X:mainfrom
itodo001:feat/1000-idempotency-keys
Jun 27, 2026
Merged

[Backend] Idempotency keys for prediction submission & other write endpoints#1241
Olowodarey merged 1 commit into
Arena1X:mainfrom
itodo001:feat/1000-idempotency-keys

Conversation

@itodo001

Copy link
Copy Markdown

Summary

  • Adds an Idempotency-Key request-header mechanism: the first request with a given key for a given user executes normally and its response is stored; a later request with the same key replays the stored response without re-executing the handler.
  • New IdempotencyKey entity + IdempotencyService (acquire/complete/release + hourly cleanup cron for rows older than 24h) under src/common/idempotency/.
  • New IdempotencyInterceptor + @Idempotent() decorator, applied to POST /predictions.
  • New migration 1776500000000-CreateIdempotencyKeys.ts creating the idempotency_keys table with a unique (key, userId) index and a FK to users.

Behavior

  • Same key + same body, sequential → second call replays the stored response, handler runs once.
  • Same key + different body → 422.
  • Missing Idempotency-Key header on an @Idempotent() route → 400.
  • Same key, concurrent (first still in flight) → second call → 409.
  • Hourly cron prunes keys older than 24h.

Files

  • src/common/idempotency/* (new)
  • src/common/common.module.ts
  • src/predictions/predictions.controller.ts
  • src/predictions/predictions.module.ts
  • src/migrations/1776500000000-CreateIdempotencyKeys.ts

Closes #1000

Introduces an Idempotency-Key mechanism: the first request with a given
key for a user executes normally; a later request with the same key and
body replays the stored response without re-running the handler. Same
key with a different body returns 422, a missing key on an @idempotent()
route returns 400, and a concurrent duplicate while the first request is
still in flight returns 409. An hourly cron prunes keys older than 24h.

Closes Arena1X#1000
@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
insight-arena-4rll Ready Ready Preview, Comment Jun 27, 2026 12:52pm

@drips-wave

drips-wave Bot commented Jun 27, 2026

Copy link
Copy Markdown

@itodo001 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Olowodarey Olowodarey merged commit e079351 into Arena1X:main Jun 27, 2026
5 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.

[Backend] — Idempotency keys for prediction submission & other write endpoints

2 participants