Reliability / explicit failure contracts
Retry a transient failure, not a bad assumption.
Use structured codes to decide what to do next. A transport timeout, permission denial and invalid envelope need different operator responses even if they all interrupt telemetry.
Error taxonomy
| Code / HTTP status | Meaning | Action |
|---|---|---|
| AUTH_REQUIRED / 401 | Missing or invalid credentials | Repair configuration; do not blindly retry |
| SCOPE_DENIED / 403 | Workspace or permission mismatch | Review the identity's authorization |
| IDEMPOTENCY_CONFLICT / 409 | Same key, different body | Investigate the caller's key allocation |
| INVALID_EVENT / 422 | Envelope failed validation | Correct fields; record a redacted diagnostic |
| RATE_LIMITED / 429 | Workspace quota or burst exceeded | Honor Retry-After and reduce throughput |
| UNAVAILABLE / 503 | Temporary service interruption | Bounded retry with jitter |
| TIMEOUT / no response | Acceptance outcome may be unknown | Retry only with the same idempotency key |
| ABORTED / local | Caller cancellation | Stop work; do not retry automatically |
A useful error envelope
{
"error": {
"code": "INVALID_EVENT",
"message": "data.duration_ms must be a non-negative integer",
"request_id": "req_demo_721",
"retryable": false,
"details": [{"path": "data.duration_ms", "rule": "integer_min_0"}]
}
}Log the code, request ID, workspace ID and field path. Do not log the authorization header or an unrestricted copy of the submitted body. Error messages are for people; machine decisions should use stable codes.
Bound the retry budget
The reference policy allows four total attempts: the original call plus three retries. Use full jitter with a 250 ms base and a 10 second ceiling. On 429 or 503, a valid Retry-After value takes precedence. It may be a delay in seconds or an HTTP date; parse both, reject invalid values and never sleep past the caller's overall deadline.
// Policy sketch; use a tested transport implementation in real code.
const maxAttempts = 4;
const retryIndex = 0; // zero for the first retry
const jitterMs = Math.random() * Math.min(10000, 250 * 2 ** retryIndex);
// Preserve the original event ID, body and idempotency key.
// Stop when maxAttempts or the overall deadline is reached.A timeout after transmission is ambiguous: the server may already have accepted the event. Generating a new key on each retry defeats idempotency and can create duplicates. Do not retry non-idempotent side effects simply because the client lost its response.
Cancellation and shutdown
Propagate an AbortSignal from the request or worker lifecycle. The imagined SDK should cancel pending sleeps as well as active network operations. During shutdown, stop accepting new telemetry, flush within a bounded deadline, then report any dropped count without blocking process termination forever.
Prevent retry storms
- Use per-workspace queues so one noisy tenant cannot starve another.
- Open a circuit after sustained transient failures; allow limited probes during recovery.
- Apply jitter independently across producers rather than using a shared fixed sleep.
- Expose queue depth, oldest-event age and dropped-event counters.
- Separate transport retry metrics from business-workflow retries.
Exercise the failure path
Toggle the timeout switch in the SDK playground. Then use the webhook simulator to compare a 429 receiver with a 500 receiver and replay a duplicate ID. Both demos are local-only and must not be mistaken for a test of real network resilience.
Review token diagnostics when failures are persistent and migration notes when an upgrade changes error behavior.