Making Great API Client

with Contracts

by

Dolganov Sergey @ Evil Martians

Developers

Resilient API Dependency

Request/Response

Mapping

Layer

Request/Response

Transportation

Layer

Layout

Example

Ossert:

  • 4 APIs already depends
  • Storage per quarter
  • Non-incremental data collection

Twitter API:

  • Public data for last week only

Non-Incremental

Per Quarter Storage

Layout (for Ossert)

Incremental

Per Week

Storage

twitter gem

Failed

Requests

Recovery

What If Everything Will Go Wrong?

Most Wanted Issues

  • Poor Boundaries

Output ?

Input

Sniffer

Most Wanted Issues

  • Poor Boundaries

  • Lost In Translation

Some "mutation" happens here

Idempotency

Most Wanted Issues

  • Poor Boundaries

  • Lost In Translation

  • Terminated in Action

Request

Request

Request

Request

Request

Request

Time

Switch Off

Most Wanted Issues

  • Poor Boundaries

  • Lost In Translation

  • Terminated in Action

  • Apocalypse

Developers

Resilient API Dependency

Most Wanted Issues

Murphy's Law

Design by Contracts

  • What does a contract expect?

  • What does a contract guarantee?

  • What does a contract maintain?

Most Wanted Issues

  • Poor Boundaries

  • Lost In Translation

  • Terminated in Action

  • Apocalypse

Developers

Resilient API Dependency

Design By Contracts

Most Wanted Issues

Murphy's Law

Intensity Strategy

Route

Mostly manual (only some steps are automated)

 

Examples:

  • Export to plot.ly

 

 

Route

Mostly manual (only some steps are automated)

 

Solutions:

  • Define expectations
  • Define guarantees
  • Define invariants

 

 

Automated but run manually

 

Examples:

  • Quarter/annual financial reports

  • CRM Contacts duplicates cleanup

Path

Path

Automated but run manually

 

Problems:

  • One-day Living Code Mindset

  • Shortage of Time

  • Part of the Business Domain Anyway

Path

Automated but run manually

 

Solutions:

  • Fail Fast

  • PORO Contracts

Road

Autonomous, usual but not frequent

 

Examples:

  • Feedback routing to CRM

Road

Autonomous, usual but not frequent

 

Problems:

  • Easy to loose track of issue ("not so important")
  • Autonomous means could corrupt the Business Domain any time

Road

Autonomous, usual but not frequent

 

Solutions:

  • Fail Fast (+ Errors Tracking)
  • PORO Contracts
  • API Calls Statistics

Highway

Autonomous, frequent

 

Examples:

  • DHL tariff for purchase

Highway

Autonomous, frequent

 

Problems:

  • Too Many Errors Happen
  • State is Constantly Changing
  • Performance Matter, Every Request Tracing Limitations

Highway

Autonomous, frequent

 

Solutions:

  • Fail Fast (+ Errors Tracking)
  • PORO Contracts
  • API Calls Statistics
  • API Calls Sampling 
  • Sampling "Hot" Switch

 

 

Developers

Resilient API Dependency

Design By Contracts

Most Wanted Issues

Murphy's Law

Intensity Strategy

Contracts Under Microscope

Contracts Test Coverage

TBD

Request/Response

Mapping

Layer

Request/Response

Transportation

Layer

Layout

Most Wanted Issues

  • Poor Boundaries

  • Lost In Translation

  • Terminated in Action

  • Apocalypse

Intensity Strategy

Design by Contracts

  • What does a contract expect?

  • What does a contract guarantee?

  • What does a contract maintain?

Thanks

Twitter: @ss_dolganov

GitHub: @sclinede

Blood Contracts: sclinede/blood_contracts

PORO Contracts: sclinede/poro_contract

Making Great API Client

By Sergey Dolganov

Making Great API Client

Nowadays, unit tests are an essential part of our development process. While we are proud we have 100% test coverage; it does not mean that our code behaves as expected, notably when we deal with external APIs. I'm working on the eBay internal project which mostly built around various API interactions: eBay API, Google Translate API, DHL API and so on. I solve different sophisticated problems based on unexpected API behavior on my daily basis. So I want to introduce a contract-based testing framework that aims to get rid of unexpected behavior of your app. I'll share the tools and approaches that will minimize the risks of being dependent on some external system API.

  • 1,531