Why we split dispatch out of Zapp
Every five seconds, thousands of delivery riders in Karachi, London, Birmingham, Finland and Singapore tell us where they are. On game nights at Nokia Arena, that stream of updates used to bring our database to its knees. This is the story of how we fixed it inside Zapp, then lifted the fix out into Zapp Dispatch, a standalone service that businesses outside Zapp now use too.
Zapp is a multi-vendor food delivery and quick-commerce platform. It runs in Karachi, London, Birmingham and Finland, and at Nokia Arena in Tampere, where fans order to their seats and to the streets around the venue. Zapp's dispatch system began as part of the platform. It decided which rider took which order, in what sequence, and when each stop would happen.
Once that dispatcher worked at Zapp's scale, we split it out into Zapp Dispatch, a separate service with its own API. Any business can send it orders, pickup and drop-off points, and rider positions, and get back who should deliver what, in which order, and when. Zapp itself still runs on it. Mustafa Centre in Singapore, a large retailer that runs its own delivery fleet, was the first business outside Zapp to adopt it.
To get here we had to solve two scaling problems and one product problem:
Location writes. Thousands of riders each send a position every 5 seconds. That load first broke PostgreSQL. Redis fixed it, and Kafka then made it scale.
Hot areas. Central London and Birmingham carry far more riders and orders than everywhere else. We split the map into geohash cells and assign cells to Kafka partitions by load, not by area, so one busy area can't hold up the rest.
One product, many customers. Each tenant gets its own rules, scoring, travel model and webhooks through configuration rather than code changes. Each rider belongs to exactly one tenant, and rider locations stay in the region where they were collected.
The rest of this article covers how each piece works and why we built it that way.
Where we started
Zapp's first version kept rider positions in a PostgreSQL table, and that was the right call until match days made it the wrong one. Every rider app sent its position every 5 seconds, and each ping became an UPDATE on that rider's row plus an INSERT into a history table.
The maths is simple: riders ÷ 5 seconds = writes per second. At our peak that was 10,000 position writes a second (about 50,000 riders online), before a single order is read. At that rate PostgreSQL was spending its time on the wrong things:
Row churn. Every update writes a new row version. Autovacuum fell behind, tables bloated and the spatial index grew with them.
Write-ahead log volume. Each update also hit the log and the replicas, so replica lag grew just when we needed fresh positions.
Contention with real work. Order creation, checkout and the "find the nearest rider" query all shared the same database. On game nights at Nokia Arena, customers placing orders and the dispatcher looking for riders competed with thousands of pings.
Expensive nearest-rider queries. A distance query over a table that changes 10,000 times a second keeps the index constantly churning. Its cost grew with the number of riders online, so it was most expensive exactly when it ran most often.
We fixed it in two steps, each described below. First, Redis took over the current positions so PostgreSQL only kept history. Then Kafka sat in front of everything so ingestion, live state and history could each scale on their own.
Each stage took work off the ping's path: first the database, then the API servers.
Three very different customers, one product
The dispatcher only became a product when we stopped writing code for Zapp alone and started writing configuration for every business that uses it. These are the three tenants that shaped it:
| Zapp marketplace: Karachi, London, Birmingham, Finland | Mustafa Centre, Singapore | Zapp at Nokia Arena, Tampere | |
|---|---|---|---|
| Who orders | Customers, from many vendors | Customers of one large retailer | Fans in their seats and in the streets nearby |
| Who delivers | Shared pool of riders across all vendors | Mustafa Centre's own drivers | Venue runners inside; riders outside |
| Typical order | 1–3 items, hot or chilled, 20–40 min promise | Larger baskets, booked time slots | Small, very time-sensitive, often to a seat |
| What matters most | Speed and rider utilisation | Hitting the booked slot, van capacity | Coping with the rush before the game and in the intervals |
| Travel model | Road network (bike, scooter, car) | Road network (van) | Venue walking graph inside, road network outside |
| Batching | Stack 2–3 orders on one rider when on the way | Multi-stop routes planned per wave | Group orders by block and section |
The same planning engine serves all three. What changes per tenant is the data it is given and the policy it applies: which riders it may consider, how it scores them, how it estimates travel and which hard rules can never be broken.
Architecture overview
Zapp Dispatch is built around two separate paths, one for rider locations and one for planning requests, which share only Redis. The location path takes thousands of small writes a second and must never slow down. The planning path takes far fewer requests but does heavy work on each.
Planning workers also write each result back to PostgreSQL. The outbox publishes it as a webhook, and the tenant can poll for it as well. Kubernetes runs and scales every Go service shown here. It is the deployment layer, not part of the design.
| Component | Responsibility |
|---|---|
| Ingest gateway | Accepts pings, authenticates devices, validates fixes, keys each ping by shard |
| Location consumers | Keep Redis current, write the reduced trail, raise geofence events |
| Planning API | Accepts, returns, accepts or cancels plans; applies idempotency and tenant config |
| PostgreSQL | Durable plans, commitments, configs, shard map, outbox |
| Planning workers | Run the engine: search, filter, travel estimates, insertion and scoring, leasing |
| Travel providers | OSRM per road profile; venue walking graphs; straight-line fallback |
| Redis | Live positions, fleet geo indexes, commitments ledger, leases, travel matrix cache |
| Simulator | Replays recorded days through the same engine for testing |
The location pipeline
A rider's position is written once, to Kafka, and everything else reads it from there. Live state lives in Redis, history in PostgreSQL. Neither one sits in the ping's critical path.
Step 1: Redis for live positions
The first fix was to stop treating "where is rider 42 now?" as a database row. Current positions moved to Redis:
GEOADDinto a geo set per area, so "riders within 2 km of this restaurant" became aGEOSEARCHin memory instead of a spatial query on a hot table.A small hash per rider (
lat,lng,heading,speed,accuracy,ts,status) with a TTL. A rider who stops sending simply disappears from search.PostgreSQL received history in batches every few seconds instead of one write per ping.
That took the write load off PostgreSQL entirely. It also exposed the next limits. The API servers wrote straight to Redis, so a slow Redis meant slow pings. History, analytics and ETA tracking each wanted their own copy of the stream. And one city's geo set became a hot key.
Step 2: Kafka in front
We put Kafka between the riders and everything that cares about them:
Ingest gateway. A thin Go service accepts pings over HTTPS or a long-lived WebSocket, authenticates the device, and validates the fix. It rejects anything with a future timestamp, a stale timestamp, poor accuracy, or a jump implying an impossible speed. Then it publishes to
location.pingsand returns. It never touches Redis or PostgreSQL.Partitioning. The message key is the rider's shard, a group of geohash cells described in the next section. All pings for one area land on one partition, in order.
Live-state consumers read each partition and update Redis. Updates go through a short Lua script that only applies a ping if its timestamp is newer than the stored one. Pings can arrive out of order when a rider crosses into another shard, and the newest fix must always win.
History writer batches pings into a PostgreSQL table partitioned by day. It keeps a reduced trail (one point every 30 seconds or on a significant turn) for proof of delivery and dispute handling. Raw pings expire quickly.
Other consumers (ETA tracking for the customer's map, geofence events such as "rider arrived at restaurant", analytics) subscribe to the same topic with their own consumer groups. None of them can slow down ingestion.
The ping
json{
"rider_id": "rdr_8f2k",
"device_ts": "2026-11-16T19:42:05.120Z",
"lat": 51.5072, "lng": -0.1276,
"accuracy_m": 8, "speed_mps": 4.1, "heading": 270,
"battery": 0.64, "seq": 18233
}
The gateway adds received_ts, the tenant and fleet memberships resolved from the device token, and the geohash cell. Consumers never have to look those up again.
What lives where
| Store | Holds | Kept for | Read by |
|---|---|---|---|
Kafka location.pings | Every accepted ping | 24 hours | All location consumers; replay after incidents |
| Redis | Latest position, status and cell per rider; geo sets per fleet and cell | Until TTL (60 s without a ping) | Candidate search, live tracking |
| PostgreSQL | Reduced trail per rider per shift | Per tenant policy | Proof of delivery, disputes, reporting |
If Redis is lost, consumers rebuild it by replaying the last few minutes from Kafka. That takes seconds, because only the newest ping per rider matters.
Hot zones: splitting the map by load, not by area
Traffic is not spread evenly across the country, so the map isn't split evenly either. A few square kilometres of central London or central Birmingham can carry more riders and orders than a whole town. Partitioning by city or by fixed grid put all of that on one partition and one consumer, while partitions covering quiet areas sat idle.
Geohash cells
A geohash turns a coordinate into a short string. Each extra character divides the cell into 32 smaller ones, and nearby points share a prefix. We use 5-character cells (such as gcpvj) by default and split busy ones into 6-character cells (such as gcpvjb). The same cell is a different shape in each place we serve:
| Where | Latitude | 5-character cell (wide × tall) | 6-character cell (wide × tall) |
|---|---|---|---|
| Singapore | 1.3° N | 4.9 × 4.9 km | 1.2 × 0.6 km |
| Karachi | 24.9° N | 4.4 × 4.9 km | 1.1 × 0.6 km |
| London, Birmingham | 51.5–52.5° N | 3.0 × 4.9 km | 0.75 × 0.6 km |
| Tampere | 61.5° N | 2.3 × 4.9 km | 0.58 × 0.6 km |
A cell in Tampere is about half as wide as the same cell in Singapore.
Cells get narrower east to west the further you are from the equator. So nearby search is sized in metres and turned into a set of cells, never the other way round.
Shards and the shard map
A shard is a group of cells that one partition handles. The shard map says which cells belong to which shard:
Quiet areas are grouped coarsely. One shard can cover dozens of precision-5 cells across a whole region.
Busy areas are grouped finely. A hot precision-5 cell in Soho or around Birmingham New Street is split into its 32 precision-6 children, which are spread over several shards.
Shards are balanced on measured load (pings per second plus planning requests per second over the last two weeks, peak hour), not on area.
The ingest gateway looks up each ping's cell in the shard map and uses the shard ID as the Kafka key. Shards are assigned to a fixed number of partitions (we run 96), so adding shards never means repartitioning the topic.
Split by area, a busy cell such as central London and its neighbours all land on one partition, and that partition falls behind while the others sit idle. Split by load, the busy cell is divided and quiet cells are grouped, so each partition carries a similar share.
Rebalancing without losing order
The shard map is versioned and stored in PostgreSQL, with a copy cached by every gateway and consumer.
A nightly job proposes a new map from the last two weeks of load. Engineers can also pin a map ahead of a known event, such as a match day.
The new version is published with an activation time a few minutes ahead.
From that time, gateways key pings by the new map. For a short overlap, consumers accept pings for a rider from both the old and new shard, and the newest-timestamp-wins rule in Redis resolves any reordering.
Searching near a point
To find riders near a pickup, we take the cell containing the pickup plus its 8 neighbours, then widen ring by ring until there are enough candidates or the tenant's maximum radius is reached. Searching only one cell misses a rider 50 metres away across a cell edge. The neighbours always come along.
Who owns a rider's coordinates
Every rider works for exactly one company, so ownership is simple: the tenant owns its riders, and only that tenant can see them. A rider can belong to several fleets inside the same tenant, such as bikes and scooters in the same city, but never to two companies. That one rule removed a whole class of problems: shared availability, cross-company leakage and conflicting assignments.
Each company's plans search only its own fleets. Nothing in Zapp Dispatch connects one company's riders to another's.
The model
| Concept | What it is | Example |
|---|---|---|
| Tenant | A business with its own API credentials, config and data | Zapp; Zapp at Nokia Arena; Mustafa Centre |
| Sub-tenant | A business operating inside a tenant | A vendor on Zapp; a kiosk at Nokia Arena |
| Fleet | A pool of riders dispatched together under one set of rules | "London bikes", "Mustafa Centre vans", "Arena runners" |
| Rider | One person with one device and one location stream, belonging to one tenant | A Zapp courier in Karachi |
| Membership | Rider × fleet within the rider's own tenant, with a status (active, on_shift, paused) | A Zapp courier in both the bike and scooter fleets |
| Commitment | Work a rider has accepted: stops, capacity used, deadlines | Two orders picked up, one drop-off left |
Rules we enforce
One tenant per rider, enforced at the door. A rider's device token is issued for one tenant. The gateway rejects any ping, or any relay batch, that names a rider belonging to a different tenant.
Indexes are scoped to the tenant. The live-state consumer adds the rider to a Redis geo set per fleet and cell (
geo:{fleet}:{cell}), only for the fleets they are on shift for. Candidate search reads only the calling tenant's fleet sets, so it physically cannot return another company's riders.Position is visible only on shift. Off shift, a rider is removed from every fleet index and the API returns no position.
Assignments are leased. Two plans in the same tenant can still want the same rider, for example when fleets overlap or orders sit near a shard edge. When a plan proposes a rider, Zapp Dispatch places a short lease on them (a Redis
SET NXwith a TTL of about 30 seconds). Acceptance turns the lease into a commitment.
Where positions come from
Tenants don't all have the same rider app, so Zapp Dispatch accepts positions three ways and treats them identically once they arrive:
Zapp Dispatch rider SDK. The rider app sends pings straight to the ingest gateway. Used by the marketplace and Nokia Arena.
Server relay. The tenant's backend forwards positions from its own app in batches. Used by Mustafa Centre, whose vans already report to its fleet system.
Inline with a plan. The planning request carries rider positions itself. This suits tenants who want Zapp Dispatch to be stateless. If a request carries a position older than the one Zapp Dispatch already has, the newer one wins, and the response says which was used.
Every result records the timestamp of each position it used. The calling application can always tell how fresh the plan was.
The planning service
The planning service answers one question: given these orders and these riders, who should take what, in which order, and when will each stop happen? It is independent of every tenant's systems. It needs nothing but the request and the live state described above.
API
| Call | Purpose |
|---|---|
POST /v1/plans | Submit orders (and optionally riders). Returns 202 with a plan ID, or the result directly if mode=sync and it finishes within the tenant's time budget. |
GET /v1/plans/{id} | Status (queued, planning, proposed, accepted, expired, cancelled) and the result. |
POST /v1/plans/{id}/accept | Confirm the proposal. Turns rider leases into commitments; fails with 409 if a lease expired or a rider's state changed. |
DELETE /v1/plans/{id} | Cancel a queued plan or release a proposal. |
POST /v1/riders/{id}/commitments/{stop}/complete | Mark a stop done so the rider's remaining capacity and route update. |
Webhook plan.proposed, plan.expired | Pushed to the tenant when a result is ready or a proposal lapses. |
Every POST takes an Idempotency-Key header. Retries never create a second plan.
jsonPOST /v1/plans
{
"fleet": "london-bikes",
"orders": [{
"id": "ord_A", "vendor": "v_123",
"pickup": {"lat": 51.5136, "lng": -0.1365, "ready_at": "2026-11-16T19:50:00Z"},
"dropoff": {"lat": 51.5202, "lng": -0.1410, "deliver_by": "2026-11-16T20:15:00Z"},
"size": 2, "tags": ["hot"], "priority": "normal"
}],
"riders": "live"
}
Inside a plan
Load policy. Fetch the tenant's config (next section) for this fleet.
Find candidates. For each pickup, search the fleet's geo sets: the pickup's cell and its neighbours, widening up to the policy radius. Riders already committed nearby are included, so new orders can be added to existing routes.
Filter on hard rules. Remove riders who would break a rule: vehicle type, capacity, a tag the rider can't carry (
hotwithchilled, age-checked items without a verified rider), a zone they may not enter, a shift that ends too soon.Estimate travel. Request a travel matrix only for the surviving riders and stops. This is a single OSRM
tablecall per plan, cached in Redis by rounded origin, destination, profile and time-of-day bucket. If OSRM is unavailable, the plan falls back to straight-line distance × a per-profile detour factor, and the result is markedtravel_source: "estimate".Insert and score. For each candidate, try inserting the new pickup and drop-off into every valid position in the rider's existing route. Discard insertions that break a deadline or capacity. Score the rest using the tenant's weights: added travel time, lateness risk, rider idle time, fairness.
Resolve conflicts across orders. When several orders arrive together, a greedy pass assigns the best pair first, then re-scores. For Mustafa Centre's scheduled waves, the engine runs a short local search instead, within the time budget.
Lease and propose. Lease the chosen riders, write the result, emit
plan.proposedthrough the outbox.
If the business doesn't accept before the lease expires, the rider is released and the order goes back into planning.
For a request with two nearby orders, A and C, a result looks like this: assign rider B; collect A, collect C, deliver A, deliver C; ETAs for each stop, the position timestamps used and the travel source.
Keeping concurrent plans apart
Planning jobs go through Kafka keyed by fleet + shard. Two requests that could compete for the same riders are processed one after the other by the same worker. Requests for different areas run in parallel on different workers. The rider lease in step 7 is the second line of defence for riders near a shard edge or shared between fleets.
Keeping integrations light
Businesses send each fact once, and Zapp Dispatch keeps the state. Early integrations put every rider position and every address into each planning request. That worked in testing, but it turned every business into a relay for thousands of coordinates, sent the same data over and over, and meant positions were already old on arrival.
| What | How it reaches Zapp Dispatch | How often |
|---|---|---|
| Rider positions | Rider SDK straight to the ingest gateway, or a bulk relay of riders who moved | Adaptive: every 5 s moving, every 30 s parked |
| Pickup points | Registered once as places | When a place opens, moves or closes |
| Drop-off points | With the first order, then saved as an address ID; or text, geocoded by Zapp Dispatch | Once per new address |
| Orders | Small events: created, ready, picked up, cancelled | On each change |
| Assignments | Webhooks back to the business | On each change |
Rider positions: not the business's job
The rider app includes the Zapp Dispatch SDK and sends pings directly to the ingest gateway, so the business sends no rider positions at all. Pings are adaptive: every 5 seconds while moving, every 30 seconds when parked, and never for movements under 25 metres. Most of a rider's shift is spent waiting at a pickup or a door, so this cuts ping volume sharply without making moving riders any less fresh.
Businesses whose drivers already report to their own fleet system, like Mustafa Centre's vans, use POST /v1/riders/positions:batch. They send only riders whose position changed, up to 1,000 per call, compressed.
Pickups: registered once as places
Restaurants, dark stores, Mustafa Centre's store and the kiosks at Nokia Arena are created once with POST /v1/places. Each gets an ID, coordinates, opening hours and the profile riders use to reach it. Orders then refer to plc_123 instead of repeating coordinates. Because pickups never move, their travel times stay in the cache and are reused across thousands of plans.
Drop-offs: sent once, then remembered
A new customer's address is sent once, with the order. The business can ask Zapp Dispatch to keep it as an address ID for repeat orders. Saved addresses follow the tenant's retention policy, because a home address is personal data. A business that only has text addresses can send the text and let Zapp Dispatch geocode it and cache the result. At Nokia Arena, the drop-off is a seat reference such as Block 112, Row K, Seat 14, which resolves to its point on the venue graph.
Orders: events, not snapshots
Instead of resubmitting the whole picture, the business sends what changed:
order.createdwith the pickup place, the drop-off and the deadlines.order.readywhen the kitchen or picker is done, so the planner can tighten the pickup time.order.cancelledif the customer cancels. The rider's route is re-planned without it.
Zapp Dispatch collects the events in the tenant's planning window (the micro-batch or wave from its config), plans continuously against live rider state, and sends plan.proposed by webhook. The stateless POST /v1/plans call still exists for businesses that want to supply everything themselves, but nobody has to.
What an order looks like now
Before, each request carried rider positions and full coordinates for every stop. Now a typical order event is this:
json{
"type": "order.created",
"id": "ord_A",
"pickup": "plc_123",
"dropoff": { "address_id": "adr_77" },
"ready_at": "2026-11-16T19:50:00Z",
"deliver_by": "2026-11-16T20:15:00Z",
"size": 2, "tags": ["hot"]
}
There are no rider positions and no repeated coordinates. Businesses with large volumes can send the same events in batches, over gRPC, or by pointing Zapp Dispatch at a Kafka topic they already publish to.
Making it customisable
Each tenant's behaviour is a versioned config document, not a code branch. The engine has one code path, and everything that differs between the marketplace, Mustafa Centre and Nokia Arena is data it reads at the start of each plan.
What a tenant can change
| Area | Options | Marketplace | Mustafa Centre | Nokia Arena |
|---|---|---|---|---|
| Candidate search | Start radius, max radius, min candidates | 1.5 km → 5 km | 3 km → 25 km | Whole venue inside; 2 km outside |
| Hard rules | Capacity units, vehicle types, incompatible tags, zones, shift cut-off | Hot and chilled not mixed | Van volume and weight | Restricted zones during play |
| Scoring weights | Travel time, lateness, idle time, fairness, distance from home base | Lateness and travel | Slot adherence | Lateness above all |
| Batching | Max orders per rider, max extra minutes for the first customer | 3 orders, +6 min | Whole wave per van | Up to 6 orders in one section |
| Travel profile | OSRM profile, venue graph, detour factor fallback | bicycle, car | van | Venue graph + foot |
| Planning mode | Per order, micro-batch window, scheduled waves | 15 s micro-batch | Waves at fixed times | 10 s micro-batch on game nights |
| Notifications | Webhook URLs, events, signing secret | Yes | Yes | Yes |
Config example
yamltenant: nokia-arena
fleet: arena-runners
region: eu-north
version: 14
search:
start_radius_m: 300
max_radius_m: 2000
min_candidates: 5
rules:
capacity_units: 6
incompatible_tags: [[hot, chilled]]
restricted_zones:
- id: rinkside
when: in_play
travel:
inside_venue: venue_graph:nokia-arena-v3
outside_venue: osrm:foot
fallback_detour_factor: 1.4
scoring:
lateness: 0.6
travel_time: 0.25
idle_time: 0.1
fairness: 0.05
planning:
mode: micro_batch
window_seconds: 10
hooks:
score_adjust:
url: https://hooks.arena.example/zapp/score
timeout_ms: 150
on_timeout: ignore
Rules for customisation
Configs are versioned and validated. A new version is checked against the schema and replayed against a sample of yesterday's plans in the simulator before it goes live. Every plan records which config version produced it.
Tenant code never runs inside Zapp Dispatch. Where a tenant needs logic the service can't express (a loyalty boost for certain riders, a vendor-specific blackout), Zapp Dispatch calls their hook with a strict timeout and carries on without it if the hook is slow or down.
New rules go into the engine once, behind a config switch. When Nokia Arena needed restricted zones, the feature became available to every tenant, off by default.
Nokia Arena: delivery inside a building
Nokia Arena in Tampere is the tenant that tested every assumption. GPS is poor under a roof, demand arrives all at once, and the shortest route is up a staircase, not along a road.
A venue graph instead of roads. Inside the ground, OSRM is replaced by a walking graph of the venue: concourses, stairs, lifts, gates, kiosks and seating blocks as nodes, with walking times on the edges. A drop-off is a seat reference (Block 112, Row K, Seat 14), which resolves to its nearest graph node. The graph plugs in as a travel profile, so the engine doesn't know or care that it's indoors.
Bluetooth beacons instead of GPS. Inside, Bluetooth beacons are mounted along concourses, stairwells and section entrances. The runner app hears the nearest beacons and reports which one is strongest. The pipeline treats each beacon report as a ping with a large accuracy radius, snapped to the beacon's node in the venue graph. Outside the ground, the same runners and street riders use normal GPS pings.
The phone hears several beacons, and the strongest one places the runner on the arena's walking map.
Peaks you can see coming. Orders arrive in sharp bursts before the game starts, during the intervals and at the end. Because the event calendar is known in advance:
The shard map for the area around the arena is pinned to a fine-grained version from two hours before the doors open.
API and worker replicas are scaled up on a schedule 30 minutes ahead of each peak, rather than waiting for the autoscaler to react to lag.
The venue graph's travel matrix is pre-computed and loaded into memory, so game-night plans make no external travel calls at all.
Batching by section. The micro-batch window collects orders for 10 seconds, groups them by stand and section, and gives each runner a loop through one area. Restricted zones (rink-side walkways) are removed from the graph while play is on.
The result is that Nokia Arena's game-night load never reaches PostgreSQL. That was the very load that broke the original design.
Reliability, scaling and observability
Every part of Zapp Dispatch is designed to degrade to a slightly worse plan rather than to no plan.
How each part fails safely
| If this fails | What happens | Plans still work? |
|---|---|---|
| Ingest gateway pod | Rider app retries against another pod; pings are small and replaceable | Yes |
| Kafka broker | Replication factor 3, min.insync.replicas=2; producers retry | Yes |
| Live-state consumer lags | Positions go stale; plans use them and report their age; alert on lag per shard | Yes, with older positions |
| Redis | Rebuilt from the last minutes of Kafka; planning pauses for seconds, not minutes | Briefly delayed |
| OSRM | Straight-line × detour factor, result marked estimate | Yes, less accurate ETAs |
| Tenant hook | Skipped after its timeout | Yes |
| Webhook endpoint | Retried with backoff from the outbox for 24 hours; tenant can also poll | Yes |
| PostgreSQL primary | Failover to replica; outbox resumes from the last committed event | Briefly delayed |
Scaling
Gateways and API scale on CPU and request rate. They hold no state.
Location consumers scale up to one per partition. Hot areas are already spread across several partitions by the shard map, so one consumer is never stuck with all of central London.
Planning workers scale on Kafka lag of the planning topic, with scheduled scale-ups for known events (game nights, Friday evenings).
OSRM runs one cluster per region and profile, with the Redis matrix cache in front. Most repeated pickup areas (busy restaurants, Mustafa Centre's store) are served from cache.
What we watch
Ping ingest rate and rejection rate per shard (a spike in rejections usually means an app release with a GPS bug).
Consumer lag per partition, in seconds rather than messages.
Position age at planning time, per fleet (p50, p95).
Plan latency per tenant, split into search, travel and engine time.
Share of plans using the travel fallback.
Proposed-to-accepted ratio and lease expiries, which show whether tenants act on plans in time.
Predicted vs actual arrival time per stop. This is the number that tells us whether the plans are any good.
Testing with the simulator
The simulator replays recorded days through the real engine with synthetic riders and orders. That includes a full game night at Nokia Arena and a Friday night in central London. Every engine change and every tenant config change is run against these recordings before release, and we compare lateness, travel time and plan latency with the previous version.
Lessons learned and what comes next
Lessons
Separate the write path from the read path early. The ping should be accepted and acknowledged before anything clever happens. Everything that went wrong at the start came from doing real work inside the ping request.
Partition by load, not by geography. Cities aren't uniform, and neither are their partitions. A shard map you can rebalance mattered more than the choice of geohash precision.
One rider, one company, one stream. Each rider belongs to one company and has one location stream. Keeping it that way made isolation a property of the data rather than of every query.
Put freshness in the result. Every plan says how old its positions were and where its travel times came from. Most support questions are answered by those fields alone.
Customise with data, not branches. Every tenant-specific request became a config option or a hook. The engine still has one code path.
Next
Learned travel times. Correct OSRM estimates with the actual-vs-predicted data we already collect, per cell and hour, especially for the last 100 metres (finding a flat, a building entrance or a seating block in an arena).
Rider-side ETAs. Push updated ETAs to customers from the live-state stream, not just at planning time.
Self-serve onboarding. A tenant console for configs, fleets, webhooks and simulator runs, so a new business can go live without an engineer.