Engineering Predictive ETA and Exception Management for Logistics Systems

Engineering Predictive ETA and Exception Management for Logistics Systems

Real-time shipment tracking helps customers to know where their shipment is. But most of them are incapable of telling you whether the package will be delivered on time or late. This usually ends up with an angry customer calling customer support.

This article covers all the engineering behind tracking. From carrier events that feed shipment ETA prediction to decisions made by the system to consider that the shipment is off track and how exceptions are managed, this article focuses on the technical implementation and architecture of a tracking system.

For that purpose, our base case will be a multi-carrier setup with mixed feeds (webhooks, REST endpoints that are polled, EDI messages, and stream telematics pings).

Pipeline Overview

Let’s start by taking a look at the entire pipeline:

Predictive ETA and Exception Management Pipeline

A predictive ETA system could be split into five stages:

  • the carrier sends the raw event
  • the system normalizes such an event by mapping it into one from its internal model
  • a state store holds the current picture of each shipment
  • a prediction service produces a median ETA and an upper arrival estimate
  • a rules layer decides whether there is a gap between the prediction and plan that requires a person to act, or it can be handled by an automated action

External dependencies might affect how this workflow behaves in practice. For instance, a carrier’s API that experiences outages could affect the information your system receives. A common strategy to ensure the ETA service does not stall is to decouple the stages of logistics event processing with durable logs. Teams usually rely on Kafka for this purpose, but any log system that allows replay might work.

Replay is important in case you need to fix a mapping bug. In that case, you’ll have to reconstruct the shipment state and the ETA after the fix is done. One thing to keep in mind is that reconstruction should keep external actions disabled to ensure notifications are not resent, and external actions (such as carrier’s requests) are not repeated.

Shipment Event Data Ingestion

Carrier’s data comes from a webhook, polled REST APIs, EDI 214 status messages, and GPS or telematics streams. Each one has its own latency and level of reliability. To reduce latency, webhooks are usually a good choice because they deliver quickly. However, retry policies may differ between carriers. Polls offer full control over the process, but they’re slow. EDI usually lands in batches, and sometimes they arrive several hours after the physical event.

No matter the way the data is delivered, the first thing the system should do is to persist the raw payload as soon as received and before any processing or receipt. That’s the only way to know exactly what the carrier sent. Teams usually write such payloads to object storage or an append-only table. Additional metadata such as the source, receive time, and a hash is useful to locate it in the future. Developers should also manage duplicate deliveries or gaps after retries are exhausted. A carrier event ID scoped to its source is the preferred way for that purpose. An alternative would be a dedupe key built using the carrier identity, shipment reference, status code, event time, and location. The system should also be able to make the difference between explicit corrections and duplicate events.

To keep logs as complete as possible, any rejection the system needs to throw should happen at the consumer level and not at the edge.

Each event has an event time, when it actually happened. It also has an ingest time, when your system sees it. Each refers to a different moment, and both are useful for ETA logic as we’ll discover below.  

The state store should create one record per shipment. It should include information such as the current status, the last known position, the planned route, the milestone history, and the current ETA with its version. Redis or a compacted topic works for reads. A relational table works for history.

Event Normalization

Each carrier builds its own API with its own language. In a multi-carrier system, that means one could send “ODF’ whereas the second one uses “Out of delivery”; let’s add a third one that sends numeric code 21. Dealing with all those values inside the core of your system makes it complex and prone to bugs.

The response here is a normalization layer. One that maps all the expected values into a small set that is internally used by the system. For instance, you could create a list of allowed values such as created, picked up, in transit, arrived at hub, departed hub, out for delivery, delivered, exception, returned. When the carrier’s event is received, the normalization translates whatever it sends into one of the states above. Should you add a new carrier in the future, it costs you a few lines of code to include it as part of the normalization. The same happens if the carrier’s API changes its shape.

While the normalization layer lives in the code, the result values should be stored as data, ideally in a versioned table of records. This way, you can fix a mapping without the need for a new deployment.

Normalization is always recommended even if you’re planning to build a system that integrates a single carrier. It will save you the pain in case you want to escalate to multiple providers in the future.

Chudovo’s team keeps the canonical event small and strict. Here is a trimmed version in Python:

@dataclass(frozen=True)
class ShipmentEvent:
  shipment_id: str
  carrier: str
  status: str               # canonical status
  event_time: datetime      # when it happened, UTC
  ingest_time: datetime     # when we received it, UTC
  location: Optional[GeoPoint]
  raw_ref: str              # pointer to the raw payload
  mapping_version: int
​
def normalize(raw, mapping):
  status = mapping.lookup(raw.carrier, raw.code)
  if status is None:
      return UnmappedEvent(raw_ref=raw.ref)   # goes to review queue
  return ShipmentEvent(
      shipment_id=resolve_shipment(raw.carrier, raw.shipment_ref),
      carrier=raw.carrier,
      status=status,
      event_time=to_utc(raw.timestamp, raw.facility_tz),
      ingest_time=raw.ingest_time,
      location=raw.location,
      raw_ref=raw.ref,
      mapping_version=mapping.version,
  )

Before any state update, you need to resolve carrier references to an internal shipment ID. If no match is found (or in case of ambiguous references), the reference should be sent for review instead of guessing, because a wrong guess corrupts the ETA silently.

Data Quality Comes First

Real-time logistics data sends a lot of out-of-order events, duplicates, missing scans, wrong time zones, and impossible locations every day. Each one requires specific handling.

Out-of-order events are usually managed by inserting late arrivals into the milestone history and updating the current status only if allowed by the transition rules. Missing scans may require the system to add an explicit mark and infer a skipped step only in cases where the next status implies it.

Time zones are a common source of bugs, because many carriers send local time with no offset. Time conversion should be done at the ingestion time, with a lookup by facility. At this point, the system should flag and skip impossible jumps such as a truck that moves 800 km in ten minutes.

Each source needs to have a quality score. Teams have to track it and use it to measure lateness, duplicate rate, and unmapped rate for each carrier. It is also useful for the ETA prediction model to check whether predictions remain calibrated for a carrier with slow EDI.

ETA Prediction in Logistics

Before thinking of models, teams need to build a baseline. What usually holds up is to use planned transit time for the lane, adjusted for time already elapsed. Then, you have to measure the error against it. This is a critical step because it will serve as the rule to evaluate each model you might want to add. To do so, you measure the model’s median ETA error and P90 coverage by lane, carrier, and prediction horizon and compare it against the baseline. Whenever the proposed model beats the baseline on a chronological holdout, you ship it; otherwise, you stick with the baseline.

Since you’re working with tabular data, gradient-boosted trees might be a good fit. To get a median and the 90th percentile, you can rely on quantile regression. If you have to deal with dense telemetry, sequence models can help you (probably most of the team won’t need them).

What to expect as an output? You get a P50 ETA and a P90 ETA, plus a confidence flag. The P50 is what you show to the customers, whereas the P90 will be used to handle exception logic. For instance, any P50 that goes beyond the promised deadline has to be considered an early warning, not just as proof that the delivery will be late. Of course, any threshold depends on the operation’s specific rules about tolerance for missed delays and false alerts.

Labels should display the actual delivery time, but features need to be built using the data received by the model at the prediction time. The model could not be aware of any event that arrives later than when the prediction takes place.

Recalculation

Right after the first estimation, you’ll face the following question: when should the ETA change?

A common pitfall most teams usually incur is to recompute on every ping, adding a debounce per shipment. A better approach recomputes whenever a new milestone is reached, if a position changes past a threshold, after a weather alert, a congestion signal, or a timer when no event arrives for N hours.

Each ETA should carry its own version, and each change needs to be stored together with a reason code. Moreover, each precision should include a tag with the shipment-state version used to compute it. This also serves as a prerequisite before saving: if the version is no longer valid, the estimation has to be discarded, and a fresh calculation needs to be scheduled.

Delay and Anomaly Detection

Here’s a quick overview of common use cases, their signal, and the recommended default action:

  • Late risk:  when P90 is later than the promised date. In this case, the system should open the exception for review, and a notification has to be sent to the customer if the severity threshold is met.
  • Stalled shipment: when no event occurs after the expected gap. Querying the carrier API’s for an updated status is usually what the system needs to do for remediation.
  • Route deviation: when the current position is outside the corridor. In this case, the system should alert the dispatcher so they can review the cause of such deviation.
  • Missed handoff: occurs when there is no departure after the package arrives at the hub. Needs escalation to the hub’s point of contact.
  • Data conflict: in some cases, you could have some contradictory statuses. Retain the valid ETA, flag the rest as degraded, and send them to review.

Teams usually build two separate layers. The first one contains explicit rules such as P90 later than the promised window, dwell at a hub past the lane threshold, no event beyond the expected gap, route deviation outside a corridor.

The second layer serves for statistics: compare dwell time against the lane’s distribution and flag outliers by z-score or IQR.

Rules need to be readable, so the Ops team can understand them and, therefore, trust what has been fired.

Logistics Exception Management Workflows

An exception has to be treated as a record instead of a notification. Most of the time, a simple state machine is enough to store the different statuses: open, acknowledged, in progress, resolved, dismissed. Exception metadata (such as ID and a type, a severity, the shipment and the rule that opened it, a state, and an SLA timer) is also useful and deserves to be stored.

Exception changes and notification jobs should be written in the same database transaction using an outbox table. To prevent losing alerts or duplicating downstream events, an idempotency key has to be added to each retry.

The database should enforce that one active exception per shipment and type is open at a time. Developers usually build a shared method in charge of creating or updating the record. After valid data shows the signal has cleared for a configured period, the exception can be closed.

A good supply chain exception management system usually groups related shipment exceptions by hub or lane for better handling. Teams need to agree on severity tiers and suppress repeats that post to notification channels, preventing them from getting extremely noisy.

Building automated exception handling in logistics is also possible, but the implementation may differ depending on each exception’s type, as discussed in a previous section. Special treatment is required for those actions that incur extra costs: they should wait for a human review.

Where This Fits

The problems you face while building predictive ETA go beyond the model. The real challenge is to plumb the whole system until you can reach reliable predictions. Event mapping and late data are the ones that eat the schedule.

If you want to move from knowing where a shipment is to knowing what happens next, start with the event layer and add prediction on top.

We use essential cookies to ensure our website works properly. With your consent, we also use optional cookies for analytics and other purposes. You can accept, reject, or customize your preferences. See our Cookie Policy.