Skip to main content

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:

  1. Customer places an order.
  2. Restaurant receives the order.
  3. Restaurant accepts or rejects the order.
  4. If accepted, backend dispatch searches for an available driver.
  5. Driver accepts or rejects the delivery.
  6. If rejected, dispatch retries with another eligible driver.
  7. Driver picks up the order.
  8. Driver starts delivery to the customer.
  9. Driver marks the order delivered.
  10. 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:

  1. customer places an order;
  2. vendor accepts the order;
  3. driver is online and has location data;
  4. dispatch assigns the order;
  5. driver accepts the delivery;
  6. delivery status updates as the driver moves through the flow;
  7. 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

ProblemFix
Dispatch never runsCheck Functions deploy, trigger path, region, and logs.
No driver is assignedCheck driver role, online status, location, and dispatch radius rules.
Order status does not updateCheck Firestore writes, listeners, and status values used by each app.
Customer cannot track deliveryCheck delivery document permissions and tracking screen query.
Costs rise during testingAvoid polling loops; use scoped listeners and review Function retries.

Next Steps