Skip to main content
NISHORGO Engineering portfolio
work independent

Navora — A distributed rides platform

A simulated ride-hailing backend that must stay correct under duplicate messages, retries, and service crashes — with the north-star invariant and the engineering behind it.

01 / evolution

5

releases from core dispatch to scale and resilience

02 / ownership

3

core services: Trip, Driver, Dispatch

03 / simulation

3

seeded scenarios: normal day, rush hour, supply shortage

04 / correctness

1

driver may hold at most one reserved or active trip

North-star invariant

One driver can have at most one reserved or active trip at a time, even with concurrent dispatchers, retries, duplicate events, and self-inflicted restarts.

Everything else in the project is a question of how to defend that invariant in a system that talks to itself through HTTP and an event stream.

What it is, briefly

Navora is a ride-hailing backend in miniature: riders request trips, drivers get assigned, trips are picked up and completed, payments are simulated, and an operations view makes all of it inspectable. The simulation engine is a workload generator, not a domain microservice — it cannot assign drivers.

The diagram shows the complete service architecture and the relationships between public APIs, domain services, the event stream, and supporting services.

Navora end-state architecture: rider, driver, operations, and simulation clients enter through Kong. Kong routes to Trip, Driver, and a client read API. Trip and Driver exchange events with Redpanda, which also exchanges events with Dispatch. Dispatch calls Trip, Driver, and Routing and ETA. Trip calls Pricing and simulated Payment. Redpanda feeds Notification and operational and analytical projections.
Clients enter through Kong. Trip and Driver own durable state; Dispatch coordinates assignments through direct service calls and events on Redpanda. The simulation engine acts through public APIs and never assigns drivers itself.

How the architecture stays correct

The diagram shows the service boundaries and event flow. The key consistency decisions sit below.

Strong consistency where it matters, eventual consistency everywhere else

  • Driver Service owns the reservation invariant in a single PostgreSQL transaction. A database constraint prevents a driver from having two reserved or active assignments, or one trip from reserving two drivers. A repeat reservation for the same trip and driver returns the prior result; availability updates cannot override an assignment.
  • Trip Service owns idempotency for POST /trips via a request table; a repeated (rider, key, payload) returns the original trip; the same key with a different payload returns a conflict.
  • Between services, state converges asynchronously. A driver may be reserved while a trip still reads matching; the workflow must finish or compensate.
  • Redis is treated as a replaceable cache, never as the authority for driver assignment. PostgreSQL remains the source of truth.

The outbox, not a transaction across services

A domain write and its outbox event are committed in one local database transaction. A relay publishes later. Each event carries an ID, schema version, timestamp, and correlation ID. Delivery is at-least-once, so consumers record processed event IDs alongside their local business effect, and internal commands remain idempotent. This is not exactly-once delivery.

Compensation and reconciliation, not two-phase commit

Cross-database work uses compensation. Dispatch reserves a candidate in Driver Service, then asks Trip Service to confirm the assignment while the trip is still matching. If Trip has cancelled the request, Dispatch releases the reservation. After a timeout, it reads the authoritative outcome before trying another driver or releasing one. Reconciliation resolves pending attempts after crashes; it never frees a confirmed active assignment solely because a short timer expired.

The most important decision

Why Driver Service owns reservations and Trip Service owns idempotency — and why this is a deliberate asymmetry.

Both responsibilities look similar. They are not. A reservation is a mutual exclusion on a finite thing: only one driver can be reserved at a time, and the system needs a single, atomic source for that answer. Driver Service exists to be that source. Idempotency is a contract with the outside: the same request sent twice must produce the same trip. That contract is on the trip, so Trip Service owns it.

Keeping each rule with its owning record avoids a distributed lock. Dispatch coordinates the two decisions and recovers when their views temporarily disagree.

What each release delivered

ReleaseModules and capabilities delivered
1 — Core ride and dispatchKong, Trip Service, Driver Service, Dispatch Service, Redpanda, and the simulation engine. The first ride flow covers request, assignment, pickup, completion or cancellation, with an inspectable operations view.
2 — Live city and routingRouting and ETA Service, H3 candidate search, road-based pickup estimates, live driver movement, and map and demand controls. A client read API/BFF and operational projections support the interfaces.
3 — Marketplace behaviorPricing Service, Notification Service, fare quotes, zone-based surge, batched matching, and cancellation policies.
4 — Complete simulated productPayment Service with a simulated provider, rider and driver accounts, trip history, simulated refunds, a ledger, and operator workflows. No real money moves.
5 — Scale and resilienceLarger scenarios, horizontal scaling, automated failure drills, dashboards, and a deployment pipeline.

Candidate search versus route choice

In Release 2, Driver Service maps fresh driver locations to H3 cells to build a bounded candidate shortlist. Dispatch expands to neighboring cells when needed, then asks Routing and ETA for road-network pickup times. H3 narrows the search; it does not calculate driving time or authorize a reservation. Dispatch ranks the reachable candidates, while Driver Service still performs the atomic reservation. Release 3 adds batched matching and fairness constraints without changing that ownership rule.

Implementation: Release 1 core ride flow

ComponentResponsibility
Trip Service (Go)Trip state machine, public request idempotency, trip database, outbox relay
Driver Service (Go)Driver state, location, durable reservations, driver database, candidate lookup
Dispatch Service (Go)Consumes trip.requested, reserves a candidate, asks Trip to confirm the assignment, reconciles after restarts
Kong GatewayPublic routes, declarative, database-free
Simulation engineSeeded scenarios and actors that drive the system through public APIs

The Trip Service moves a trip through matching → assigned → picked_up → completed, with cancelled or unfulfilled as terminal alternatives. Driver assignments move through reserved → active → released. Invalid trip transitions return a conflict. Dispatch persists its attempt before acknowledging a request event, so a restart can resume the work.

Build order

  1. A small Go CLI that emits JSON drivers and trip requests. First piece of the simulation engine.
  2. Docker Compose, migrations, JSON event contracts, scenario configuration, CI commands.
  3. Trip lifecycle, POST /trips, idempotency, migrations, transition tests.
  4. Atomic reservation, conflict under concurrent calls.
  5. Simulation engine + temporary test harness that proves a ride can complete without events. Harness removed when Dispatch works.
  6. Redpanda, outbox publisher, dispatch consumer, Manhattan-distance candidate ranking, reservation/confirmation.
  7. Idempotent event handling, bounded retries, dead-letter path, reconciliation for pending reservations and unpublished outbox rows.
  8. Kong in front of public APIs, OpenTelemetry trace propagation, structured logs, request/assignment latency/outbox backlog/consumer-lag/pending-reservation metrics.
  9. Named scenarios, duplicate-request and duplicate-event tests, two-replica Dispatch race, kill-and-restart drill.

Verification scenarios

Automated, because the interesting failures are timing-sensitive:

  • Concurrent reservations for the same driver.
  • Duplicate POST /trips with the same idempotency key.
  • Duplicate trip.requested delivery to Dispatch.
  • Trip restart after DB commit but before publication.
  • Dispatch restart after reservation but before assignment confirmation.
  • Cancellation during matching or before pickup.
  • Driver restart before processing trip.completed.

For each, the test asserts authoritative database states and the no-double-booking invariant. A seeded load scenario reports actual throughput and assignment latency.

Acceptance criteria

The Release 1 acceptance criteria are:

  • docker compose up starts everything; documented commands run a scenario and inspect a trip.
  • A repeated trip request with the same (rider, key, payload) returns the same trip; the same key with a different payload returns a conflict. Concurrent reservations for one driver yield at most one success.
  • A committed trip request has a matching outbox event; an outbox relay restart does not lose it. Duplicate delivery does not create a second trip or reservation.
  • A dispatcher crash during assignment leaves a recoverable pending state. Reconciliation eventually confirms or releases it.
  • Every trip ends in a valid state or remains visibly pending with a reason. Invariant violations in the scenario summary are zero.
  • A single end-to-end trace follows a request through Kong, Trip, message publication, Dispatch, Driver reservation, and assignment confirmation.

Technology choices

ConcernChoiceWhy here
Services and engineGoOne language for concurrent workers, APIs, and the simulation
GatewayKong (declarative, DB-free)Reproducible public routes and gateway controls
Durable stateSeparate PostgreSQL databases and credentials per service in one local instanceTransactions, constraints, outbox, recovery
Event transportRedpandaKafka-compatible local broker; demonstrates application recovery from broker downtime, not broker high availability
Geographic indexingH3 (Release 2)Nearby-driver candidate search and supply/demand aggregation
Road routingValhalla or OSRM (Release 2)Pickup ETA over roads, not straight-line distance
Database codepgx + sqlcExplicit SQL and typed queries
ContractsOpenAPI + versioned JSON eventsReviewable interfaces from day one
DeploymentDocker Compose firstReproducible local demo
ObservabilityOpenTelemetry Collector (Release 1); Prometheus + Grafana as dashboards matureTrace workflow; measure lag, latency, failures

What changed for me

Working through this project changed how I make platform decisions. The interesting constraint is not “what should this service do?” but “what happens when two of them disagree?” — and the answer is almost always “the database that contains the rule wins.”

What remains difficult

  • Replay realism. A seeded scenario is reproducible but may not match the failure modes that show up in a live platform. The scenario library needs broader failure and demand patterns.
  • Pending reservations under partition. Two dispatch replicas can disagree about a timed-out confirmation, but Driver Service’s database constraint still prevents double booking. The difficult choice is when to release a pending reservation without racing a delayed confirmation.
  • Evaluation without live traffic. The seeded load scenario is the closest proxy. Better benchmarks need more representative scenario inputs.

What I would improve next

  1. Trace-driven failure injection. Inject failure modes from real traces, not from a fixed scenario list.
  2. Schema compatibility checks in CI so the existing versioned event contracts can evolve without a coordinated deploy.
  3. An operator runbook that walks through failure and recovery scenarios. The automated tests check state; the runbook explains what an operator should inspect.

The full architecture and project plan are documented in navora-platform-plan.md in the project workspace.