Field Manual PHP / Laravel reference
← Financial-system patterns

Idempotency

Persisted idempotency prevents a repeated logical request from producing a second effect.

What it is

Persisted idempotency prevents a repeated logical request from producing a second effect.

When to use it

Use for mutations clients or networks may retry.

Syntax

UNIQUE (actor_id, idempotency_key)
request_hash + saved_status + saved_response

Example

// Transaction algorithm:
// Insert request row using unique actor + key.
// Save a canonical validated-payload fingerprint.
// Execute local operation and save result in same transaction.
// On uniqueness conflict: load existing committed row.
// Same fingerprint -> replay; different -> 409.
// Define handling for in-progress requests and key retention.

Common mistakes

Check-then-insert races; catching a unique violation inside a failed PostgreSQL transaction requires rollback/savepoint.

Related topics

Idempotency