liveBook · Manning

Contract

As explained in Machine Learning System Design

A defined interface through which software components request functionality or exchange data.

An API is a contract between a system and its users or other components: it defines the interface through which they request functionality or exchange data. Design it carefully, because changing it can be costly even while the system is still under development. section 13.1

For an ML system, aim for simplicity and predictability. Hide unnecessary implementation details behind a few methods with a small number of parameters, so users can work with the system without understanding its internals. section 13.1 section 13.6

Listing 13.2 A better design for a predict function
def predict(features, time=None, seed=42):
    if time is None:
        time = datetime.now()
    return model.predict(features, time, seed)

This predict interface lets callers supply a time and seed while providing defaults. Making these inputs available gives callers more control than hiding them inside the function. section 13.1

Practical ways to keep the contract usable as the system evolves:

  • Separate external and internal API layers. Keep compatibility in mind for the external interface while retaining freedom to change unexposed internals. section 13.1.1
  • Separate ML and input/output components where possible. They can then scale independently, and a new model component can be introduced for A/B testing or gradual rollout. section 13.1.1
  • Provide a client library to lower the entry barrier and support debugging and experiments. It can also implement recommended retries and timeouts. section 13.1.1
  • Consider feature toggles or an organizational alternative when operating in risky environments. section 13.1.1 section 13.6

An external API as a baseline

A third-party AI API can provide a baseline with zero or a few training samples. Comparing a specialized system against a major vendor’s offering can also help customers or investors understand its performance. section 8.4

How Machine Learning System Design covers it

How deep it goes
Provides design principles and integration practices while deferring general API design and REST-versus-RPC distinctions.
Examples
Uses predict functions with time and seed parameters and third-party AI services as concrete examples.
What it assumes
Assumes familiarity with general API design rather than teaching REST and RPC distinctions from zero.
What you can do after
Evaluate API designs for simplicity and predictability, and apply integration practices that support compatibility and maintenance.
How it connects
Connects API design with abstraction, compatibility, client libraries, feature toggles, and A/B testing.

Also explained in

Compare how 45 books explain contract →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning System Design. The section links point to the parts of the book it draws on.