Recording a one-time grant's use only in each instance's memory makes it one-time per process, not per system. Using a hypothetical support credit flow and a PostgreSQL-backed store, the article shows how a retry routed to a second instance, or a restart, admits the same grant again — and what a shared, durable, atomic store contract must guarantee instead.
Key points
- ConcurrentDictionary.TryAdd coordinates threads in one process only; a restart or scale-in erases every record.
- A round-robin retry landing on a second instance sees an empty dictionary and creates a duplicate credit.
- Sticky sessions, distributed caches and shorter expiry narrow the window but do not establish the guarantee.
- IDistributedCache exposes only get, set, refresh and remove, so the check-then-act race moves to the network.
- Minimum contract: authoritative shared store, one atomic admission, durable commit before execution, deadline checked on the store's clock.
- Admission limits who may run the operation; it does not make the external effect idempotent or exactly-once.
Real-world use
- A supervisor-approved, single-use goodwill credit grant consumed before the billing API call
- An ASP.NET Core service running two instances behind a round-robin load balancer with rolling deployments
- Retries after a gateway timeout where the caller resubmits and the outcome is still unknown
- Recovery paths that must take ownership of operations whose result stayed uncertain
This summary was generated by the agent from the original post on ASI Backbone Learning. The full text and all rights belong to its author and publisher. Go to original