Skip to content

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 ​

DependencyUnavailableRationale
Identity / verification providerPENDING → 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 / databaseFail 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 documentFail closed — REVIEW.Evaluating against no policy means evaluating against nothing.
Routing providerJourney 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 / MapLibreDegrade 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.
RedisFall back to the database. Queue depth is reduced; correctness is preserved.Cache and queue, never system of record.
Notification deliveryPreserve the transaction and retry. Never roll back a booking because an SMS failed.The booking is real whether or not the message arrived.
WebSocketClient falls back to POST /journeys/{id}/location polling.In-journey only.
Emergency servicesNever fail. Escalate through an independent path.See below.

Fail-safe invariant ​

text
Verification unavailable
        ↓
Do NOT assume PASS
        ↓
PENDING / REVIEW

An 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.

text
Emergency detected
        ↓
Safety workflow
        ├── Emergency contact notification
        ├── Live location sharing
        ├── Incident creation
        ├── Platform safety team
        └── Regulatory escalation where applicable

If 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 ​

CallTimeoutOn timeout
Verification provider3sREVIEW
Routing provider5sJourney stays DRAFT, retry
Database2sFail request
Redis500msFall back to database
Strapi2sCached content
Notification (queued)n/a — asyncRetry 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:

text
Content serving      → cached
Matching             → unavailable (no routing = no matching)
Compliance           → REVIEW
Booking confirmation → blocked
Journey in progress  → unaffected, continues
Emergency            → unaffected

Journeys 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-ID propagated end to end
  • Metrics per dependency: latency, error rate, circuit state
  • Alerts on fail-safe activations — a spike in REVIEW means 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.

KHAWI — same route, go together.