blog

From Webhook to Action: Building an AI Dispatch Layer for Delivery & Ride-Sharing Apps

By khurram August 17, 2026 13 min read
 

The AI dispatch layer is the intelligence at the heart of any delivery or ride-sharing platform — the system that decides, in real time, which driver gets which job, how routes should be updated as conditions change, and how to balance competing demands across the entire operational fleet. Getting this layer right is what separates platforms that scale gracefully from those that require constant manual dispatcher intervention as volume grows. This article covers how to build an AI dispatch layer that works — from the webhook triggers that initiate dispatch decisions, through the matching algorithm, to the driver notification and monitoring infrastructure that closes the loop.

What an AI Dispatch Layer Actually Does

At its core, an AI dispatch layer solves a continuous assignment problem: given a set of available drivers with known positions, capacities, and constraints, and a set of pending orders or ride requests with known origins, destinations, time windows, and priorities, find the assignment that maximises a defined objective function (typically a weighted combination of driver utilisation, estimated time to pickup, on-time delivery rate, and customer wait time).

The real-world complexity comes from the dynamic nature of the problem: drivers become available as they complete jobs, new orders arrive continuously, real-time traffic changes expected transit times, and drivers have connectivity interruptions that cause their position data to lag. The dispatch layer must make good decisions continuously, updating assignments in response to new information, without causing excessive reassignment churn that confuses drivers or degrades customer experience.

Webhook Architecture: Triggering Dispatch Decisions

The Event-Driven Dispatch Model

Dispatch decisions in an effective AI dispatch layer are triggered by state change events, not by polling. The events that trigger dispatch actions: new order received (trigger: initial assignment), driver position update (trigger: re-evaluate nearby pending orders), driver status change — becomes available, goes offline, signals delay (trigger: reassignment of affected orders), order status change — confirmed, picked up, delivered, cancelled (trigger: free driver capacity or trigger reassignment), and customer cancellation (trigger: free driver capacity).

Each of these events arrives as a webhook or message queue event. The dispatch layer subscribes to these events, maintains a current state model of all active drivers and orders, and triggers dispatch decisions when events indicate an assignment opportunity or requirement. This event-driven model is significantly more responsive than a polling-based approach — an order becomes dispatchable immediately on receipt, not at the next polling interval.

Message Queue Architecture

Dispatch events must be processed reliably and in order. Kafka is the standard choice for high-volume dispatch event streaming: it provides durable message storage, consumer group management, and the ability to replay events for recovery or debugging. Topics: driver-location-updates, order-events, driver-status-events, dispatch-actions. The dispatch service consumes from the first three topics and produces to the fourth, decoupling the dispatch logic from the driver notification and order management services that act on dispatch decisions.

AI dispatch layer architecture showing webhook event ingestion driver state management matching algorithm and real-time driver notification pipeline
AI dispatch layer architecture — event-driven webhook processing, real-time driver state management, matching algorithm, and driver notification pipeline

The Matching Algorithm: How the AI Dispatch Layer Assigns Jobs

Proximity-Based Baseline

The simplest effective dispatch algorithm: assign each order to the nearest available driver. This is easy to implement, easy to understand, and works reasonably well at moderate order volume. Its limitations become apparent at scale: nearest-driver assignment is locally optimal (each order is assigned to the best currently available driver) but globally suboptimal (a driver slightly further away might be the better choice if it avoids stranding a different order without coverage). It also doesn’t handle driver capacity for multi-order assignment or time window constraints.

Optimisation-Based Dispatch

Production AI dispatch layers typically use optimisation algorithms that solve the assignment problem across all pending orders and available drivers simultaneously. The Vehicle Routing Problem with Time Windows (VRPTW) is the formal problem statement — it is NP-hard for large instances, which means exact solutions are not computationally feasible in real time. Production systems use heuristic approaches that find near-optimal solutions quickly: greedy insertion (build routes by inserting orders at their cheapest insertion point), simulated annealing (iterative improvement with controlled acceptance of worse solutions), or genetic algorithms (population-based search with crossover and mutation).

Google OR-Tools provides open-source implementations of these heuristics that can solve practical-scale dispatch problems (hundreds of orders, dozens of drivers) in seconds. Commercial route optimisation engines (OptimoRoute, Routific) provide API access to similar capabilities. Our post on AI-Powered Route Optimization in Logistics: Best Practices covers these algorithms in detail.

Machine Learning for ETA Prediction

The optimisation algorithm’s quality is bounded by the accuracy of its time estimates. Real driving times depend on traffic conditions that vary by time of day, day of week, and real-time incidents. ML models trained on historical GPS trace data for your specific operating area provide significantly more accurate ETA estimates than static speed assumptions. Features: distance, time of day, day of week, current traffic speed on the route segments, historical average speed for this route at this time. Gradient boosting models (XGBoost, LightGBM) perform well for this task and train quickly on historical drive time data.

Real-Time State Management

The dispatch layer needs a real-time view of all driver positions, statuses, and current assignments. This state must be: updated with low latency (driver position updates should propagate to the dispatch algorithm within seconds), consistent (the algorithm should never see a state where a driver appears both available and assigned), and durable (driver state should survive dispatch service restarts without requiring drivers to re-register). Redis is the standard choice for this real-time state: sub-millisecond reads, atomic operations for state transitions, and built-in expiry for stale driver entries (drivers who have lost connectivity).

Driver Notification and Acceptance Flow

The dispatch decision must reach the driver and be accepted before the assignment is confirmed. The standard flow: dispatch algorithm selects the best available driver, sends a push notification to the driver app with job details, starts a countdown timer (typically 15–30 seconds), and waits for acceptance or timeout. If the driver accepts, the order is confirmed and the next-nearest driver in the assignment queue is released for other assignments. If the driver declines or times out, the order is reassigned to the next candidate. This flow must be atomic: only one driver can accept each order, even if multiple drivers receive the notification simultaneously due to system latency.

AI dispatch layer driver assignment flow showing job offer notification countdown acceptance timeout and reassignment handling
Driver assignment flow in the AI dispatch layer — job notification, acceptance window, timeout handling, and cascading reassignment

Monitoring and Operations for the AI Dispatch Layer

Key metrics for a production AI dispatch layer:

  • Match rate: Percentage of orders successfully dispatched to a driver — unmatched orders require manual intervention or customer notification
  • Time to first dispatch offer: How quickly after order receipt is a driver offered the job — measures algorithm speed and driver availability
  • Acceptance rate: Percentage of offers accepted on first attempt — low acceptance rate indicates job unattractiveness, driver shortage, or notification delivery issues
  • ETA accuracy: Predicted vs actual driver arrival time — measures ETA model quality
  • Reassignment rate: How often orders require reassignment after initial dispatch — high reassignment rates indicate driver availability problems or ETA inaccuracy

Alerts should fire when match rate drops below threshold (driver shortage or system issue), when time to dispatch spikes (algorithm performance issue or high order volume), or when ETA accuracy degrades significantly (traffic model drift or data quality issue).

Building for Multi-City and Multi-Mode Dispatch at Scale

A dispatch layer that works correctly for a single city with a homogeneous fleet is a solved problem. The engineering complexity emerges when the same infrastructure must serve dozens of cities simultaneously, handle multiple vehicle types with different matching rules, adapt to radically different demand patterns by geography, and do all of this without a single central bottleneck that becomes the system’s failure point. This section covers the architectural decisions that make an AI dispatch layer genuinely scalable across cities and transport modes.

City-Level Partitioning and Data Isolation

The most important scaling decision in a multi-city AI dispatch layer is where to draw the partition boundary. Naive implementations use a global driver state store and run all dispatch decisions in a single service. This works up to the point where cross-city traffic — drivers near city boundaries, airport routes that span zones — becomes significant, and then the global state creates consistency problems that are expensive to resolve.

The production pattern is city-level partitioning with controlled boundary handling. Each city maintains its own driver state partition in Redis — a separate keyspace or Redis instance per city. Dispatch decisions for orders within a city run entirely within that partition, with no cross-city data reads required. Orders that originate near a city boundary trigger a boundary expansion query: if no suitable driver is found within the primary city partition within a configurable timeout (typically 500ms), the system queries adjacent city partitions with a reduced candidate threshold.

This partition-first approach gives the system horizontal scalability — adding a new city adds a new partition, not load on existing ones — while the boundary expansion handles the edge cases that pure partitioning cannot.

Multi-Mode Dispatch: Different Vehicle Types, Different Rules

Platforms that dispatch multiple vehicle types — motorcycles, cars, cargo vans, refrigerated vehicles — cannot use a single matching algorithm with vehicle type as a filter. Each mode has structurally different matching economics that require mode-specific configuration.

Motorcycle dispatch in dense urban environments optimises heavily on proximity — a motorcycle 400 metres away in a traffic-free direction is worth more than a car 600 metres away even if the car has a higher rating. Van dispatch for cargo optimises on load capacity fit and route efficiency — a van that is already running a multi-stop route in the right direction is preferred over a closer van with no current route. Cold-chain refrigerated dispatch adds constraint checking that other modes skip entirely: is the vehicle currently at temperature, what is the remaining capacity in refrigerated compartments, and does the vehicle’s current route keep total cold-chain transit time within the required window?

Implement multi-mode dispatch as a mode-specific scoring configuration, not as code branches. Each mode defines its scoring weights (proximity, rating, acceptance rate, load fit, route compatibility) as a configuration object. The matching engine reads the order’s required mode, loads the corresponding configuration, and executes the same scoring algorithm with different parameters. This keeps the matching engine code unified while supporting arbitrarily different matching behaviour per mode.

Demand Forecasting: Proactive Driver Positioning

Reactive dispatch — match available drivers to arriving orders — is necessary but not sufficient at scale. A reactive-only dispatch layer is always one demand spike behind the market, resulting in high match latency and poor customer experience during predictable high-demand periods. Demand forecasting closes this gap.

The production demand forecasting approach uses a gradient boosting model (XGBoost or LightGBM) trained on historical order volume per zone per hour, enriched with contextual features: day of week, local events calendar, weather data, and proximity to known demand generators (offices, transit hubs, restaurant clusters). The model produces a 15–30 minute forward-looking demand estimate per zone, updated every 5 minutes.

This forecast feeds two downstream systems. First, a driver incentive engine: zones predicted to go into supply shortage receive surge pricing or bonus incentives for nearby available drivers, encouraging voluntary repositioning before the shortage materialises. Second, a fleet positioning recommendation system: for platforms with employed or contracted drivers on shift, the dispatch layer can recommend repositioning moves — push 5 drivers from Zone A (predicted oversupply) to Zone B (predicted shortage) — displayed to the operations team as a suggested action rather than an automated command.

The measurable impact of demand forecasting on dispatch performance: match latency reduction of 15–25% during predicted high-demand periods, compared to reactive-only dispatch. The improvement is larger for longer-cycle demand spikes (lunch rush, post-event dispersal) than for sudden demand spikes that forecasting cannot anticipate.

Failover and Degraded-Mode Operation

A dispatch layer that fails completely when its ML model is unavailable is unacceptable for an operational platform. Production dispatch infrastructure requires defined degraded-mode behaviour for each dependency failure.

When the ML matching model is unavailable (model server down, inference timeout): fall back to the rule-based baseline immediately, without manual intervention. The rule-based baseline is always running in parallel — its output is discarded when ML is available and used directly when ML is not. This fallback adds approximately 10–15% to average match time but keeps the platform operational.

When the Redis driver state store is degraded: switch to a PostgreSQL-backed driver state read path, which is slower but consistent. Pre-warm this fallback read path with a 30-second cache so that the first queries on failover do not hit a cold database. Alert operations and set a maximum failover duration — if Redis is not restored within 10 minutes, escalate to on-call infrastructure.

When the Kafka queue is unavailable: fall back to synchronous dispatch processing in the webhook handler, accepting the latency increase and throughput reduction as a temporary degradation rather than dropping orders. Queue all decisions to a dead-letter store for replay once Kafka recovers.

AI dispatch layer multi-city scaling showing city partition architecture demand forecasting driver positioning and degraded mode failover patterns
AI dispatch layer at scale – city partitioning, multi-mode scoring configuration, demand forecasting, and degraded-mode failover for production resilience

Frequently Asked Questions

At what order volume does a simple nearest-driver algorithm need to be replaced?

Nearest-driver dispatch works adequately up to roughly 50–100 concurrent orders with 20–40 drivers. Above this, the globally suboptimal nature of nearest-driver assignment produces measurably worse utilisation and customer wait times compared to optimisation-based dispatch. The specific threshold depends on your geography, order clustering, and the time sensitivity of your deliveries.

How do you handle surge demand in the AI dispatch layer?

Surge handling operates at multiple levels: the dispatch algorithm should deprioritise non-urgent orders during shortage periods, surge pricing incentivises additional driver supply, and demand forecasting (trained on historical order patterns) allows pre-positioning of drivers near anticipated high-demand areas before surge begins. Real-time demand vs supply imbalance metrics drive both the pricing and the pre-positioning decisions.

How do you test an AI dispatch layer without affecting live operations?

Shadow mode: run the new dispatch algorithm alongside the production algorithm, generate dispatch decisions from both, but only act on the production algorithm’s decisions. Compare the shadow algorithm’s decisions against production decisions on the same real-world state. Over time, compare the simulated outcomes of shadow decisions against actual production outcomes. This approach validates algorithm changes without operational risk.

Conclusion

An AI dispatch layer is the operational intelligence that determines whether a delivery or ride-sharing platform scales smoothly or requires increasing dispatcher intervention as volume grows. The foundations — event-driven webhook architecture, real-time state management, optimisation-based assignment, and ML-powered ETA prediction — are well-understood, but require careful implementation to work reliably in production. The platforms that invest in this infrastructure early find that it becomes a compounding operational advantage; those that defer the investment find themselves rebuilding their dispatch logic under operational pressure.

If you are building a dispatch layer for a delivery or ride-sharing platform and want to discuss the matching algorithm or infrastructure architecture, get in touch with the Lycore team. Related architecture patterns are also covered in our post on Handling Peak Season Traffic in Delivery Management Systems.