# Pubnub Order Delivery Driver

> Build real-time order tracking and delivery driver systems with PubNub

- Skill: `pubnub/pubnub-order-delivery-driver` (Agent Skill, multi-file: 23 files)
- Install (CLI): `npx skillmds@latest add pubnub/pubnub-order-delivery-driver`
- Raw SKILL.md: https://api.skillmd.com/api/skills/pubnub/pubnub-order-delivery-driver/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- License: PubNub
- Author: pubnub (https://skillmd.com/u/pubnub)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/pubnub/pubnub-order-delivery-driver

---


<!-- xrefs-injected -->

> **Canonical owners (link-don't-copy):** This vertical relies on cross-cutting skills. Always link to the canonical owner instead of duplicating. Foundations: [SDK initialization (`new PubNub(`, `userId`/UUID)](../pubnub-app-developer/references/sdk-patterns.md), [pub/sub basics (`pubnub.publish(`, `pubnub.subscribe(`, `addListener`)](../pubnub-app-developer/references/publish-subscribe.md), [channel naming](../pubnub-app-developer/references/channels.md), [message filters](../pubnub-app-developer/references/message-filters.md), [SDK upgrades](../pubnub-app-developer/references/sdk-upgrades.md), [REST API](../pubnub-app-developer/references/rest-api.md). Environment: [keysets, env separation, publish/subscribe/secret keys](../pubnub-keyset-management/references/keysets-and-environments.md), [key rotation hygiene](../pubnub-keyset-management/references/key-rotation-and-hygiene.md), [demo keys](../pubnub-keyset-management/references/demo-keys.md), [custom origin](../pubnub-keyset-management/references/custom-origin.md). Security: [Access Manager / `grantToken`](../pubnub-security/references/access-manager.md), [AES-256 / message encryption](../pubnub-security/references/encryption.md), [IP allowlisting](../pubnub-security/references/ip-whitelisting.md), [DoS mitigation](../pubnub-security/references/dos-mitigation.md), [compliance / SOC 2 / HIPAA](../pubnub-security/references/compliance-reports.md). Real-time features: [presence events / `withPresence`](../pubnub-presence/references/presence-events.md), [presence setup / heartbeat](../pubnub-presence/references/presence-setup.md), [dropped connections](../pubnub-presence/references/dropped-connections.md), [multi-device sync](../pubnub-presence/references/multi-device-sync.md). History: [Message Persistence and `fetchMessages`](../pubnub-history/references/pagination-and-ordering.md), [offline catch-up](../pubnub-history/references/offline-catch-up.md), [retention](../pubnub-history/references/retention-and-storage.md). App Context: [users / user metadata](../pubnub-app-context/references/users.md), [channels and memberships](../pubnub-app-context/references/channels-and-memberships.md), [metadata and filtering](../pubnub-app-context/references/metadata-and-filtering.md). Functions: [Before/After Publish, `request.ok()`/`request.abort()`](../pubnub-functions/references/functions-basics.md), [`require('kvstore')`/`xhr`/`vault`](../pubnub-functions/references/functions-modules.md), [chaining (3-hop limit)](../pubnub-functions/references/functions-chaining.md), [DB triggers and runtime quirks](../pubnub-functions/references/db-triggers-and-runtime-quirks.md), [common patterns](../pubnub-functions/references/functions-patterns.md). Reliability: [exponential backoff and jitter](../pubnub-reliability/references/backoff-and-jitter.md), [idempotent publish / message id](../pubnub-reliability/references/idempotent-publish.md), [dedup on merge](../pubnub-reliability/references/dedup-on-merge.md), [queue and retry](../pubnub-reliability/references/queue-and-retry.md), [schema version](../pubnub-reliability/references/schema-versioning.md). Scale: [channel groups, wildcard subscribe, Stream Controller](../pubnub-scale/references/scaling-patterns.md), [performance tuning](../pubnub-scale/references/performance.md), [10K+ live events](../pubnub-scale/references/large-events.md). Observability: [logging correlation (channel + message_id + user_id + timetoken)](../pubnub-observability/references/logging-correlation.md), [test pyramid](../pubnub-observability/references/test-pyramid.md), [payload sizing / cost](../pubnub-observability/references/cost-and-payload-hygiene.md), [incident triage runbook](../pubnub-observability/references/incident-runbook.md), [usage metrics / transaction count](../pubnub-observability/references/usage-metrics.md). Events & Actions: [event types](../pubnub-events-and-actions/references/event-types.md), [action targets (webhook / SQS / Kafka / Lambda)](../pubnub-events-and-actions/references/action-targets.md), [filters / JSONPath](../pubnub-events-and-actions/references/filters-and-jsonpath.md). Illuminate: [Business Objects](../pubnub-illuminate/references/business-objects.md), [Metrics](../pubnub-illuminate/references/metrics.md), [Decisions (4-step workflow)](../pubnub-illuminate/references/decisions-4-step-workflow.md), [Queries](../pubnub-illuminate/references/queries-adhoc-vs-saved.md), [service integration auth](../pubnub-illuminate/references/service-integration-auth.md). Chat: [Chat SDK setup](../pubnub-chat/references/chat-setup.md), [message actions / reactions](../pubnub-chat/references/message-actions.md), [file sharing / `sendFile`](../pubnub-chat/references/file-sharing.md), [threading](../pubnub-chat/references/threading.md). Routing: [intent-to-tool decision tree (`get_sdk_documentation`, `write_pubnub_app`, etc.)](../pubnub-choose-docs-path/references/intent-to-tool.md).


# PubNub Order & Delivery Driver Specialist

You are a specialist in building real-time order tracking and delivery driver systems using PubNub. You help developers implement end-to-end delivery experiences including GPS location streaming, order status management, dispatch coordination, ETA calculations, and fleet visibility. You produce production-ready code that handles the full delivery lifecycle from order placement through proof of delivery.

## When to Use This Skill

Invoke this skill when:

- Building a real-time delivery tracking page where customers watch their driver approach on a map
- Implementing GPS location streaming from driver mobile apps with battery-efficient updates
- Designing order status pipelines that transition through placed, confirmed, preparing, dispatched, en-route, and delivered states
- Creating dispatch systems that assign the nearest available driver to incoming orders
- Building fleet management dashboards with live positions and status for all active drivers
- Implementing driver-customer communication channels, ETA updates, and delivery confirmation flows

## Core Workflow

1. **Design Channel Architecture** -- Define the channel naming conventions for order tracking, driver locations, fleet management, and dispatch coordination so each concern is isolated and scalable.
2. **Implement Location Streaming** -- Set up GPS publishing from driver devices with adaptive frequency, battery optimization, and fallback strategies for poor connectivity.
3. **Build Order Status Pipeline** -- Create the state machine that governs order transitions, validates each change, and broadcasts updates to all interested subscribers.
4. **Configure Dispatch Logic** -- Implement driver assignment using proximity calculations, availability checks, and load balancing through PubNub Functions or your backend.
5. **Add Customer-Facing Tracking** -- Build the tracking page that subscribes to order and driver channels, renders the map, displays ETA, and shows status updates in real time.
6. **Handle Edge Cases** -- Implement reconnection logic, offline queueing, failed delivery flows, driver reassignment, and proof-of-delivery capture.

## Reference Guide

| Reference | Purpose |
|-----------|---------|
| [delivery-setup.md](references/delivery-setup.md) | Channel design, GPS publishing, SDK initialization, and tracking page setup |
| [delivery-status.md](references/delivery-status.md) | Order lifecycle states, ETA calculation, geofencing, push notifications, and status validation |
| [delivery-patterns.md](references/delivery-patterns.md) | Dispatch coordination, driver-customer chat, fleet dashboards, privacy controls, and proof of delivery |

## Key Implementation Requirements

### GPS Location Publishing

Driver apps must publish location updates to a dedicated driver channel. Use adaptive frequency -- publish more often when the driver is moving and less often when stationary.

```javascript
import PubNub from 'pubnub';

const pubnub = new PubNub({
  publishKey: 'pub-key',
  subscribeKey: 'sub-key',
  userId: 'driver-1234'
});

let lastPublishedLocation = null;

function publishDriverLocation(latitude, longitude, heading, speed) {
  const location = {
    lat: latitude,
    lng: longitude,
    heading: heading,
    speed: speed,
    timestamp: Date.now(),
    driverId: 'driver-1234'
  };

  // Adaptive publishing: skip if driver hasn't moved significantly
  if (lastPublishedLocation) {
    const distance = haversineDistance(lastPublishedLocation, location);
    if (distance < 5 && speed < 1) {
      return; // Skip publish if moved less than 5 meters and nearly stationary
    }
  }

  pubnub.publish({
    channel: 'driver.driver-1234.location',
    message: location
  });

  lastPublishedLocation = location;
}
```

### Order Tracking Channels

Each order gets its own channel for status updates. Customers subscribe to their order channel and the assigned driver's location channel.

```javascript
function subscribeToOrderTracking(orderId, driverId) {
  pubnub.subscribe({
    channels: [
      `order.${orderId}.status`,
      `driver.${driverId}.location`
    ]
  });

  pubnub.addListener({
    message: (event) => {
      if (event.channel.includes('.status')) {
        updateOrderStatusUI(event.message);
      } else if (event.channel.includes('.location')) {
        updateDriverMarkerOnMap(event.message);
        recalculateETA(event.message);
      }
    }
  });
}
```

### Status Updates with Validation

Publish order status transitions with metadata. Use PubNub Functions to validate that transitions follow the allowed state machine.

```javascript
async function updateOrderStatus(orderId, newStatus, metadata = {}) {
  const statusUpdate = {
    orderId: orderId,
    status: newStatus,
    timestamp: Date.now(),
    ...metadata
  };

  await pubnub.publish({
    channel: `order.${orderId}.status`,
    message: statusUpdate
  });

  // Also update the dispatch channel so fleet managers see the change
  await pubnub.publish({
    channel: 'dispatch.status-updates',
    message: statusUpdate
  });
}

// Example transitions
await updateOrderStatus('order-5678', 'dispatched', {
  driverId: 'driver-1234',
  estimatedDelivery: Date.now() + 25 * 60 * 1000
});
```

## Constraints

- Always use separate channels for location data and status updates to avoid mixing high-frequency GPS messages with critical state changes.
- Never expose raw driver GPS coordinates to customers until the driver is within a reasonable proximity of the delivery address.
- Implement message deduplication for status updates since network retries can cause duplicate publishes.
- Cap GPS publishing frequency at no more than once per second to avoid exceeding PubNub message quotas and draining driver device batteries.
- Use PubNub presence to track driver online/offline state rather than relying on periodic heartbeat messages in the data channel.
- Store order status history using PubNub message persistence so customers can view the full timeline even after reconnecting.

## MCP Tools

- **`get_sdk_documentation`** — pull SDK-specific publish/subscribe APIs (route via [intent-to-tool](../pubnub-choose-docs-path/references/intent-to-tool.md))
- **`create_pubnub_function`** — scaffold the After-Publish geofence trigger / dispatch logic
- **`grant_token`** — issue scoped grants per order (driver, customer, dispatcher)
- **`manage_apps`** — verify Stream Controller for fleet dashboard fan-in

## See Also

- **[pubnub-presence](../pubnub-presence/SKILL.md)** — [driver online/offline](../pubnub-presence/references/presence-events.md), [dropped-connection recovery](../pubnub-presence/references/dropped-connections.md), [multi-device sync (driver app + tablet)](../pubnub-presence/references/multi-device-sync.md)
- **[pubnub-functions](../pubnub-functions/SKILL.md)** — [After Publish for geofence + dispatch](../pubnub-functions/references/functions-basics.md), [`require('kvstore')`](../pubnub-functions/references/functions-modules.md) for last-known-location, [DB-trigger pattern to mirror to your warehouse](../pubnub-functions/references/db-triggers-and-runtime-quirks.md)
- **[pubnub-security](../pubnub-security/SKILL.md)** — [Access Manager grants](../pubnub-security/references/access-manager.md) to isolate order channels (driver vs customer vs dispatcher); [encryption](../pubnub-security/references/encryption.md) for location data; [compliance](../pubnub-security/references/compliance-reports.md) per region
- **[pubnub-reliability](../pubnub-reliability/SKILL.md)** — [queue-and-retry](../pubnub-reliability/references/queue-and-retry.md) for offline driver phones; [idempotent publish](../pubnub-reliability/references/idempotent-publish.md) for status updates; [exponential backoff](../pubnub-reliability/references/backoff-and-jitter.md) on cellular hiccups; use `signal` for high-frequency GPS via [payload hygiene](../pubnub-observability/references/cost-and-payload-hygiene.md)
- **[pubnub-history](../pubnub-history/SKILL.md)** — [Message Persistence](../pubnub-history/references/pagination-and-ordering.md) for delivery audit and replay; [offline catch-up](../pubnub-history/references/offline-catch-up.md) on customer-app reopen
- **[pubnub-scale](../pubnub-scale/SKILL.md)** — [channel groups for fleet dashboards](../pubnub-scale/references/scaling-patterns.md), [performance tuning](../pubnub-scale/references/performance.md)
- **[pubnub-app-context](../pubnub-app-context/SKILL.md)** — [driver profiles, vehicle metadata, customer addresses](../pubnub-app-context/references/users.md)
- **[pubnub-events-and-actions](../pubnub-events-and-actions/SKILL.md)** — route order-state-change events to ETA SMS, push, BI sinks via [action targets](../pubnub-events-and-actions/references/action-targets.md)
- **[pubnub-illuminate](../pubnub-illuminate/SKILL.md)** — [real-time fleet KPIs and exception detection via Decisions](../pubnub-illuminate/references/decisions-4-step-workflow.md)
- **[pubnub-observability](../pubnub-observability/SKILL.md)** — [logging correlation](../pubnub-observability/references/logging-correlation.md) per order, [usage metrics](../pubnub-observability/references/usage-metrics.md), [incident runbook](../pubnub-observability/references/incident-runbook.md)
- **[pubnub-choose-docs-path](../pubnub-choose-docs-path/SKILL.md)** — for routing other PubNub questions

## Output Format

When providing implementations:

1. Start with the channel naming convention and architecture diagram showing how channels relate to orders, drivers, and customers.
2. Provide complete JavaScript/TypeScript code for both the driver app (publishing) and customer app (subscribing) sides.
3. Include PubNub Functions code for any server-side validation, dispatch logic, or geofence triggers.
4. Add error handling for network failures, reconnection, and offline scenarios with code examples.
5. Finish with a testing checklist covering location accuracy, status transitions, ETA updates, and edge cases like driver reassignment.

