Deploy Valhalla
Self-hosted OSM routing: routes, matrices, isochrones, map matching
valhalla
Just deployed
/custom_files
Deploy and Host Valhalla on Railway
Valhalla is an open-source routing engine for OpenStreetMap data. This template runs it on Railway backed by a persistent volume, serving turn-by-turn routes, time and distance matrices, isochrones and map matching over any region you point it at.
About Hosting Valhalla
Valhalla first builds routing tiles from an OpenStreetMap extract, then serves them over HTTP. Doing that on Railway takes three adjustments, all handled here: the service binds Railway's $PORT rather than the hardcoded 8002; a dual-stack listener fronts the router, because Valhalla's zmq socket cannot bind IPv6 while Railway's private network is IPv6-only; and worker threads default to 1, since a container reads the host core count and would otherwise spawn 32+ tile-caching workers and run out of memory. Tiles live on a volume at /custom_files, so they survive redeploys instead of being rebuilt each time.
First boot builds tiles before accepting traffic - about a minute for Monaco, tens of minutes for a country, hours for a continent. The deployment log is the progress bar. Leave the healthcheck path empty; any healthcheck window is shorter than a real first build.
Common Use Cases
- Time and distance matrices for fleet routing and vehicle optimisation (VROOM, OR-Tools, your own solver)
- Turn-by-turn directions, ETAs and isochrones for your own app, with no per-request API fees
- Map matching raw GPS traces onto the road network
Dependencies for Valhalla Hosting
- A volume mounted at /custom_files
- An OpenStreetMap .osm.pbf extract for the region you want to route over
Deployment Dependencies
- Regional extracts: https://download.geofabrik.de/
- Valhalla HTTP API reference: https://valhalla.github.io/valhalla/api/
- Upstream image: ghcr.io/valhalla/valhalla-scripted
Implementation Details
Stock Valhalla rejects any matrix past 20 locations and exposes no environment variable to change it, so this template patches the generated valhalla.json on every boot. Defaults are 500 locations and 250,000 source-target pairs, both configurable.
Why Deploy Valhalla on Railway?
Railway turns a multi-step tile build into a one-click deploy with a persistent volume attached. Other services in the same project reach the router over private networking at no egress cost, which makes it a natural backend for a solver or an API of your own.
Template Content
