Home / GIS and Open Map Data for Beginners

OpenStreetMap Routing: OSRM, Valhalla, GraphHopper, and Which One to Call

Aerial view of winding highways crossing green countryside

Photo: Zeeshaan Shabbir / Pexels

A common first misunderstanding about OpenStreetMap is that it is a navigation service. It is not; it is a database of the world's roads, paths, and places, and the directions come from separate routing engines that read that database and compute paths through it. The openstreetmap.org website makes this visible if you look: its directions feature quietly delegates to external engines. Four names dominate the ecosystem, OSRM, Valhalla, GraphHopper, and OpenRouteService, and they are not interchangeable clones. They differ in the deepest design decision a router makes: whether speed is baked into the data before you ask, or priced fresh for every request. This guide explains that divide, profiles each engine honestly, and ends with the practical question every developer and heavy user faces: call a public instance, pay for a hosted one, or run your own.

Interactive tool

Fit Is Performance: The OSM Routing Checklist

Check off each step as you finish it. Your progress stays on this page.

0 of 8 complete

0% done

How Routing on OSM Data Works

A routing engine consumes OpenStreetMap data and builds a graph: intersections become nodes, road segments become edges, and every edge carries the costs a traveler cares about, distance, expected time, and restrictions such as one-way streets, turn bans, access rules, and vehicle limits drawn from the map's tags. A route request is then a search through that graph for the cheapest path under a chosen profile, car, bicycle, foot, truck, where the profile decides which edges exist at all and what each one costs. Two consequences follow, and both explain most surprises. First, routing quality is data quality: a missing one-way tag or an unmapped turn restriction in OpenStreetMap becomes a wrong instruction in every engine that reads it, which is why a bad route is often a mapping bug you can fix, a possibility our guide to adding a place to OpenStreetMap introduces from the editing side. Second, engines differ less in the algorithm than in when they pay the computation cost. Preprocessing engines spend hours baking shortcuts into the graph so each query is answered almost instantly, at the price of a graph tuned to fixed profiles. Runtime engines keep the graph general and price each request as it arrives, slower per query but free to weigh hills, surfaces, and preferences differently for every single ask. That divide, baked versus priced, is the key to the whole family.

OSRM and GraphHopper: Speed Baked In

OSRM, the Open Source Routing Machine, is the engine behind the car directions many people meet first on openstreetmap.org. Its design preprocesses the graph with contraction techniques that let it answer continental routes extremely fast, and its public demo server exists so developers can test and small projects can call, within fair use. OSRM's profile set is fixed at build time, car, bike, and foot in the demo, and its personality is precision about the road network itself: fastest routes, turn-by-turn instructions, and a table service that computes many-to-many distances, beloved of logistics tools. GraphHopper shares the baked-speed philosophy and adds a commercial dimension: an open-source engine you can run yourself, and a hosted API from the company behind it for those who would rather pay than operate. GraphHopper's distinguishing depth is its vehicle and weighting flexibility for self-hosters willing to configure it, and its long history in delivery and field-service routing. Choose from this pair when your problem is high-volume, profile-stable routing, the same kinds of vehicles asking all day, and when you are prepared to rebuild the graph on a schedule, because a baked graph is only as fresh as its last build. Stale builds route yesterday's roads; serious operators rebuild daily or weekly from fresh OpenStreetMap extracts.

Valhalla and OpenRouteService: Priced Per Request

Valhalla, built at Mapbox and now stewarded in the open, takes the other fork: it tiles the world into a hierarchy of graph tiles and prices each request at runtime through a costing model. The payoff is flexibility that baked engines cannot match cheaply: the same server can price a route for a car avoiding highways, a cyclist who welcomes hills or one who refuses them, a pedestrian who prefers lit streets, with the preferences arriving inside the request rather than fixed at build time. If your product's routing questions vary by user and by moment, Valhalla's design is the natural fit, and its public and hosted options mirror the same call-it-or-run-it choice. OpenRouteService, run by the Heidelberg Institute for Geoinformation Technology, is a different kind of answer: not an engine you install so much as a hosted routing service on OSM data, with an API key, a free tier within its terms, and specialties the general engines treat as extras, including isochrones that draw the area reachable within a time budget, and profiles tuned for wheelchair routing and heavy vehicles. For a researcher or a small product that needs those specialties without operating anything, it is often the shortest path. The fair-use principle governs all public endpoints in this family: demo servers are for development and light use, and production traffic belongs on your own deployment or a paid plan.

Black and white aerial view of a snow-covered highway interchange
Black and white aerial view of a snow-covered highway interchange

Call It or Run It: The Deployment Decision

Every engine in this guide can be self-hosted, and the decision deserves the same clarity as the engine choice. Call a public or hosted API when your volume is modest, your profiles are standard, and your tolerance for operations is zero; you are renting freshness, someone else rebuilds the graph and keeps the lights on. Run your own when any of three conditions bite: your request volume makes per-call pricing or rate limits the binding constraint; your profiles are unusual enough that no public instance offers them; or your product cannot depend on a third party's uptime and terms for its core function. Self-hosting a router is honest work but not exotic: the data pipeline is a regional or planet extract, a build step measured in hours for baked engines, and a server sized to the graph, with Valhalla's tiling easing the memory problem for large areas. One more consideration belongs in every plan: data freshness is a feature users can feel. A router rebuilt monthly will confidently route through roads that opened last week only if the map has them and the build includes them, and in fast-growing areas the hosted services' update cadence can be worth more than any engine feature. The OpenStreetMap wiki maintains a routing software matrix comparing engines and services feature by feature; treat it as the living reference, and this guide as the map of how to think. Neighboring services divide the rest of the work: Nominatim answers where places are, and the OpenStreetMap API is how the data itself is read and edited.

Reading a Route Response: What the Engines Hand Back

Choosing an engine is half the integration; reading its answer well is the other half. A routing response is more than a line on a map. It carries the route's geometry, its total distance and duration, and a structured list of steps, the maneuvers with their road names, distances, and instruction types, from which your application builds its turn-by-turn voice. Three fields deserve a developer's respect. The duration is a model, not a measurement: engines estimate segment speeds from road class, surface, and profile settings, and none of the open engines, on their public instances, prices your specific journey with live traffic the way the big consumer apps do, so an ETA from an OSM router is an honest free-flow estimate to be presented as one. The geometry arrives at a precision you choose, and requesting full detail for a continental route returns a very large answer to draw a line a screen cannot resolve; ask for the simplification your display can use. And the steps are only as good as the underlying names and refs in the data, which returns us to this article's first lesson: routing quality is data quality, all the way down to whether the exit you are told to take carries its number in the map. Build your interface to degrade gracefully where the data is thin, and your users will trust the router precisely because it never pretends to know what it does not.

Choosing Between Engines: A Decision in Four Questions

When two engines could serve, four questions decide in order. Which profile carries your users? If your product is a delivery fleet, a cycling app, or a hiking platform, the engine whose profiles were built for that mode, and whose per-request costing can express its rules, wins before benchmarks are consulted. Whose data freshness can you control? Self-hosting any of these engines means owning an update pipeline for the planet's most-edited dataset; teams that cannot staff that pipeline should buy the freshness from a hosted instance, whichever engine it runs. What does the route need to explain? An engine is also its response: maneuvers, alternatives, and costing details differ, and the engine whose answer your interface can render most honestly is worth real money in user trust. What happens at ten times the traffic? Public instances have politeness ceilings by design, hosted tiers have prices, and self-hosting has hardware; the engine you can scale without re-architecting is the engine you actually chose, whatever the prototype used. Answer the four in order and the field of four engines usually narrows to one without a single benchmark being run, which is as it should be: in routing, fit is performance.

Related Guides

The closest companions to this guide are the GIS and open map data guides below. Each one picks up a thread this page starts:

Frequently Asked Questions

Does OpenStreetMap provide routing itself?

No. OpenStreetMap is the database; routing is computed by separate engines that read it. The directions on openstreetmap.org delegate to external engines such as OSRM and GraphHopper, and apps and services each choose their own router.

What is the difference between OSRM and Valhalla?

OSRM precomputes speed into the graph at build time, giving extremely fast answers for fixed profiles like car, bike, and foot. Valhalla prices each request at runtime through a costing model, so preferences such as avoiding highways or seeking hills can vary per request.

Can I use the public routing servers for my app?

Public demo servers, such as OSRM's, are offered for development, testing, and light use under fair-use expectations. Production volume belongs on your own deployment or a hosted plan, such as GraphHopper's API or OpenRouteService within its terms.

Which routing engine is best for cycling or wheelchair routes?

Valhalla's per-request costing handles varied bicycle and pedestrian preferences well. OpenRouteService is notable for specialized profiles including wheelchair routing and isochrones. The right choice depends on whether you want to run an engine or call a service.

Why did a router send me down a road that does not allow it?

Usually the OpenStreetMap data is missing a restriction tag, a one-way, an access rule, or a turn ban, and every engine reading that data inherits the gap. The durable fix is to correct the map itself; engines can only route the world as it is mapped.

Photo credits: Zeeshaan Shabbir (Pexels); Chait Goli (Pexels). Photos are served from this site; follow the credit to the library page for the original.