|
| 1 | +# Self-Hosting a Routing Engine |
| 2 | + |
| 3 | +rendezvous-kit is engine-agnostic — it works with any routing service that can compute isochrones and route matrices. This guide covers self-hosting options so you can run the full pipeline without third-party API keys or rate limits. |
| 4 | + |
| 5 | +## Quick Comparison |
| 6 | + |
| 7 | +| Engine | Isochrone | Route Matrix | Docker image | Typical RAM | Setup effort | |
| 8 | +|--------|:---------:|:------------:|--------------|-------------|--------------| |
| 9 | +| Valhalla | Yes | Yes | `ghcr.io/gis-ops/docker-valhalla` | 2–8 GB | Medium | |
| 10 | +| OSRM | No | Yes | `osrm/osrm-backend` | 1–4 GB | Low | |
| 11 | +| GraphHopper | Yes | Yes | `graphhopper/graphhopper` | 2–6 GB | Low | |
| 12 | + |
| 13 | +**Recommendation:** Valhalla is the best all-round choice — it supports isochrones, route matrices, and turn-by-turn routing. OSRM is lighter but cannot compute isochrones, so you would need to supply your own intersection polygon or pair it with another engine. |
| 14 | + |
| 15 | +## Valhalla (Recommended) |
| 16 | + |
| 17 | +The easiest way to run Valhalla is with the [GIS-OPS Docker image](https://github.com/gis-ops/docker-valhalla): |
| 18 | + |
| 19 | +```bash |
| 20 | +docker run -d --name valhalla \ |
| 21 | + -p 8002:8002 \ |
| 22 | + -e tile_urls=https://download.geofabrik.de/europe/great-britain-latest.osm.pbf \ |
| 23 | + -v valhalla_data:/custom_files \ |
| 24 | + ghcr.io/gis-ops/docker-valhalla/valhalla:latest |
| 25 | +``` |
| 26 | + |
| 27 | +The first run downloads and builds routing tiles — this can take 10–60 minutes depending on the region size. Subsequent starts are fast. |
| 28 | + |
| 29 | +**Use in rendezvous-kit:** |
| 30 | + |
| 31 | +```typescript |
| 32 | +import { ValhallaEngine } from 'rendezvous-kit/engines/valhalla' |
| 33 | + |
| 34 | +const engine = new ValhallaEngine({ baseUrl: 'http://localhost:8002' }) |
| 35 | +``` |
| 36 | + |
| 37 | +### Choosing a Region |
| 38 | + |
| 39 | +Download `.osm.pbf` extracts from [Geofabrik](https://download.geofabrik.de/). Smaller regions use less RAM and build faster: |
| 40 | + |
| 41 | +- `great-britain-latest.osm.pbf` — ~1.2 GB, builds in ~15 min, ~4 GB RAM |
| 42 | +- `europe-latest.osm.pbf` — ~28 GB, builds in hours, ~16 GB RAM |
| 43 | +- Country-level extracts are a good compromise |
| 44 | + |
| 45 | +### Multiple Regions |
| 46 | + |
| 47 | +To cover multiple non-contiguous regions, download separate extracts and merge them with [Osmium](https://osmcode.org/osmium-tool/): |
| 48 | + |
| 49 | +```bash |
| 50 | +osmium merge england.osm.pbf scotland.osm.pbf wales.osm.pbf -o gb.osm.pbf |
| 51 | +``` |
| 52 | + |
| 53 | +## OSRM |
| 54 | + |
| 55 | +OSRM is fast and lightweight but only supports route matrices — no isochrones. |
| 56 | + |
| 57 | +```bash |
| 58 | +# Download and prepare data |
| 59 | +wget https://download.geofabrik.de/europe/great-britain-latest.osm.pbf |
| 60 | +docker run -t -v $(pwd):/data osrm/osrm-backend osrm-extract -p /opt/car.lua /data/great-britain-latest.osm.pbf |
| 61 | +docker run -t -v $(pwd):/data osrm/osrm-backend osrm-partition /data/great-britain-latest.osrm |
| 62 | +docker run -t -v $(pwd):/data osrm/osrm-backend osrm-customize /data/great-britain-latest.osrm |
| 63 | + |
| 64 | +# Run the server |
| 65 | +docker run -d --name osrm \ |
| 66 | + -p 5000:5000 \ |
| 67 | + -v $(pwd):/data \ |
| 68 | + osrm/osrm-backend osrm-routed --algorithm mld /data/great-britain-latest.osrm |
| 69 | +``` |
| 70 | + |
| 71 | +**Use in rendezvous-kit:** |
| 72 | + |
| 73 | +```typescript |
| 74 | +import { OsrmEngine } from 'rendezvous-kit/engines/osrm' |
| 75 | + |
| 76 | +const engine = new OsrmEngine({ baseUrl: 'http://localhost:5000' }) |
| 77 | +// Note: OSRM cannot compute isochrones — findRendezvous will throw. |
| 78 | +// Use OSRM for computeRouteMatrix only. |
| 79 | +``` |
| 80 | + |
| 81 | +## GraphHopper |
| 82 | + |
| 83 | +GraphHopper supports isochrones and route matrices. The open-source version is free to self-host. |
| 84 | + |
| 85 | +```bash |
| 86 | +docker run -d --name graphhopper \ |
| 87 | + -p 8989:8989 \ |
| 88 | + -e JAVA_OPTS="-Xmx4g" \ |
| 89 | + -v graphhopper_data:/data \ |
| 90 | + graphhopper/graphhopper:latest \ |
| 91 | + --url https://download.geofabrik.de/europe/great-britain-latest.osm.pbf \ |
| 92 | + --host 0.0.0.0 |
| 93 | +``` |
| 94 | + |
| 95 | +**Use in rendezvous-kit:** |
| 96 | + |
| 97 | +```typescript |
| 98 | +import { GraphHopperEngine } from 'rendezvous-kit/engines/graphhopper' |
| 99 | + |
| 100 | +const engine = new GraphHopperEngine({ baseUrl: 'http://localhost:8989' }) |
| 101 | +``` |
| 102 | + |
| 103 | +## Cloud-Hosted Alternatives |
| 104 | + |
| 105 | +If you prefer not to self-host: |
| 106 | + |
| 107 | +- **OpenRouteService** — free API key from [openrouteservice.org](https://openrouteservice.org/dev/), rate-limited (40 requests/min on free tier) |
| 108 | +- **Trotters Routing** — `https://routing.trotters.cc`, L402-gated (pay-per-request with Lightning) |
| 109 | + |
| 110 | +```typescript |
| 111 | +import { OpenRouteServiceEngine } from 'rendezvous-kit/engines/openrouteservice' |
| 112 | + |
| 113 | +const engine = new OpenRouteServiceEngine({ apiKey: 'your-api-key' }) |
| 114 | +``` |
| 115 | + |
| 116 | +## Tips |
| 117 | + |
| 118 | +- **Start with a small region** while developing — city or country level. You can always upgrade later. |
| 119 | +- **Pin the PBF date** in production so tile rebuilds are reproducible. |
| 120 | +- **Monitor memory** — routing engines are memory-hungry. Valhalla with GB data uses ~4 GB RAM. |
| 121 | +- **Health checks** — all engines respond to `GET /` or similar. Add a health check to your Docker Compose or Kubernetes config. |
0 commit comments