📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

How would you stop a double-submitted create from producing two records, even if the client disables the button?

Mid-Level Coding Intermediate

🎯 Key points

  • Client guards are not enough
  • Same Idempotency-Key reused across retries of one submission
  • Key stored in the same transaction as the write, unique constraint resolves races
  • Return the original response for repeats; 409 for an in-flight duplicate
  • Natural unique key as a second guard
  • TTL on keys (e.g. 24 hours) with a cleanup job
  • Client shows replayed success as normal success

⏱ 30-second answer

Disabling the button only stops the common case; retries, two tabs or a flaky network can still send the request twice. Make the write idempotent: the client generates an idempotency key (a GUID) when the form is opened or first submitted and reuses the same key on every retry of that submission, sending it in an Idempotency-Key header. The API inserts the key and the result in the same database transaction as the create, protected by a unique constraint, and returns the stored response for repeats (a concurrent duplicate that loses the race gets 409 or waits and replays). A natural unique key such as the SKU adds a second guard. Keys carry a TTL (for example 24 hours) and a scheduled job deletes expired rows. For UX, the client treats a replayed response as success and shows the saved record, so the user never sees 'already exists'.

🔍 What the interviewer is checking

Checks whether they know client-side guards are not enough and understand idempotency keys.

↩ Usually asked after

More in SPA Integration

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me