Mid-level Track Roadmap

Pattern: idempotency keys

This course builds an idempotency guard in Rails one piece at a time. It starts with a check-then-store key that lets five concurrent threads create duplicate XP records. Reordering the steps into claim, work, complete lets the unique index decide before any work runs. Later lessons cover what losing requests should do, using 409 Conflict as Stripe does. They also cover fingerprinting parameters and rejecting mismatches with 422, storing claims in Postgres or Solid Cache, and choosing random or derived keys.

What you'll learn

  • ✓Why a check-then-store key lets concurrent requests duplicate the work
  • ✓The claim, work, complete order with a pending status
  • ✓Polling, blocking or failing fast with 409 when a request loses the claim
  • ✓Request fingerprints and 422 responses for keys reused with different parameters
  • ✓Trade-offs between a Postgres table and Solid Cache for storing claims
  • ✓Choosing between random UUID keys and keys derived from stable fields
Free preview · Lesson 1 4 min read

Duplicate keys vs. duplicate work

Lesson 3 of the mid-level course "Service objects: idempotency" showed a check-then-store shape: look up the idempotency key, and if it's missing, do the work, then save the key. It used a hypothetical payment service. Here is the same shape applied to a hypothetical XP award:

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...