Route Optima

Project · June 2026

Dispatcher console, driver app, and a distributed route solver

Next.js consoles and an Expo driver app sit on a FastAPI and PostgreSQL backend. Road times come from OSRM. OR-Tools runs on GCE workers behind a job queue, so the web API and the CPU-heavy solver scale independently.

  • Next.js
  • FastAPI
  • PostgreSQL
  • Expo
  • OR-Tools
  • OSRM
  • Cloud Run
  • GCE
Route Optima dispatcher interface beside the driver app trip-offer screen
Composite view of the dispatcher and driver applications

Architecture

Consoles and the driver app share one API. The solver is its own fleet.

Cloud Run hosts the UIs and FastAPI. PostgreSQL holds operational state. OSRM and OR-Tools run separately so a heavy solve does not take down dispatch.

Route Optima system architectureThe shared Next.js frontend and Expo driver app call a FastAPI control plane on Cloud Run. The control plane stores state in PostgreSQL via Supabase, streams dispatch alerts back over server-sent events, sends push notifications to drivers, and submits solve jobs to a solver coordinator. OR-Tools workers on GCE claim geographic groups from a Postgres queue with leases and heartbeats, scale from zero to demand and back, and fetch travel-time matrices from OSRM on Cloud Run, autoscaling to one machine per matrix.CLIENTSCONTROL PLANEDATA · SUPABASESOLVER FLEET · GCENEXT.JSWeb frontendDispatch console · Tenant portalshipments · trips · drivers · org ordersEXPODriver apptrip offers · GPS · proof of deliverytenant config loaded at startupFASTAPIBackend APIauth + RBAC · JWT, invites, PATsplanning scheduler · advisory locktrip revisions · driver offersdispatch alerts over SSESUPABASEPostgreSQLoperational stateAuth (JWT) · StorageLISTEN / NOTIFYExpo Pushdriver notificationsFASTAPISolver coordinatorjob queue in Postgresgeographic groups · matricesGCE MIGOR-Tools workerson-demand · 1 group per VMgroup 1group 2group 3CLOUD RUNOSRM serviceautoscaling · 1 machine per matrixmatrix 1matrix 2matrix 3SSE alertsREST · JWTSQLAlchemyNOTIFYsolve job · poll resultclaim groupSKIP LOCKEDlease · heartbeat0→N→0matricespushpush notifications

Web consoles

Next.js dispatch and tenant apps on Cloud Run.

Control plane

FastAPI + PostgreSQL: orders, trips, auth, and dispatch.

Driver app

Expo app: offers, maps, GPS, and proof of delivery.

Solver fleet

OSRM matrices and OR-Tools workers that scale with the queue.

Expo · iOS & Android

Driver app

Swipe to explore

  • On duty

Original

10 routes
Original plan on Google Maps: 100 stops grouped into 10 routes in Dubai

Optimized

4 routes
Route Optima plan on Google Maps: the same 100 stops on 4 routes
Public sample: original plan vs clustered routes for the same day.
Distance
325.42 → 205.01 km−37.0%325.42 to 205.01 km, −37.0%
Drive time
564.0 → 355.3 min−37.0%564.0 to 355.3 min, −37.0%
Routes
10 → 410 to 4

System behavior

Plan, solve, validate, and recover.

  1. 01

    Plan once

    Shipment changes are batched inside a moving planning window.

    An advisory lock prevents overlapping plans, and near-start trips are frozen before the request is built.

  2. 02

    Solve in parallel

    OSRM supplies travel matrices and OR-Tools builds constrained routes.

    Geographic groups run independently on GCE workers, keeping CPU-heavy solves away from the API.

  3. 03

    Apply current routes

    The backend checks solver output against current database state.

    Stale results are discarded, while accepted work stays pinned to an immutable trip revision.

  4. 04

    Recover and scale

    Workers claim leased groups from a PostgreSQL queue and report heartbeats while solving.

    SKIP LOCKED, lease expiry, and 0 → N → 0 GCE autoscaling handle interruptions and bursts.