---
title: Validation, Errors, and Resilience
summary: Shared request validation, HTTP error mapping, and capability-specific retry and duplicate-request behavior.
owners:
  - platform-engineering-team
badges:
  - content: Cross-cutting Concept
    backgroundColor: purple
    textColor: purple
---

## Purpose and Scope

Validation, error handling, and resilience protect public and internal boundaries from malformed work, overload, partial failure, and repeated delivery. These rules apply to HTTP and RPC endpoints, message consumers, external calls, schedulers, and workflows across every building block.

## Visual Reference

**Request Validation and Recovery**

<MermaidFileLoader file="mermaids/003-validation-errors-and-resilience-diagram-1.mmd" />

## Core Rules and Standards

1. **Validate at the trust boundary.** Reject malformed shape, ranges, identities, required fields, and authorization state before domain execution.
2. **Use a stable error contract.** Return machine-readable problem details with type, status, title, detail, instance, and correlation without exposing stack traces or secrets.
3. **Separate expected and unexpected failures.** Validation and not-found conditions are caller errors; conflicts represent state; unhandled faults indicate incidents.
4. **Bound overload controls.** Limit concurrency and request rate per source or user and shed work with a retry hint where appropriate.
5. **Make mutations retry-safe.** Require an operation identifier for duplicate-sensitive writes and retain intent until the authoritative outcome is known.
6. **Classify retries.** Retry only bounded transient faults; never retry validation, authorization, permanent deserialization, or destructive ambiguous work automatically.
7. **Compensate or confirm.** After a timeout or partial failure, verify authoritative state or execute an explicitly approved compensating action.

<Admonition type="warning">
	A retry, acknowledgement, or successful transport call does not prove business completion.
	Consumers and callers must verify final state or receive a durable outcome.
</Admonition>

## Mechanism / How It Works

| Condition                             | Standard Response                                                                      |
| :------------------------------------ | :------------------------------------------------------------------------------------- |
| Invalid input                         | Return 400 with field-level or operation-level problem details                         |
| Unauthenticated or forbidden          | Return 401 or 403 without leaking protected resource details                           |
| Missing resource                      | Return 404 unless availability concealment is an explicit policy                       |
| State conflict or duplicate operation | Return 409 or the standard precondition response and preserve the existing state       |
| Preconditions not met                 | Return 412 and direct the caller to refresh the authoritative version                  |
| Capacity exceeded                     | Return 429 with retry guidance                                                         |
| Unexpected fault                      | Return 500 or 503 with correlation; log full diagnostics only inside protected systems |

## Resilience Pattern

| Step        | Rule                                                                                 |
| :---------- | :----------------------------------------------------------------------------------- |
| Admission   | Enforce transport limits and request or user quotas                                  |
| Idempotency | Create or confirm the operation key before executing side effects                    |
| Validation  | Run schema and domain preconditions before persistence                               |
| Execution   | Apply operation-specific timeouts and cancellation                                   |
| Retry       | Use bounded attempts, jitter, and backoff for classified transient faults            |
| Containment | Use circuit-breaking or fail-fast behavior to protect downstream dependencies        |
| Recovery    | Reconcile, replay, compensate, or escalate according to the capability's state model |

## Verification and Governance

- Test invalid, unauthorized, duplicate, concurrent, timed-out, and unavailable-dependency cases.
- Verify that 429 responses include retry guidance and that retries do not amplify load.
- Confirm idempotency keys are removed or released only after a safe retry outcome.
- Require a final-state check or compensation test for every distributed mutation.

## Related Documentation

- [[doc|arc42/08-crosscutting-concepts/002-contracts-and-messaging]] — Delivery guarantees and envelope handling.
- [[doc|arc42/08-crosscutting-concepts/004-observability]] — Trace and error correlation.
- [[doc|arc42/06-runtime-view]] — End-to-end exception and compensation scenarios.
