Validation, Errors, and Resilience
Shared request validation, HTTP error mapping, and capability-specific retry and duplicate-request behavior.
Cross-cutting Concept
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
Loading graph...
Core Rules and Standards
- Validate at the trust boundary. Reject malformed shape, ranges, identities, required fields, and authorization state before domain execution.
- Use a stable error contract. Return machine-readable problem details with type, status, title, detail, instance, and correlation without exposing stack traces or secrets.
- Separate expected and unexpected failures. Validation and not-found conditions are caller errors; conflicts represent state; unhandled faults indicate incidents.
- Bound overload controls. Limit concurrency and request rate per source or user and shed work with a retry hint where appropriate.
- Make mutations retry-safe. Require an operation identifier for duplicate-sensitive writes and retain intent until the authoritative outcome is known.
- Classify retries. Retry only bounded transient faults; never retry validation, authorization, permanent deserialization, or destructive ambiguous work automatically.
- Compensate or confirm. After a timeout or partial failure, verify authoritative state or execute an explicitly approved compensating action.
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.
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
- Contracts and MessagingCustom DocContracts and MessagingOwned APIs and events connect independently maintained BookWorm capabilities without sharing business state.Ownerplatform-engineering-teamOpen doc — Delivery guarantees and envelope handling.
- ObservabilityCustom DocObservabilityShared structured logging, OpenTelemetry signals, and health checks support diagnosis across BookWorm services.Ownerplatform-engineering-teamOpen doc — Trace and error correlation.
- Runtime ViewCustom DocRuntime ViewRepresentative BookWorm runtime scenarios across commerce, discovery, customer feedback, and platform operations.Ownerarchitecture-enabling-teamOpen doc — End-to-end exception and compensation scenarios.