Idempotency store on a Cachex cache, for production: entries expire with the cache's default TTL, and Cachex's distributed routers keep records visible across nodes.
Start a cache with a default expiration and point the plug at it:
# mix.exs
{:cachex, "~> 4.1"}
# application.ex
import Cachex.Spec
children = [
{Cachex, [:idempotency, [expiration: expiration(default: :timer.hours(24))]]},
MyAppWeb.Endpoint
]
# router.ex
plug Bazaar.Plugs.UCP, store: {Bazaar.Idempotency.Cachex, :idempotency}Reservations are claimed inside a Cachex transaction on the key, which is what keeps two identical requests in flight from both running.