The problem
Same job, different rules
Shipping companies do pretty much the same thing. They pick up a package and deliver it somewhere.
Their APIs, however, tell a completely different story.
Some send tracking updates through webhooks. Others expect you to keep asking for them. Some let you cancel a package, others don't.
Even something as simple as identifying a city can work differently from one carrier to another.
My approach
Sharing what actually makes sense
We already had a common delivery service when I joined the project, but there was still room for improvement.
Take tracking statuses. Each carrier had its own status mapping and its own copy of the conversion logic.
I moved the conversion logic into a shared service. Each carrier only needed to describe how its statuses mapped to ours.
DELIVEREDDEL30DELdeliveredSame conversion logicAdding support for a new status could now be as simple as adding an entry to a mapping table.
The interesting part
Not every carrier can do everything
Some carriers require us to register merchants before creating shipments. Others don't.
Yet our contract required every carrier to implement a registration method, even when it had nothing to do.
That's where abstraction gets a little silly.
When introducing newer capabilities like return requests and package update notifications, I took a different approach.
Carriers could implement what they supported. Unsupported operations had an explicit way of saying so.
| Operation | Carrier A | Carrier B | Carrier C |
|---|---|---|---|
Create shipment | |||
Tracking history | |||
Cancel shipment | |||
Update notification Optional | |||
Return request Optional |
createReturnRequest() NotImplementedEndpointExceptionThere was no reason to make every carrier pretend it could do everything.
What changed
A new carrier, a familiar process
Integrating a new shipping company became a familiar process, even when its API was completely different.
New capabilities could be introduced without requiring every existing integration to change.
The goal wasn't to make all shipping companies identical. It was to make working with them feel consistent.