Go backend challenge

38:12 left

Idempotent payment API

MediumGo 35 min suggested

Implement a handler that processes payment requests exactly once. Clients may retry with the same Idempotency-Key header; duplicate requests must return the original response without charging twice.

Requirements

  • Store responses keyed by Idempotency-Key for 24h
  • Handle concurrent duplicates safely
  • Return 409 if the same key is reused with a different body
  • Unit tests must pass (6 provided)
Example
POST /payments
Idempotency-Key: 7f3c…
→ 201 {"id":"pay_91","status":"captured"}

Tests

4 / 6 passing
  • TestCreate_NewKey
  • TestCreate_ReplayReturnsOriginal
  • TestCreate_MissingKey
  • TestCreate_DifferentBody409
  • TestCreate_ConcurrentDuplicates
  • TestStore_Expiry24h