Order Tracking and Driver Dispatching for Food Delivery
The food delivery app uses client-side order updates plus backend dispatch logic to move an order from cart checkout to restaurant preparation, driver pickup, and delivery completion.
Quick Answer
Customer, vendor, and driver apps update order status from the client when users take actions. The driver assignment step should run on the backend because it needs access to available drivers, restaurant location, distance rules, and dispatch retries.
Order Lifecycle
Typical flow:
- Customer places an order.
- Restaurant receives the order.
- Restaurant accepts or rejects the order.
- If accepted, backend dispatch searches for an available driver.
- Driver accepts or rejects the delivery.
- If rejected, dispatch retries with another eligible driver.
- Driver picks up the order.
- Driver starts delivery to the customer.
- Driver marks the order delivered.
- Customer sees status changes in the tracking flow.
Your product can adjust statuses, timing, and labels, but keep every app aligned with the same backend status model.
Dispatch Function
The dispatch logic usually lives in the Firebase backend included with the app package. Search the backend source:
rg "dispatch|delivery|driver|restaurant_orders|restaurant_deliveries" firebase
Common responsibilities:
- read the accepted order;
- find eligible online drivers;
- compare distance or service radius;
- create/update delivery records;
- notify drivers;
- retry if a driver rejects;
- write status updates for customer tracking.
Deploy Backend Dispatch
From the app's Firebase folder:
firebase login
firebase use --add
firebase deploy --only firestore:rules
firebase deploy --only firestore:indexes
firebase deploy --only functions
Review:
Test Dispatch End to End
Use at least three test accounts:
- customer;
- restaurant owner/vendor;
- driver.
Then test:
- customer places an order;
- vendor accepts the order;
- driver is online and has location data;
- dispatch assigns the order;
- driver accepts the delivery;
- delivery status updates as the driver moves through the flow;
- customer tracking screen reflects each status.
Watch Functions logs while testing:
firebase functions:log
Firestore and Security Notes
Before production, confirm:
- customers can read only their own orders;
- vendors can read and update only their restaurant orders;
- drivers can read and update only assigned deliveries;
- admin users have explicit role checks;
- dispatch Functions use server-side privileges safely;
- broad client-side writes are not allowed.
Troubleshooting
| Problem | Fix |
|---|---|
| Dispatch never runs | Check Functions deploy, trigger path, region, and logs. |
| No driver is assigned | Check driver role, online status, location, and dispatch radius rules. |
| Order status does not update | Check Firestore writes, listeners, and status values used by each app. |
| Customer cannot track delivery | Check delivery document permissions and tracking screen query. |
| Costs rise during testing | Avoid polling loops; use scoped listeners and review Function retries. |