For this article, we will use Kenya as our reference environment, starting with Nairobi's public transport network.
The objective is to move from the problem described in Part 1 to a working routing foundation. We will examine how OpenTripPlanner (OTP) combines public transport data with geographic networks, how its graph is built, and what needs particular attention when applying it to Kenya.
One important distinction: OTP can process the data we provide, but it cannot make incomplete or outdated transport data accurate. In a city such as Nairobi, preparing and validating the input data is part of building the routing system, not an administrative task to postpone until later.
1. What OpenTripPlanner actually does
OpenTripPlanner (OTP) is an open-source routing engine written in Java. It combines scheduled public transport with street networks to calculate journeys involving modes such as walking, cycling, public transport, and supported mobility services.
The important concept is the routing graph.
OTP does not independently calculate a road route and a bus route, then simply join the results. It builds a graph representing the transport network, linking transit stops to the surrounding street network. Its routing algorithms can then search for itineraries that combine street and transit segments.
For a Nairobi deployment, think of the graph as containing two major data layers:
A geographic layer derived from OpenStreetMap, representing streets and pedestrian connections.
A public transport layer derived from GTFS, representing routes, stops, trips, and service times.
These layers must connect correctly. If a GTFS stop is positioned far from the actual road or pedestrian network, the passenger may receive an unrealistic access or egress route.
2. Preparing the Kenyan data
The first practical task is identifying the data that will feed the graph.
OpenStreetMap: The geographic foundation
OpenStreetMap data around Kibera, Nairobi. The geographic detail illustrates why street-network quality matters. Source: CARTO.
For a Nairobi deployment, the OSM extract should cover the intended service area, not merely the central business district.
It should include:
Road networks and their access restrictions.
Pedestrian paths and footways.
Relevant crossings and connectivity.
Geographic features needed to interpret the street environment.
A common starting point is a regional .osm.pbf extract. You can obtain Kenya extracts from providers such as Geofabrik.
However, an OSM extract is not automatically a reliable pedestrian network. Mapping completeness, access tags, and connectivity vary across neighbourhoods. Informal settlements, private roads, gated developments, and pedestrian shortcuts deserve particular attention.
There is also a country-specific configuration consideration: OTP interprets OSM tags using its configured street-property rules. Its documentation explicitly notes that road tags and their meaning can vary by country. A configuration suitable for another country should not automatically be assumed correct for Kenya.
GTFS: Representing Nairobi's public transport
For Nairobi, one important starting point is the Digital Matatus dataset.
The dataset is especially relevant because it represents matatu routes and stops, helping transform an otherwise difficult-to-model informal transport network into structured data.
The TUMI Datahub lists a Nairobi GTFS dataset containing routes, schedules, and stop locations. Mobility Database also lists the DigitalMatatus feed with 136 routes. However, its recorded service-date range is January 2019 to December 2020. This is a critical distinction: a feed being available or recently catalogued does not mean its schedules are current.
Before building an OTP graph, inspect the feed rather than assuming it is production-ready.
At minimum, validate:
GTFS file | What to inspect |
|---|---|
| Agency identity and timezone |
| Route identifiers, names and types |
| Trip definitions and route associations |
| Stop coordinates, names and identifiers |
| Stop sequence and arrival/departure times |
| Days on which services operate |
| Service exceptions and special dates |
| Route geometry, where supplied |
For Nairobi, I would pay particular attention to stop coordinates, route shapes, service calendars, and whether scheduled trips reflect actual operations.
A GTFS validator can identify structural issues, but validation alone cannot establish that the service is still operating as represented.
3. How OTP turns these datasets into a routing graph
The graph-building process is one of the most important parts of an OTP deployment.
At a high level, the process looks like this:

The process can be understood in five stages:
Import: OTP reads the OSM and GTFS input files.
Street construction: It creates the street network used for supported street-based travel.
Transit construction: It imports routes, stops, trips, and service calendars.
Linking: It connects transit stops to the street network so passengers can access and leave services.
Serialization: It saves the resulting graph so the server can load it for journey planning.
The resulting graph is not just a copy of the input datasets. It is a prepared representation of the network that OTP uses during routing.
OTP separates graph-building configuration from runtime routing configuration. build-config.json contains settings that affect the graph itself, while router-config.json controls settings that can be changed when the server runs.
4. A practical OTP project structure for Nairobi
For a first implementation, I would keep the deployment simple and make the input data and configuration explicit.
nairobi-otp/
├── data/
│ ├── kenya-latest.osm.pbf
│ └── nairobi-gtfs.zip
│
├── config/
│ ├── build-config.json
│ └── router-config.json
│
├── graph/
│ └── graph.obj
│
└── logs/
For OTP, the directory passed to the application is its base directory. It scans that directory for graph inputs and configuration files by default, unless explicit input locations are configured. Keep the actual OTP base directory and its file layout consistent with the paths in your deployment.
{
"osm": [
"data/kenya-latest.osm.pbf"
],
"gtfs": [
"data/nairobi-gtfs.zip"
],
"buildReportDir": "logs/build-report"
}
This is an illustrative configuration fragment. Check the exact path resolution and accepted configuration structure against the OTP release you deploy.
The build report is important. Do not treat a successfully generated graph.obj as proof that the graph is correct. Review import warnings and errors, inspect stop linking, and test actual journeys.
For a production deployment, I would also version the source datasets and configuration together. That makes it possible to identify which OSM extract, GTFS feed, and build settings produced a particular graph.
5. Configuring OTP for Nairobi's routing requirements
Once the graph is built, the next concern is how OTP evaluates journeys.
Consider a passenger travelling from Kikuyu to Nairobi CBD.
The planner may need to:
Find nearby transit stops reachable by walking.
Identify services that can take the passenger towards the CBD.
Evaluate transfers between available routes.
Calculate the final walking segment.
Return reasonable alternatives based on travel time and other routing costs.
OTP exposes routing parameters for this process.
For example, boardSlack and alightSlack introduce safety margins around boarding and alighting. These are relevant when a passenger needs time to board or leave a service. OTP also provides transfer-related configuration and transfer optimization.
An important caution for Nairobi: a formally scheduled GTFS service and an informal service operating with variable departure times are not equivalent. OTP can calculate using the schedule represented in the feed, but it cannot infer the actual departure frequency of a matatu from incomplete schedule data.
This is a data-modelling limitation, not something that can be fixed by increasing a routing parameter.
For the first iteration, I would establish a reliable baseline using the available static GTFS data, then separately investigate how observed service frequency and real-time vehicle information could improve the passenger experience.
6. Exposing the routing engine to an application
OTP is a routing engine, not a complete mobility application.
It exposes APIs that allow other systems to request itineraries and integrate routing into web and mobile applications. OTP 2 provides GraphQL-based APIs, among other interfaces.
A typical architecture for a Nairobi application could look like this:

In this design:
React Native handles the passenger experience, map display, and journey selection.
Laravel provides the application API, authentication, user preferences, and application-specific business logic.
OTP handles the multimodal journey computation.
PostgreSQL/PostGIS can store application data, transport metadata, and geographic information that the application needs independently of OTP.
The backend should not need to reimplement OTP's routing algorithm. Instead, it should translate application requests into routing requests, normalize the response where necessary, and expose a stable contract to the mobile application.
For example, the application might request a journey from Kikuyu to Kenyatta Avenue at a particular departure time. The backend would resolve the request, call OTP, and return a structured itinerary containing walking legs, transit legs, stops, departure times, arrival times, and route information.
The distinction between routing and application orchestration becomes increasingly important when multiple providers or routing engines are introduced. That will be the subject of Part 5.
7. What should be tested before calling it a working routing foundation?
A graph that builds successfully is only the beginning.
For a Nairobi pilot, I would create a small but representative test suite:
Local access: A short journey between two locations within one neighbourhood.
CBD access: A journey from a residential area to the city centre.
Multi-transfer journey: A journey that requires connecting between two or more services.
Walking-only journey: A test that verifies the pedestrian network independently of transit.
Missing-data scenario: A journey near a stop with incomplete or questionable information.
Time-dependent scenario: The same origin and destination at different departure times.
For each test, inspect whether OTP returns a journey, whether the stops are geographically plausible, whether the service dates are valid, and whether the transfer sequence makes sense.
I would also record graph build time, serialized graph size, startup time, memory consumption, and journey response latency. These measurements establish the baseline for the performance investigation in Part 3.
The key is to test actual journeys across Nairobi, not just whether the API returns HTTP 200.
One important Kenya-specific conclusion
The biggest risk in this implementation is not necessarily the routing engine. It is the accuracy and operational relevance of the transport data.
The Nairobi GTFS feed is a valuable starting point, but its published service-date range must be checked before using it to make current journey recommendations. A successful graph build does not establish that the resulting itineraries reflect today's matatu operations.
Part 3 will take this foundation further: The Performance Challenge, Benchmarking OpenTripPlanner. We will investigate graph size, memory consumption, build time, startup time, and query latency, then compare a Nairobi-area graph with a larger geographic graph. The aim is to determine what actually limits OTP as the network grows, using measurements rather than assumptions.





