SQL / Reference example
Scope an idempotency key by tenant
A uniqueness constraint is the foundation for atomic operation claims.
SQL
CREATE TABLE operation_requests (
tenant_id text NOT NULL,
operation_key text NOT NULL,
request_fingerprint text NOT NULL,
status text NOT NULL,
response_json jsonb,
created_at timestamptz NOT NULL DEFAULT now(),
PRIMARY KEY (tenant_id, operation_key)
);What matters
A database uniqueness constraint helps arbitrate concurrent attempts. This is only the schema: transactional claim/commit, result persistence, key reuse policy and external effects still need implementation.
Test these cases
- Two requests race for the same tenant/key
- Same key with different request fingerprint
- Outbox handling after process crash
Sources and limits
This is a reference snippet, not a substitute for reviewing the full vendor API contract, concurrency rules or production threat model. Do not paste secrets into sample code.