Failure Handling
What happens when a dependency is unavailable, slow or returns garbage. The central rule is that failure degrades to REVIEW, never to ALLOW.
Dependency matrix
| Dependency | Unavailable | Rationale |
|---|---|---|
| Identity / verification provider | PENDING → REVIEW. No journey published, no booking confirmed. | Never treat "unable to verify" as "verified". An unverified participant has no value in the audit trail. |
| PostGIS / database | Fail the request. No cached or degraded mode. | A journey cannot be matched, booked or audited without its records. Serving stale data here would create bookings that cannot be explained. |
| Compliance policy document | Fail closed — REVIEW. | Evaluating against no policy means evaluating against nothing. |
| Routing provider | Journey stays DRAFT; retry with backoff. Never publish an unrouted journey. | Detour is the core matching constraint. Publishing without it would surface incompatible journeys to passengers. |
| Map tiles / MapLibre | Degrade the map only. Core flows continue. | Presentation layer. Never blocks a booking. |
| Strapi (CMS) | Serve cached or last-known content. Journeys, bookings and compliance decisions are unaffected. | Strapi owns content and policy drafts, not transactions. |
| Redis | Fall back to the database. Queue depth is reduced; correctness is preserved. | Cache and queue, never system of record. |
| Notification delivery | Preserve the transaction and retry. Never roll back a booking because an SMS failed. | The booking is real whether or not the message arrived. |
| WebSocket | Client falls back to POST /journeys/{id}/location polling. | In-journey only. |
| Emergency services | Never fail. Escalate through an independent path. | See below. |
Fail-safe invariant
Verification unavailable
↓
Do NOT assume PASS
↓
PENDING / REVIEWAn outage in an identity provider must degrade to REVIEW. It must never resolve to ALLOW. This is the single most consequential invariant in the system: a rule that fails open under load converts a temporary provider outage into a window of unverifiable, unauditable journeys.
Emergency is independent
The emergency pathway does not depend on ordinary matching, compliance or notification infrastructure being healthy.
Emergency detected
↓
Safety workflow
├── Emergency contact notification
├── Live location sharing
├── Incident creation
├── Platform safety team
└── Regulatory escalation where applicableIf a downstream service is degraded, the workflow degrades its own branches — it does not fail to start. An emergency path gated on a healthy dependency is not a safety path.
Retry and idempotency
Retry with exponential backoff and jitter for transient failures. Do not retry validation errors, compliance blocks or permission failures — they are deterministic and retrying produces load without changing the outcome.
Idempotency-Key is the recovery mechanism for the operations most likely to be retried by a flaky mobile client:
- create journey
- accept match
- create booking
- confirm booking
- start / complete / cancel journey
- create contribution
- emergency
A retried create must return the original result, not create a second one. Without this, a passenger retrying on a dropped connection gets double-booked.
Timeouts
| Call | Timeout | On timeout |
|---|---|---|
| Verification provider | 3s | REVIEW |
| Routing provider | 5s | Journey stays DRAFT, retry |
| Database | 2s | Fail request |
| Redis | 500ms | Fall back to database |
| Strapi | 2s | Cached content |
| Notification (queued) | n/a — async | Retry with backoff |
Verification gets the shortest timeout because it is on the critical path for every publish and every booking, and because a slow provider should surface as REVIEW quickly rather than holding a request open.
Degradation is per-capability
A degraded system does not go into one global "degraded mode". Each capability degrades independently:
Content serving → cached
Matching → unavailable (no routing = no matching)
Compliance → REVIEW
Booking confirmation → blocked
Journey in progress → unaffected, continues
Emergency → unaffectedJourneys already in progress continue during any dependency outage. A driver mid-commute must not have their journey interrupted because a content API or a notification provider is down.
Circuit breakers
Wrap each external dependency in a circuit breaker. Open the circuit after a sustained failure rate, fail fast while open, and probe with a half-open request before closing.
This is what keeps a dead dependency from consuming the request budget of a live one — without it, a provider timeout degrades every request rather than the requests that touch that provider.
Observability
Failure handling is only useful if it is visible:
- Structured logs with
X-Request-IDpropagated end to end - Metrics per dependency: latency, error rate, circuit state
- Alerts on fail-safe activations — a spike in
REVIEWmeans something upstream is wrong, and it is the visible symptom of a problem users cannot report - Queue depth monitoring for retry backlogs
- Audit records for every administrative or automated control applied
A fail-safe that activates silently converts a detectable outage into an invisible degradation. Alerting on REVIEW volume is how the outage is noticed.
