Transport & Delivery

How to Build Transport, Logistics and Delivery Applications with PubNub

Oliver Carson on Dec 19, 2024
How to Build Transport, Logistics and Delivery Applications with PubNub

Transport, Delivery, and Logistics (T&L) applications require real-time visibility, efficient routing, and reliable communication across dispersed fleets, devices, and supply chains. Companies like Decisiv and Tenna streamline operations, improve delivery times, and ensure transparency for their customers and business partners for their applications. They need to track and trace shipments, stream real-time vehicle fleet data, dynamically route vehicles, monitor asset status, and share critical data seamlessly in real time.

The following application shows how a logistics delivery app that requires real-time proximity matching, location tracking, chat, time-sensitive alerts/notifications, and live dashboards can provide real-time updates to the driver & dispatcher:

The previously mentioned transport, delivery, and logistics applications are powered by PubNub, a real-time developer platform that enables you to build, manage, and enhance interactive cross-platform, data-driven T&L experiences seamlessly, no matter the app’s purpose, scale, or complexity. PubNub serves as the foundation for over 2000 customers in diverse industries, ranging from geolocation tracking, on-demand delivery, fleet monitoring, e-commerce, supply chain management, to online chat and interactive experiences. With over 1B unique devices monthly, 99.999% reliability, and 3 trillion transactions monthly, you can let PubNub handle the scalability and security of your T&L application, so you can focus on optimizing your logistics operations for customer satisfaction.

Continue reading to learn more about the essential features to build your transport, delivery, and logistics application using PubNub. If you’d like to jump into the action immediately, you can learn more about building a T&L application with PubNub by following our developer resources.

Building Transport, Delivery and Logistics Applications

Although our customers building T&L applications may operate in different markets, they share one key requirement: enabling real-time data flow and visibility. This often means tracking shipments, delivery status, managing fleets, synchronizing supply chain data, and ensuring that updates are instantly reflected across all other connected devices, dashboards, and control systems.

PubNub is structured based on the publish/subscribe model, which means that a publisher (source of data) pushes messages to subscribers (receivers of data) through channels. These subscribers are immediately notified when new messages such as shipment location updates, routing instructions, or real-time sensor data are published.

PubNub Platform Overview

The following scenarios are common when building T&L applications and we’ll show how PubNub’s features can meet these unique needs.

Sending Updates: Publish

When a truck’s location changes, a package is scanned at a warehouse, or a route needs to be dynamically adjusted, you must send updates to all relevant stakeholders: dispatchers, drivers, warehousing managers, customers, or integrated enterprise systems.

PubNub’s Publish functionality is the first key pillar. To send an update, you create a PubNub message containing the relevant event data: sensor readings, instructions, shipment status, or routing instructions. These JSON-formatted messages are transmitted in less than 30ms globally to ensure information is delivered on-time. You can also utilize Signals for sending small payloads at a high rate, perfect for geolocation coordinates or quick updates when devices are communicating.

Both messages and signals are sent via channels, which transmit data from one device to another. When sending a message, you must specify a channel to send the message. You might have a channel for each fleet, route, warehouse, or shipment. Once you publish the latest data, such as a new ETA for delivery, temperature readings inside a refrigerated container, or other complex metadata, every connected subscriber on that channel receives the update in real time.

Receiving Updates: Subscribe

Once a location update, route adjustment, or status change is published, everyone who needs to know must receive that data.

PubNub’s Subscribe functionality is the second key pillar of the publish-subscribe model. You would subscribe users to a channel (or multiple channels) or create an entity-based subscription or a subscription set, depending on your SDK, and handle incoming messages using an event listener. Any clients subscribed to the channel(s) or entities, which are subscribable objects within a PubNub SDK that allows you to perform context-specific operations, will receive all messages sent to it, and handle them based on the received update.

Track Asset State: Presence

Many operations often require knowing which assets, drivers, or devices are online, en route, or offline. You need visibility for these fleet management apps to know which vehicles are active, which warehouses are operational, and which endpoints (users or devices) are currently connected.

PubNub Presence monitors the subscribers of channels. This means you can look up who’s currently online when a user has joined/left a channel, or which channels a user is subscribed to. Checking presence is based on receiving presence events, which are sent automatically from the PubNub servers when a user’s state changes. You would then add a presence event listener to listen for these events and handle them based on the received action (join, leave, timeout, state-change, or interval).

Based on these different presence actions, you can maintain accurate fleet status, trigger alerts when a carrier unexpectedly disconnects, and ensure operational continuity. This real-time awareness of which assets are active helps route optimization, route planning, load balancing, and resource allocation.

Retain and Retrieve Previous Information: Message Persistence

Historical data is critical in T&L application development: delivery timestamps, route history, sensor readings, and past shipment statuses from shippers are required for analytics, fleet management, audits, and compliance checks, as well as for when devices that were originally offline come online.

PubNub’s Message Persistence feature allows you to retain and retrieve historical messages. You need to know the channel name the message was sent to and the message’s timetoken. You can control how long messages are stored, how far back you want to retrieve messages, the number of entries, and influence the return order.

Notify Offline Stakeholders: Push Notifications

Message Persistence is a great to store and obtain previous information sent on that channel for users that were not online. While the information will be waiting for them as soon as they come online (caught by Presence detection), drivers, customers, and remote workers might be offline. What if they are busy but still need to know when their delivery is arriving or if there’s a route change that has occurred?

PubNub’s Mobile Push Notifications feature provides a method to deliver in-app messages quickly and reliably, regardless of whether the mobile application is in the foreground or background on iOS and Android devices. The app feature bridges native PubNub publish with different notification service providers like Firebase Cloud Messaging and Apple Push Notification Service by sending updates in one message call - this means that your mobile app development doesn't need to handle different frameworks for each device platform and helps keep your tech stack simple.

PubNub Mobile Push Notifications Gateway

Most applications support web and mobile devices. Users who are using your application on Android and iOS devices can benefit from mobile push notifications to alert them whenever new information is available. A warehouse manager can receive a push notification on their phone about a delayed shipment or customers can be alerted that their package is out for delivery.

Store Device and User Metadata: App Context

T&L systems often involve multiple layers of information: users, vehicles, shipments, and routes, each with specific attributes, permissions, or preferences.

PubNub’s App Context feature provides easy-to-use, serverless storage to store metadata for users, channels, and memberships (relationship between a user and a channel) without the need to set up your database. You can optionally store metadata, including custom properties, for your users in applications. PubNub triggers events when object data is set, updated, or removed from the database, which means that you can receive these events in real time and update your front-end application accordingly.

You can use App Context to store any attributes about your user, assets, or devices in one place and can then easily present this data in your application, without the need of setting up your database, helping keep down development cost and keeping the technology stack simple. This gives you a flexible way to manage attributes like driver profiles, asset barcodes, vehicle capacity, inventory management, and warehouse addresses. You can manage the metadata via API calls or utilize BizOps Workspace to gain real-time control over your app through a user-friendly, no-code interface.

Organize and Protect Your Data Streams: Access Manager

Security and access control are critical in any application, especially so for T&L apps. You must ensure that only authorized users and devices can access sensitive data, such as shipment details, routing instructions, or driver identification info.

PubNub’s Access Manager controls client access to resources using restricted permission tokens and allows you to regulate clients’ access to PubNub resources, such as channels, channel groups, and UUIDs.

PubNub Access Manager Authorization Flow

With Access Manager, you could allow a customer to view their shipment’s status but not internal routing details or grant a dispatcher write access to update driver routes while restricting other roles to read-only permissions.

Ensure a Great User Experience: Functions

At this point, you can send and receive messages in real time, notify offline users, and track user states. But what if you want to do something with a message before or after a user sends it?

PubNub’s Functions feature is used to capture events happening in your PubNub channels and enables you to perform an action based on that event. It enables you to write code to address your business needs and allows you to capture events before and after publishing messages. This means that you don’t need to create and set up your servers or incur increased latency to external servers.

This means you can filter out irrelevant updates, enrich data with additional context before it’s broadcast, or automatically route alerts based on conditions like temperature thresholds, route deviations, or late deliveries. You can utilize your code, integrate it with one of our third-party services, or run your own trusted third-party vendor APIs on the edge for payment gateways such as Stripe or Paypal, mapping systems like Google Maps, or artificial intelligence to help with automation workflows.

Analyze and Make Instant Data-Driven Decisions: Insights and Illuminate

Understanding patterns in delivery times, predicting delays, optimizing routes, and improving operational KPIs all depend on analyzing real-time data.

PubNub Insights allows you to dive into your current PubNub implementation to view turnkey data analytics based on your messages, users, and channels, all through an intuitive user interface without any code required. You can utilize this data to implement Illuminate alongside Insights to not only understand your data but also make real-time decisions without the need for long iteration cycles, improving logistics management.

PubNub Illuminate is a real-time decisioning and analytics product that is customizable to an organization’s unique use case. The product is designed with the product managers and analysts in mind, allowing them to define conditions based on your data metrics, which, when triggered, will perform dynamic actions based on that data for your management system. You can then see your application respond in real time to improve business KPIs and iterate as events happen. This means that your development team can focus on the development process.

What’s Next

You’ve learned about PubNub’s key features and how you can use them to create unique T&L applications that deliver real-time updates, optimize routes, secure data streams, and provide better visibility across supply chains. Whether you’re building a real-time fleet tracking solution, a last-mile delivery optimization platform, calculating fuel consumption costs for a transportation management feature of your app, or a sensor-driven cold chain monitoring system, PubNub can power the backend of your T&L data flows so you can focus on streamlining operations, improving efficiency, and enhancing the customer experience.

If you would like to learn more about getting started with your own transportation app or delivery app, take a look at our growing collection of developer resources:

Feel free to reach out to the Developer Relations Team at devrel@pubnub.com for any questions or concerns or sign-up for your free account to get started today.