Building a Global Delivery Prediction System

Building a Global Delivery Prediction System

●2 ●39 ●92
calendar_today • schedule14 min read

There is a strange moment in every delivery.

You place an order.

The system says “Arriving Tuesday.”

Tuesday arrives.

Nothing.

Then the status changes.

“Delayed.”

A few hours later:

“Out for delivery.”

Then:

“Delivered.”

The package appears at your door.

From the customer's perspective, delivery prediction looks simple. There is a destination, a package, a courier, and a date.

But underneath that simple interface is a remarkably complex system.

A delivery does not move through a single machine.

It moves through a network.

A warehouse receives an order. A worker picks an item. Another system packages it. A truck collects it. A sorting facility processes it. A flight may move it across countries. Customs may inspect it. Another warehouse receives it. A local courier takes responsibility. Traffic affects the final journey. Weather can change transportation conditions. Operational capacity can change. Addresses can introduce additional uncertainty.

The package is effectively moving through a global graph of events.

And if we want to predict when it will arrive, we should not simply ask:

“How long does shipping usually take?”

We should ask:

“Given everything that has happened to this package, everything currently happening in the network, and everything likely to happen next, when is this package most likely to arrive?”

That is a much more interesting engineering problem.

This is the idea behind a Global Delivery Prediction System.

It is not merely a tracking dashboard.

It is a prediction engine that continuously transforms logistics events into an evolving estimate of the future.


1. The Real Problem Is Time

Suppose a customer places an order at 10:00 AM.

The delivery pipeline might look like this:

Order Created
     ↓
Payment Confirmed
     ↓
Warehouse Processing
     ↓
Item Picked
     ↓
Package Packed
     ↓
Courier Pickup
     ↓
Origin Hub
     ↓
Sorting Facility
     ↓
International Transit
     ↓
Destination Customs
     ↓
Local Hub
     ↓
Last-Mile Courier
     ↓
Delivered

The customer does not necessarily care about every internal event.

They care about one question:

When will I receive it?

That means the prediction system needs to compress a complicated operational process into a useful temporal estimate.

For example:

Predicted delivery:
September 25

Confidence:
82%

Likely window:
14:00–18:00

The important part is that this prediction should not be static.

If the package is delayed at customs, the prediction should change.

If it reaches the destination hub earlier than expected, the prediction should change.

If a courier scans the package as loaded onto a delivery vehicle, the prediction should change again.

The prediction is therefore a living value.


2. Think of Delivery as a Graph

One of the most useful architectural decisions is to model logistics as a graph.

A simplified graph could look like:

                    ┌──────────────┐
                    │   Warehouse  │
                    └──────┬───────┘
                           │
                           ▼
                    ┌──────────────┐
                    │ Origin Hub   │
                    └──────┬───────┘
                           │
               ┌───────────┴───────────┐
               ▼                       ▼
        ┌──────────────┐        ┌──────────────┐
        │ Airport Hub  │        │ Transit Hub  │
        └──────┬───────┘        └──────┬───────┘
               │                       │
               └───────────┬───────────┘
                           ▼
                    ┌──────────────┐
                    │ Destination  │
                    │ Hub          │
                    └──────┬───────┘
                           │
                           ▼
                    ┌──────────────┐
                    │ Last Mile    │
                    └──────┬───────┘
                           │
                           ▼
                       Customer

Each node represents a location or operational stage.

Each edge represents a possible transition.

We can assign properties to both.

A node might have:

processing_time
queue_size
operational_capacity
operating_hours
historical_delay_rate

An edge might have:

travel_time
distance
transport_mode
historical_variance
departure_frequency

Now delivery prediction becomes a graph problem.

The package is currently at node A.

The destination is node Z.

The system needs to estimate the remaining journey.


3. Events Are More Important Than Statuses

Traditional tracking systems often revolve around statuses:

PROCESSING
SHIPPED
IN_TRANSIT
OUT_FOR_DELIVERY
DELIVERED

These are useful for humans.

But a prediction engine needs richer information.

Instead of simply storing:

{
  "status": "IN_TRANSIT"
}

we might store:

{
  "event": "ARRIVED_AT_HUB",
  "timestamp": "2026-09-21T09:42:00Z",
  "location": "HUB-042",
  "carrier": "carrier_a",
  "package_id": "PKG-19384"
}

Then:

{
  "event": "DEPARTED_HUB",
  "timestamp": "2026-09-21T12:15:00Z",
  "location": "HUB-042",
  "carrier": "carrier_a",
  "package_id": "PKG-19384"
}

The difference is enormous.

The prediction engine can now reconstruct the journey.

It can calculate:

time spent at hub
time between scans
time between facilities
transport duration
processing duration

The system is no longer observing a status.

It is observing behavior.


4. Build the Event Ingestion Layer

A global logistics network can generate enormous numbers of events.

Events may arrive from:

  • courier APIs
  • warehouse systems
  • ERP systems
  • transportation systems
  • customs systems
  • mobile applications
  • barcode scanners
  • IoT devices
  • partner platforms

The architecture therefore needs an ingestion layer.

Courier APIs
     │
Warehouse Systems
     │
Partner Systems
     │
Mobile Devices
     │
IoT Devices
     │
     ▼
┌─────────────────────┐
│ Event Ingestion API │
└──────────┬──────────┘
           ▼
     Event Stream
           ▼
   Normalization Layer

The normalization layer is particularly important.

Different carriers may describe the same event differently.

One carrier might send:

ARRIVED

Another:

RECEIVED_AT_FACILITY

Another:

FACILITY_SCAN

The internal system should normalize these into a common event vocabulary.

For example:

ARRIVED_AT_FACILITY
DEPARTED_FACILITY
CUSTOMS_STARTED
CUSTOMS_COMPLETED
OUT_FOR_DELIVERY
DELIVERED

Now the prediction engine can work across carriers.


5. Create a Universal Shipment Model

A global system needs a common representation of a shipment.

For example:

class Shipment:
    id
    origin
    destination
    carrier
    service_level
    package_type
    weight
    dimensions
    created_at
    promised_at
    current_location
    current_status

But we should not stop there.

The shipment should also maintain its event history.

class ShipmentEvent:
    shipment_id
    event_type
    timestamp
    location
    facility
    carrier
    metadata

And the system should maintain the route.

class RouteSegment:
    origin_node
    destination_node
    transport_mode
    expected_duration
    duration_variance

This gives us three important dimensions:

Shipment
   +
Events
   +
Route

Together they provide the foundation for prediction.


6. Prediction Is a Sequence of Predictions

A common mistake is trying to predict the final delivery date directly.

Instead, predict each stage.

Suppose a package has four remaining stages:

Current Hub
   ↓
Regional Hub
   ↓
Destination Facility
   ↓
Last Mile
   ↓
Customer

We can estimate:

Current Hub → Regional Hub
2.1 hours

Regional Hub → Destination Facility
5.4 hours

Destination Facility → Last Mile
3.2 hours

Last Mile → Customer
4.0 hours

Total:

14.7 hours

But each stage has uncertainty.

So instead of:

14.7 hours

we might calculate:

P50: 14.7 hours
P80: 18.3 hours
P95: 26.1 hours

This is much more useful.

The system can translate those probabilities into customer-facing windows.


7. The Prediction Engine

A simple first version can use historical averages.

For every route segment:

average_duration(origin, destination)

But averages are rarely enough.

Consider two packages traveling between the same locations.

Package A:

Express
Small
Already sorted
Departing immediately

Package B:

Economy
Large
Awaiting sorting
High facility queue

Their expected delivery times are different.

So the model needs features.

For example:

distance
package_weight
package_dimensions
carrier
service_level
origin
destination
current_facility
day_of_week
hour_of_day
historical_route_duration
facility_processing_time
current_queue_size
number_of_previous_scans
time_since_last_event

The model can then estimate:

remaining_delivery_time

8. Start Simple Before Using Machine Learning

You do not need a sophisticated neural network on day one.

A strong baseline could be:

Predicted Time =
Historical Segment Time
+
Current Queue Time
+
Known Processing Time
+
Route Adjustment

For example:

prediction = (
    route_average
    + facility_queue_estimate
    + processing_estimate
    + operational_adjustment
)

This baseline gives the engineering team something measurable.

Then machine learning can improve it.

Possible models include:

  • gradient boosting
  • random forests
  • regression models
  • survival models
  • temporal models
  • sequence models
  • neural networks

The important principle is:

Machine learning should improve a well-understood system rather than replace understanding of the system.


9. Model Time as a Distribution

One of the most important improvements is moving away from a single prediction.

Imagine the system predicts:

September 25

That sounds precise.

But reality is not precise.

Instead:

September 25
60% probability

September 26
25% probability

September 27
10% probability

September 28+
5% probability

Now the system can produce a delivery window.

For example:

Expected delivery:
September 25–26

Confidence:
High

This is more honest and operationally useful than pretending the future is deterministic.


10. Global Means Time Zones

A global delivery system cannot treat time as a simple string.

Consider:

Lusaka
London
Dubai
New York
Tokyo

Every location has different local time.

Events should therefore be stored using a canonical representation such as UTC.

2026-09-21T16:00:00Z

Then converted into local time for presentation.

This prevents errors involving:

  • daylight saving changes
  • cross-border shipments
  • overnight transport
  • international handoffs
  • operating hours

Time zones become part of the logistics model.


11. Operating Hours Matter

A package arriving at a facility at 23:50 does not necessarily get processed immediately.

The facility might operate:

06:00–22:00

So the package effectively waits.

A prediction engine should understand this.

For example:

if arrival_time > facility.close_time:
    processing_start = next_operating_period

This simple rule can significantly improve predictions.

The same concept applies to:

  • warehouses
  • customs offices
  • sorting centers
  • local courier branches
  • pickup points

Operational calendars are therefore valuable prediction features.


12. Geography Is More Than Distance

Two destinations can be equally distant but operationally very different.

A 300-kilometer journey might take:

5 hours

in one environment and:

12 hours

in another.

Distance alone does not determine delivery time.

The model can incorporate:

historical travel time
route reliability
transport mode
facility density
handoff frequency
delivery zone

Geographic information becomes useful when combined with operational history.


13. The Last Mile Deserves Its Own Model

The final stage is often different from the rest of the journey.

International transportation might be predictable at a broad level.

Last-mile delivery can be much more granular.

The package may move from:

Destination Hub
      ↓
Courier Vehicle
      ↓
Delivery Zone
      ↓
Street
      ↓
Customer

The system might need features such as:

delivery zone
route density
number of stops
estimated route duration
vehicle capacity
historical stop duration
delivery attempt history

The final prediction can therefore be calculated separately.

Global Transit Model
        +
Regional Model
        +
Last-Mile Model
        =
Final Delivery Prediction

This modular architecture is easier to improve.


14. Detect Delays Before They Happen

A truly interesting delivery system should not only react to delays.

It should detect delay risk.

Suppose a package has been sitting at a facility longer than packages normally remain there.

The system could calculate:

Expected processing time: 3 hours
Current processing time: 5.5 hours
Delay risk: elevated

This does not necessarily mean the package is delayed.

It means the package is behaving differently from the historical pattern.

That distinction matters.

The system can generate an internal event:

DELAY_RISK_DETECTED

Then downstream systems can react.


15. Build a Delivery Digital Twin

One of the more advanced directions is to create a digital representation of the delivery network.

Imagine every shipment having a continuously updated state:

Shipment
├── Current Location
├── Current Facility
├── Route
├── Historical Events
├── Predicted Next Event
├── Expected Delivery
├── Confidence
└── Risk Factors

And every facility has its own state:

Facility
├── Current Queue
├── Processing Capacity
├── Active Shipments
├── Average Processing Time
├── Delay Risk
└── Operating Schedule

The entire network becomes a living model.

The prediction engine can then reason over the current state of the network.


16. Architecture

A production architecture might look like this:

                  ┌──────────────────┐
                  │ Customer Apps    │
                  └────────┬─────────┘
                           │
                           ▼
                  ┌──────────────────┐
                  │ Delivery API     │
                  └────────┬─────────┘
                           │
          ┌────────────────┴────────────────┐
          ▼                                 ▼
┌──────────────────┐              ┌──────────────────┐
│ Shipment Service │              │ Prediction API   │
└────────┬─────────┘              └────────┬─────────┘
         │                                 │
         ▼                                 ▼
┌──────────────────┐              ┌──────────────────┐
│ Event Store      │◄─────────────│ Prediction Engine│
└────────┬─────────┘              └────────┬─────────┘
         │                                 │
         ▼                                 ▼
┌──────────────────┐              ┌──────────────────┐
│ Event Stream     │─────────────►│ Feature Store    │
└────────┬─────────┘              └────────┬─────────┘
         │                                 │
         ▼                                 ▼
┌──────────────────┐              ┌──────────────────┐
│ Route Graph      │              │ ML Models        │
└──────────────────┘              └──────────────────┘

This separates responsibilities.

The event system records reality.

The graph represents the network.

The prediction engine estimates the future.


17. Use Event-Driven Architecture

Delivery networks are naturally event-driven.

A package generates events continuously.

That makes an event stream architecture particularly appropriate.

For example:

ShipmentEvent
      ↓
Message Broker
      ↓
 ┌────┼───────────┐
 ▼    ▼           ▼
Risk  Prediction  Analytics

A single event can trigger multiple workflows.

For example:

ARRIVED_AT_DESTINATION_HUB

could trigger:

Update shipment state
Recalculate ETA
Update customer application
Check delay risk
Update analytics

This avoids tightly coupling every service.


18. Store Predictions Separately

A useful design is to treat predictions as first-class data.

For example:

prediction_id
shipment_id
created_at
predicted_delivery_time
lower_bound
upper_bound
confidence
model_version
feature_snapshot

Why store them?

Because later we can compare:

Prediction
vs
Reality

Suppose the system predicted:

September 25, 15:00

and actual delivery was:

September 25, 14:20

We can calculate the error.

Over thousands or millions of shipments, this becomes a powerful feedback loop.


19. Measure the Model

A prediction system needs more than model accuracy.

Useful metrics include:

Mean Absolute Error

MAE = average(|prediction - actual|)

This tells us the average absolute error.

Median Absolute Error

Useful when extreme cases exist.

Prediction Interval Coverage

If we claim that:

90% of deliveries should happen within the predicted interval

we can measure how often that actually happens.

Calibration

If the system says:

80% confidence

we want events with that confidence level to behave approximately as expected over time.

The goal is not simply to produce predictions.

It is to produce trustworthy predictions.


20. Prediction Versioning

Models change.

Suppose:

Model v1

is replaced with:

Model v2

We should preserve the model version associated with every prediction.

For example:

{
  "prediction": "2026-09-25T15:00:00Z",
  "model_version": "delivery-v2.4",
  "generated_at": "2026-09-21T17:30:00Z"
}

This makes debugging possible.

If predictions suddenly become less accurate, engineers can investigate which model version introduced the change.


21. Feedback Loops Make the System Better

Every completed delivery creates new training data.

The cycle becomes:

Observe
   ↓
Predict
   ↓
Deliver
   ↓
Compare Prediction With Reality
   ↓
Measure Error
   ↓
Improve Model
   ↓
Predict Again

This is one of the most beautiful aspects of the architecture.

The logistics network continuously generates data that can improve the prediction system.

The system becomes an observer of its own historical performance.


22. Handling Missing Data

Real logistics data is messy.

A package may not receive a scan.

A carrier API may temporarily fail.

A timestamp may be missing.

A location may be approximate.

A system should not collapse because one event is missing.

Instead, the prediction engine should estimate the current state from available evidence.

For example:

Last known event:
Departed Hub A

Elapsed time:
6 hours

Expected travel duration:
4–7 hours

The model may infer that the package is probably somewhere along the next route segment.

This is fundamentally different from claiming an exact location.

The system maintains uncertainty.


23. Confidence Should Be Dynamic

Confidence should not be a permanent property of a shipment.

When the package has just entered a long international route:

Confidence: 58%

When it reaches the destination hub:

Confidence: 82%

When it is loaded onto the final delivery vehicle:

Confidence: 94%

The closer the shipment gets to the destination, the more information becomes available.

Therefore:

More observations
        ↓
Less uncertainty
        ↓
Higher confidence

This is a natural property of the system.


24. Build an ETA API

The customer-facing API could be simple.

GET /shipments/{id}/eta

Response:

{
  "shipment_id": "PKG-19384",
  "estimated_delivery": "2026-09-25T15:00:00Z",
  "window": {
    "from": "2026-09-25T13:00:00Z",
    "to": "2026-09-25T18:00:00Z"
  },
  "confidence": 0.86,
  "last_updated": "2026-09-21T17:45:00Z"
}

The frontend can turn this into something simple:

Expected Friday afternoon

The complexity remains inside the system.

That is good architecture.


25. Notifications Should Be Event-Driven

The prediction system can also power proactive notifications.

For example:

ETA changed

or:

Delivery window moved earlier

or:

Shipment requires additional processing

The important idea is that notifications should be triggered by meaningful changes.

If the prediction changes by two minutes, notifying the customer is probably unnecessary.

A threshold can be used:

if abs(new_eta - old_eta) > notification_threshold:
    notify_customer()

This reduces notification noise.


26. Global Scale Changes Everything

A local delivery system might process thousands of shipments.

A global platform could process millions.

That changes architectural requirements.

The system needs:

horizontal scaling
partitioned event streams
distributed storage
caching
idempotent consumers
fault tolerance
observability
backpressure

Shipment events can be partitioned by:

shipment_id

This keeps events for a shipment ordered within a partition.

Prediction workloads can also be distributed.

Instead of recalculating every shipment after every event, only affected shipments need to be recalculated.

That saves enormous computational resources.


27. Cache Predictions Carefully

Predictions are dynamic, but not every request needs a full model execution.

We can cache:

shipment_id → latest_prediction

When a significant event occurs:

invalidate cache
recalculate prediction
store new prediction

Customer requests then become inexpensive.

The architecture becomes:

Event
 ↓
Prediction Recalculation
 ↓
Prediction Cache
 ↓
Customer API

This creates a fast user experience without unnecessarily running the model on every API request.


28. Observability Is Part of Prediction

Imagine customers report that delivery estimates suddenly became inaccurate.

The engineering team needs to know:

Did the model change?
Did a carrier stop sending events?
Did a facility become slower?
Did route data disappear?
Did event processing lag?

Therefore the system should expose metrics such as:

event_ingestion_latency
prediction_latency
prediction_error
missing_event_rate
carrier_event_rate
facility_processing_time
model_accuracy

Tracing is also valuable.

A single shipment can be followed across:

API
→ Event Service
→ Stream
→ Feature Service
→ Prediction Engine
→ Cache

That makes complex failures much easier to investigate.


29. Security and Data Protection

A global delivery system handles valuable information.

Potential data includes:

names
addresses
phone numbers
order identifiers
delivery locations
shipment histories

The architecture should therefore include:

  • authentication
  • authorization
  • encryption
  • access controls
  • audit logging
  • data minimization
  • secure API design
  • retention policies

Prediction systems should only expose information required for the requested operation.

A customer should not automatically gain access to internal operational data simply because the prediction engine has access to it.


30. The Interesting Part Is the Future

A normal tracking system tells you:

What happened.

A prediction system tries to tell you:

What is likely to happen next.

That distinction changes the entire architecture.

Tracking is primarily observational.

Prediction is inferential.

Tracking asks:

Where is the package?

Prediction asks:

Given where it is, what has happened before, what is happening now, and what does the remaining network look like, when is it likely to arrive?

That requires combining:

events
+
graphs
+
time
+
geography
+
operations
+
statistics
+
machine learning

And that is why delivery prediction is such an interesting systems problem.


31. A Possible Technology Stack

A practical implementation could use:

Backend

Python
FastAPI
PostgreSQL
Redis

Event Infrastructure

Kafka
Redpanda
RabbitMQ

Data Processing

Python
Spark
Flink

Machine Learning

PyTorch
scikit-learn
XGBoost

Storage

PostgreSQL
ClickHouse
Object Storage
Redis

APIs

REST
GraphQL
WebSockets

Observability

Prometheus
Grafana
OpenTelemetry

The exact technologies can change.

The architecture matters more than the brand names.


32. Build It Incrementally

I would not start by building the entire global prediction platform.

Start with a narrow version.

Phase 1

Build:

Shipment API
Event ingestion
Event storage
Basic ETA calculation

Phase 2

Add:

Route graph
Historical route statistics
Facility processing times

Phase 3

Add:

Machine learning
Prediction intervals
Confidence scores

Phase 4

Add:

Delay detection
Dynamic recalculation
Last-mile prediction

Phase 5

Add:

Multi-carrier support
Global time zones
Large-scale streaming
Advanced analytics

This creates a system that evolves naturally.


33. The Bigger Idea

The most interesting part of this project is not predicting whether a package arrives tomorrow.

It is building a system that understands movement through a global network.

The package is simply the object being observed.

The real system is the network.

Warehouses.

Vehicles.

Airports.

Sorting centers.

Customs processes.

Delivery routes.

Operating schedules.

Customers.

Events.

Every movement creates information.

Every event changes the state of the network.

Every state change changes the probability of future events.

This gives us a powerful abstraction:

Current State
      ↓
Possible Future States
      ↓
Probability Distribution
      ↓
Predicted Outcome

That is bigger than package tracking.

It is a general architecture for predicting movement through complex systems.


34. Final Architecture

At its most complete form, our system looks like this:

                  GLOBAL LOGISTICS NETWORK
                           │
                           ▼
                  ┌─────────────────┐
                  │ Event Sources   │
                  └────────┬────────┘
                           ▼
                  ┌─────────────────┐
                  │ Event Ingestion │
                  └────────┬────────┘
                           ▼
                  ┌─────────────────┐
                  │ Event Stream    │
                  └────────┬────────┘
                           ▼
              ┌──────────────────────────┐
              │ Normalization + State    │
              │ Reconstruction           │
              └────────────┬─────────────┘
                           ▼
                  ┌─────────────────┐
                  │ Logistics Graph │
                  └────────┬────────┘
                           ▼
             ┌──────────────────────────┐
             │ Feature Generation       │
             └────────────┬─────────────┘
                          ▼
             ┌──────────────────────────┐
             │ Prediction Engine       │
             └────────────┬─────────────┘
                          ▼
             ┌──────────────────────────┐
             │ ETA + Confidence + Risk │
             └────────────┬─────────────┘
                          ▼
               ┌─────────────────────┐
               │ Delivery API        │
               └──────────┬──────────┘
                          ▼
             Customers / Businesses

And underneath it all is a feedback loop:

Prediction
    ↓
Actual Delivery
    ↓
Prediction Error
    ↓
Model Evaluation
    ↓
Model Improvement
    ↓
Better Prediction

That loop is what turns a static logistics application into an intelligent system.


Conclusion

Building a Global Delivery Prediction System is ultimately an exercise in understanding uncertainty.

A package does not travel through a perfectly deterministic pipeline.

It moves through a changing network.

Facilities become busy.

Routes take different amounts of time.

Events arrive at different intervals.

Operating schedules introduce waiting periods.

The final delivery stage behaves differently from international transportation.

And every new event changes what we know about the future.

The engineering challenge is therefore not to create a magical system that always knows exactly when something will happen.

The challenge is to create a system that continuously updates its understanding of what is likely to happen next.

That requires a combination of event-driven architecture, logistics graphs, historical data, operational modeling, machine learning, probabilistic prediction, and strong software engineering.

The most important architectural idea is simple:

Do not treat delivery as a status. Treat it as a changing state moving through a network.

Once you make that mental shift, the project becomes much more interesting.

You stop building another tracking dashboard.

You start building a computational model of movement.

And that model can answer one of the most useful questions in logistics:

“Given everything we know right now, what happens next?”

That is where delivery prediction becomes real engineering.

And that is where a package stops being just a package.

It becomes a stream of data moving through a living global system.

Want more #programming & #softwareengineering deep dives?

Join 6,134+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

More Posts

The Zero-Net-Loss Fleet & The Mercenary Squad: A Live AI Economy

DEVPlank - Aug 4

How AI Is Changing Web Development, and What Developers Still Need to Understand

Daniel Decker - Nov 10

I’m a Senior Dev and I’ve Forgotten How to Think Without a Prompt

Karol Modelski - Mar 19

Stop Turning Every REST Endpoint into an MCP Tool: A Better Approach to AI Tool Design

zeekwrites - Nov 30

Frameworks Are Institutional Memory

Ken W. Algerverified - Sep 17
chevron_left
2.5k Points • 133 Badges
Kapiri Mposhi, Zambia. • zambianmillenial.com
56Posts
11Comments
410Connections
Derek Mwale — Where Code Meets Creativity.

Related Jobs

View all jobs →

Commenters (This Week)

1 comment
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!