Idempotency Keys for a Retried Job Creation Endpoint

Last updated: November 29, 2026

Quick Overview

Clients of an API that creates fine-tuning or batch jobs retry on timeouts, which sometimes creates duplicate jobs and double charges. Implement server-side idempotency keys so a retry with the same key and body returns the original response, a retry with a different body is rejected, and a concurrent retry does not run the work twice.

OpenAI
Software Engineering Fundamentals
Software Engineer
OpenAI
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Hard

0

0

0 solved


Clients of an API that creates fine-tuning or batch jobs retry on timeouts, which sometimes creates duplicate jobs and double charges. Implement server-side idempotency keys so a retry with the same key and body returns the original response, a retry with a different body is rejected, and a concurrent retry does not run the work twice.

Job creation on the OpenAI platform is expensive and billable, and SDKs retry automatically on network errors. The interviewer is looking for a precise state machine (absent, in progress, done), scoping keys per organization, request fingerprinting, and careful thinking about what happens when the server fails midway.

What the Interviewer Expects
  • Scopes keys by organization so tenants cannot collide
  • Stores a fingerprint of the request body and rejects mismatches
  • Models an in-progress state so concurrent retries do not both execute
  • Decides explicitly what to do on failure: cache the error or release the key
  • Expires records with a TTL
  • Explains how this works across many API servers with a shared store
Key Topics to Cover
idempotency
API design
retries
state machines
distributed consistency
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you implement begin atomically in Redis or Postgres?
  • What if the server crashes after creating the job but before recording the response?
  • Should a 400 validation error be cached under the key?
  • How long should the TTL be, and what do you tell clients?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements
  • Header Idempotency-Key on POST. Same org, key, and body within 24 hours returns the stored response without new side effects.
  • Same key, different body returns 422.
  • Retry while the first attemp...
High-Level Design

A record per (org_id, key) holds the body fingerprint, a state, and the response. begin is a single atomic check-and-insert: in production, INSERT ... ON CONFLICT DO NOTHING in Postgres or `SET ...


Submit Your Answer
Markdown supported