TLDR;
Ebay has API’s and sometimes they need to get updated. They also need to be backwards compatible.
To make API changes easier, they used “contract testing” which means consumers give the API tests and the APIs need to pass those tests before making updates.
Give me the Problem Deets (Details)
Ebay has a lot of APIs and needs to update them… regularly. The problem is that updating APIs means you also need to be backwards compatible.
One way of doing this is by running a ton of E2E tests for new APIs and ensuring they all succeed.
Except doing that is slow and inefficient and flaky and problematic. So Ebay turned to Contract Testing .
WTF is Contract Testing?
Here’s the simple breakdown how contract testing works
You have a provider for an API
You have consumers that call this API
You have tests by the consumers for the API
You have the provider translate those tests to a contract for the API
You make changes to the API and all the verification tests for the contract must pass.
Sounds hard. How to do this?
There’s existing tools that make contract testing easier. Because it’d be insane to implement it from scratch.
Pactflow
There’s a framework by Pactflow that offers contract testing.
It works like this:
The API consumer lists some details in a domain-specific language (DSL) on API expectations
A mock file is generated off that DSL to be used for unit tests. After passing some unit tests, the mock file is uploaded to the Pact Broker.
The Pact Broker replays all the old contracts on the API. Why? Because calling the same API multiple times with different requests can change things. Gotta make sure it’s always working as expected.
If all the replayed contracts passes, we got a new contract for the API!
So Ebay Just Added PactFlow Contract Testing?
They did, and like any other company, added a bunch of things to it to simplify things for Ebay specifically.
Ebay set up a service that bootstraps their Pact contract testing. With a config file, Ebay sets everything up in their initializer service. This includes updating the contracts using their PR pipeline and running their CI/CD flows to check if everything’s working.
They even linked this to their analytics to check how often their jobs succeed, fail, and other metrics Ebay needs to cover.
Sources and Official Article!
(Links to official article and sources are available to paid subscribers. They help maintain and support this newsletter!)
Keep reading with a 7-day free trial
Subscribe to Byte-Sized Design to keep reading this post and get 7 days of free access to the full post archives.