Part 1 described the problem as a journey planner that must work "beyond a single city or transportation network". So far, this series has mostly been about Nairobi's matatus. This part widens the map: other cities, and the services that connect them.
In Kenya, that means two kinds of transport with opposite rhythms. Urban matatus run every few minutes, with no timetable. Long-distance services run a few times a day, to the minute: the SGR's Madaraka Express between Nairobi and Mombasa, the Nairobi Commuter Rail lines, intercity coaches, domestic flights. A trip from a Nairobi estate to Mombasa uses both: a matatu to a station, a train, then something at the other end.
Two architecture questions follow. Where do the regions live: in one graph, or several? And what has to change in the router for a service that runs three times a day?
1. One national graph, or one per region?
There are two defensible designs.
One graph for the whole country. A single OpenTripPlanner instance loads the national OpenStreetMap extract and every GTFS feed. Cross-region trips are ordinary searches: the router sees the matatu, the station and the train in one network.
One graph per region, behind a routing proxy. Nairobi, Nakuru and Mombasa each get their own instance with a smaller street network. The proxy picks an instance from the origin and destination. Cross-region trips need stitching: plan to the regional hub in one graph, the long-distance leg separately, and onwards in another.

The measurements in Part 3 settle it for Kenya, at least for now. The national graph (1.25 million street vertices, 3.1 million edges, every feed) serves in 2.4 GB of memory. Per-region graphs would save memory we don't need to save, and they would turn the trips we most want to plan well into the hardest ones to plan.
What a single graph does cost is build time: 17 minutes for any change anywhere, because the street network dominates the build. That is the axis to watch. The point where regional graphs start to pay is roughly when one of these becomes true:
the street network grows enough that serving needs more memory than one server can comfortably give (several countries, not several cities);
regions need to publish on different schedules, and a 17-minute national rebuild per edit becomes the bottleneck;
one region's traffic justifies scaling its instance independently.
For a multi-country deployment, the OTP README's own recommendation is the right shape: one instance per country behind a proxy that picks by coordinates, with cross-border trips stitched at known border hubs. Not before.
2. Modular feeds inside one graph
One graph doesn't mean one monolithic feed. OTP loads any number of GTFS zips, and each one can carry its own identity:
feed_publisher_name,feed_publisher_url,feed_lang,feed_version,feed_id
Navigo,https://navigo.co.ke,en,20261118T133250,navigo-kefeed_id namespaces every ID in the feed (navigo-ke:10106110), so two feeds can both have a stop called 1 without colliding. A publish takes a scope (Part 4: country, administrative regions, mode families, operators) and a split: one feed for the whole scope, or one feed per mode family.
Split | Feeds for Kenya | When it helps |
|---|---|---|
|
| One network, one validation, one file to inspect |
|
| Rail timetables and matatu headways have different owners and update rhythms |
Navigo publishes a single national feed today: 134 matatu routes and 11 rail routes in one zip. The split is about operations, not routing. A bad edit to a matatu route then fails validation without blocking a railway timetable change, and the router doesn't care: after the build, it is one network either way.
3. Long-distance services in GTFS
The rail services in the published feed show how different their data is from a matatu's:
Route | What it is | Service |
|---|---|---|
Madaraka Express Inter-County | Nairobi ↔ Mombasa, stopping service | Daily, 08:00 from each end |
Madaraka Express | Nairobi ↔ Mombasa, express | Daily, 15:00 from each end |
Madaraka Night | Nairobi ↔ Mombasa | Daily, 22:00 |
Suswa SGR | Nairobi ↔ Suswa | Weekends, 08:30 out, 15:30 back |
NCR Ruiru, Limuru, Lukenya, Embakasi | Nairobi Commuter Rail | Weekdays, one trip in around 06:15, one out around 17:45 |
NCR Syokimau / SGR Link | Nairobi Central ↔ the SGR terminus | Daily, three trips |
Kisumu and Nanyuki Safari trains | Weekend services on the old metre-gauge lines | Out on Friday, back on Sunday |
These are ordinary timetabled trips: stop_times with real arrival and departure times, route_type = 2 (rail), and calendars like FRI_ONLY and SUN_ONLY. No frequencies.
Coaches and flights fit the same model. GTFS's extended route types give coaches 200–299 and air 1100–1199, and Part 4's export scopes already map both into mode families. What's missing for them is the data, not the model: intercity coach operators in Kenya publish schedules on their websites and booking platforms, not as feeds. Navigo's published feed has no coaches or flights yet. When they come, they will arrive as GTFS like the trains, with the same pipeline.
What GTFS doesn't model at all is availability. A Madaraka Express in December can be sold out days ahead. A journey planner can say "the 15:00 train gets you to Mombasa by 21:00". Saying whether you can get a seat on it needs a booking integration. That is a different product, and the planner should be honest about that boundary.
4. Searching a timetable that runs three times a day
Part 3 showed that a 30-minute search window keeps matatu searches fast. On a long-distance network, that same window has an odd effect.
OTP's Range RAPTOR returns itineraries that depart within the window. Waiting is allowed after that. Two measurements on the same graph as Part 3, both at 07:00 on a Monday, show what that means for long-distance trips:
Search | Window | Time | What it finds |
|---|---|---|---|
Train only, Nairobi Terminus → Mombasa | 30 min | 21 ms | Nothing |
Train only, Nairobi Terminus → Mombasa | 6 h | 21 ms | The 08:00 Inter-County train |
Matatu + train, Westlands → Mombasa | 30 min | 1.9 s | 2 itineraries, both on the 15:00 Express |
Matatu + train, Westlands → Mombasa | 6 h | 21.3 s | 4 itineraries, adding the 22:00 night train |
The first row is the trap. With only trains allowed, there is nothing to board in the first 30 minutes, so the search returns no journey at all, while a train leaves an hour later. The mixed search does find a train, because it boards a matatu inside the window and then waits at the terminus. But it finds only one train, and a traveller choosing between the afternoon express and the night train wants to see both.
So rail-only searches use a different window:
// Rail-only searches look further ahead: trains run a few times a day
// (a 30-min window misses them), and with no matatus in the search it stays fast.
'searchWindow' => str_contains($otpMode, 'BUS') || str_contains($otpMode, 'TRANSIT')
? (int) config('transit.otp.search_window', 1800) // 30 min
: (int) config('transit.otp.rail_search_window', 21600), // 6 hThe two train-only rows took the same 21 ms. With a handful of trains and no five-minute headways, 360 iterations have almost nothing to do. The mixed search is a different story: 6 hours cost 11 times as much as 30 minutes, because the matatus near Westlands are in it. The cost of a window depends on the density of what it searches, not on the window alone.
That suggests the shape of a better long-distance search, which isn't built yet. Plan the trip in two phases: first the long-distance leg on its own, rail only, with a long window (cheap, and it lists every train); then, for each train, the urban access leg with a short window, arriving by the train's departure minus its slack. Two cheap searches replace one expensive one, and the traveller sees every train with a realistic way to reach it. The measurements also show where these trips are weakest today: the itineraries reach the Syokimau terminus by chaining several matatus. That says more about the data around the terminus than about the router.
5. Boarding a train is not boarding a matatu
A matatu stops, you get on. A train has a platform to reach. An SGR terminus has security screening before the platform. An airport has check-in and security, and you collect luggage at the other end. A journey planner that treats all of them like a bus stop produces itineraries that look perfect and miss the train.
OTP models this with slack: extra time required before boarding and after alighting, per mode. Navigo's router config:
"boardSlack": "PT1M",
"boardSlackForMode": {
"BUS": "PT1M", "TRAM": "PT1M", "SUBWAY": "PT2M",
"RAIL": "PT4M", "FERRY": "PT5M", "COACH": "PT10M", "AIRPLANE": "PT45M"
},
"alightSlackForMode": {
"RAIL": "PT2M", "SUBWAY": "PT1M", "FERRY": "PT2M", "AIRPLANE": "PT15M"
},
"transferSlack": "PT2M"
These are deliberately conservative defaults, not measured averages. They encode one asymmetry worth stating: missing a matatu costs five minutes, missing a train costs hours. A planner should be generous with slack in front of rare services and lean in front of frequent ones. A per-station value (the SGR terminus needs more than a commuter halt) would be the natural refinement.
6. Transfers between networks
The places where networks meet are where long trips succeed or fail. Two build settings shape them:
{
"maxTransferDuration": "PT30M",
"transitModelTimeZone": "Africa/Nairobi"
}During the build, OTP walks the street network from every stop to find the stops reachable on foot within maxTransferDuration. In the Kenya graph that produced 57,519 walking transfers from 3,999 stops. They are what connect a matatu stage on Mombasa Road to a railway station a few hundred metres away, without anyone having drawn that connection by hand.
At large stations, the street network isn't enough: the entrance, the ticket hall and the platform are inside a building. GTFS models those with pathways.txt and levels.txt, and the schema in Part 4 stores both. They turn "walk to the station" into "walk to the station, through the entrance, up one level, to platform 2", with honest times.
The timetable also needs one honest check that's easy to miss: service IDs are case-sensitive. While preparing this article, I found two calendars in our own feed, WEEKDAYS (Monday to Friday) and weekdays (every day of the week), each used by a different commuter trip. To the router, they're unrelated services, and one "weekday" train was being offered on Sundays. A validator should flag service IDs that differ only by case.
The same goes for names. The feed has a matatu stop called Mombasa, about 14 km from Nairobi's CBD. Once long-distance services share a search box with urban stops, a query for "Mombasa" has to rank the city and its SGR terminus above a stage that happens to share the name.
7. Where the regions meet the rest of the architecture
The orchestration layer from Part 5 barely changes for long distance, and that's a sign the layers are right:
Dispatch already has a
railmode; "train only" searches use their own window.The itinerary contract already carries route type, agency and headsign, so a Madaraka Express leg renders as a train with its operator's name and colour, not as a bus.
Fares are rules per route, with conditions such as peak hours, resolved by the same fare service as matatus.
The cache is keyed on the request, so a busy Nairobi–Mombasa search in December costs one routing call every five minutes.
What does change is the meaning of "real-time". A matatu's live position matters for the next five minutes. A train's delay matters for the connection at the other end. Neither has a public real-time feed in Kenya today; Navigo's live bus positions are simulated, and the planner says so. When operators publish GTFS-Realtime, OTP consumes it through updaters, and the trip updates flow into the same itineraries. That's the long-distance problem I'd most like to see solved.
In short
At the scale of one country, one graph keeps cross-region trips simple and fits in memory. Split by region when memory, publishing cadence or traffic forces it, and plan for stitching when you do.
Keep feeds modular even inside one graph: per region and per mode, namespaced, validated separately.
Treat long-distance services as a different rhythm: a longer search window when only trains are searched, more slack before rare services, walking transfers generated by the build, pathways inside stations.
Be honest about what GTFS can't say: seats, delays, and whether the stop called Mombasa is in Mombasa.
Part 7: External Mobility APIs, Live Traffic, Boda Bodas and Honest Estimates is about the data a journey planner doesn't own: live traffic, incidents and community reports, and the rules that keep a third-party API from making the product worse when it's slow, expensive or down.
Technical references
OpenTripPlanner:
boardSlackForMode,alightSlackForMode,transferSlack, andmaxTransferDuration.GTFS Realtime and OTP's real-time updaters.





