Grokking Modern API Design Interview
Vote

0% completed

What Is an API?

  1. The Two Sides of Every API
  1. What One Call Contains
  1. The Vocabulary in One Place
  1. Why Programs Publish an API at All
  1. The Kinds of API You Will Meet
  1. Published Decisions Are Permanent Decisions

"Permanent" does not mean "frozen"

Key Takeaways

A delivery application shows that a package will arrive before six in the evening.

The application holds no delivery data of its own. It asked another program for the answer: it sent a short message naming one tracking number, and a server operated by the carrier sent back a small structured reply. The application then arranged those values on the screen.

The agreement that made that exchange possible is an API.

An API, short for application programming interface, is a published agreement that lets one program use another program's capability without knowing how that capability is built.

Two words in that sentence carry most of the meaning. Published means somebody outside the implementation is relying on it. Interface means the agreement is the visible surface, and the machinery behind it is deliberately hidden.

1. The Two Sides of Every API

Every API has a provider and a consumer.

The provider is the team or service that publishes the API and operates the code behind it. The consumer, also called the caller or the client, is the program that uses it. In the delivery example, the carrier is the provider and the phone application is the consumer.

The two sides are usually different programs, often written in different languages, frequently owned by different teams, and sometimes owned by different companies. That separation is the point. The consumer needs the carrier's tracking capability without joining the carrier's engineering team.

Every API has two sides. The consumer is the program that calls and needs the capability without owning it; the provider is the team that publishes the API, operates the code, owns the storage, and keeps the promises. Between them sits the published agreement, and the consumer never sees the language, storage, or services behind it.
Every API has two sides. The consumer is the program that calls and needs the capability without owning it; the provider is the team that publishes the API, operates the code, owns the storage, and keeps the promises. Between them sits the published agreement, and the consumer never sees the language, storage, or services behind it.

2. What One Call Contains

A call has two halves. The consumer sends a request, and the provider returns a response.

A request to read one shipment looks like this:

GET /shipments/shp_81M Authorization: Bearer <credential>

The response carries the answer:

HTTP/1.1 200 OK Content-Type: application/json
{ "id": "shp_81M", "tracking_number": "1Z-4471-9930", "status": "in_transit", "estimated_delivery_at": "<RFC 3339 UTC timestamp>" }

Every part of that exchange has a name, and the rest of the course uses those names constantly.

The anatomy of one call. The request carries a method saying what kind of interaction is wanted, a path identifying the thing addressed, and headers about the request. The response carries a status code saying how the attempt ended, headers, and the body holding the answer. Below them, the contract also holds what no single message shows: which fields are always present, how absence is reported, whether a retry is safe, and what stays true later.
The anatomy of one call. The request carries a method saying what kind of interaction is wanted, a path identifying the thing addressed, and headers about the request. The response carries a status code saying how the attempt ended, headers, and the body holding the answer. Below them, the contract also holds what no single message shows: which fields are always present, how absence is reported, whether a retry is safe, and what stays true later.

An operation is one named thing a caller can do, such as reading one shipment. The method says what kind of interaction the caller wants. The path identifies which thing the caller is addressing. Headers carry information about the request rather than the thing itself, such as the credential proving who is calling. The body, also called the payload, is the structured data the message carries. The status code is a short number telling the caller how the attempt ended.

The contract is all of that together, plus the promises no single message shows: which fields are always present, what happens when the shipment does not exist, whether repeating the call is safe, and how much of this will still be true a year from now.

3. The Vocabulary in One Place

These terms recur in every chapter, so it is worth reading them once as a set.

The nine words every later chapter assumes, each with a plain definition and the value it takes in the shipment example: provider, consumer, request, response, operation, endpoint, payload, status code, and contract.
The nine words every later chapter assumes, each with a plain definition and the value it takes in the shipment example: provider, consumer, request, response, operation, endpoint, payload, status code, and contract.

Two of them are easy to confuse. An endpoint is a location the caller can address. An operation is one thing the caller can do at that location. Reading a shipment and deleting a shipment can share one address while remaining two operations with different inputs, different permissions, and different failures.

4. Why Programs Publish an API at All

Building the capability again is always an option. An API is worth its cost when at least one of these applies.

Reuse without rebuilding. The phone application does not operate a delivery network. One published call replaces work the consumer could never do on its own.

The implementation stays replaceable. The carrier can move from one database to another, split a service in two, or add a cache, and the consumer keeps sending the same request. This is the benefit the whole course protects, and it survives only while the contract stays stable.

Access stays controlled. The provider decides who may call, what each caller may see, and how often. A published surface is easier to secure than direct access to storage.

Teams move independently. Inside one company, an API is the line that lets two teams release on their own schedules instead of coordinating every change.

Other people build things you did not plan. A payment API becomes part of products its authors never designed. That is the largest benefit and also the reason published decisions become so difficult to reverse, which Section 6 covers.

5. The Kinds of API You Will Meet

The word covers several different things, and interviews mix them freely.

By where the code runs. A library API is the set of functions one program exposes to code running in the same process. An operating-system API is how a program asks the machine to open a file or a network connection. A web API is reached over a network, and it is what an API design interview almost always means.

By who is allowed to call. This distinction changes the contract more than any other, so the course returns to it repeatedly.

Three audiences for the same product and what each costs to change. A private API is called by your own services, so callers are known and reachable and it evolves fastest. A partner API is called by named outside businesses, so changes need notice and a deadline. A public API is called by developers you never meet, so some changes may never fully land.
Three audiences for the same product and what each costs to change. A private API is called by your own services, so callers are known and reachable and it evolves fastest. A partner API is called by named outside businesses, so changes need notice and a deadline. A public API is called by developers you never meet, so some changes may never fully land.

By the style of the contract. A web API can be expressed in more than one way. REST addresses things by URL and acts on them through a small fixed set of methods. gRPC defines typed service methods in a schema and generates code for both sides. GraphQL publishes a typed graph and lets the caller select the fields it wants. Related mechanisms cover what a plain request cannot: webhooks, where the provider calls the consumer back, and streaming, where one connection carries a sequence of updates.

The course uses REST as its default because it is the most common interview vocabulary, and Chapter 2 designs it in full. Chapter 3 covers the rest, including the trigger that justifies each one and the cost it brings.

6. Published Decisions Are Permanent Decisions

This is the central idea of the course, and it is the reason API design is a distinct skill rather than a naming exercise.

Imagine that you own an internal function:

loadCustomerProfile(customerId)

You decide getCustomerProfile is clearer. Tools find the call sites, you update them, and you deploy. You control both the function and its callers.

Now imagine your API publishes this response:

{ "user_id": "usr_7241", "display_name": "Mina Patel" }

Six months later you decide name is cleaner than display_name. If you rename it, existing applications still look for the old field. They may show a blank label, reject the response, or fail somewhere you cannot see. Some callers are partner integrations at other companies, some are scripts with no maintainer, some are old mobile applications nobody has updated. No tool finds those callers for you, and you cannot make them all deploy at the same time as you.

The small rename is now a compatibility project, and the diagram below shows what it costs.

Renaming an internal function is a local refactor: tools find the call sites, you update them, run the tests, and deploy once. Renaming a published API field is a compatibility migration that must return both fields, deprecate the old one, contact consumers, measure remaining use, and set a deadline, because partner integrations, unmaintained scripts, and old mobile applications cannot be reached.
Renaming an internal function is a local refactor: tools find the call sites, you update them, run the tests, and deploy once. Renaming a published API field is a compatibility migration that must return both fields, deprecate the old one, contact consumers, measure remaining use, and set a deadline, because partner integrations, unmaintained scripts, and old mobile applications cannot be reached.

Field names are only one kind of promise. Callers depend on operation names and URLs, request and response shapes, types and units, whether a field is required or nullable, status codes, defaults, pagination, retry behavior, authorization rules, and timing guarantees.

Even accidental behavior joins the contract once enough clients depend on it. If invalid input wrongly returns a server error, clients learn to retry it. Correcting the status code later is good design, and it still changes how those callers behave. The earlier decision is already running inside other programs.

This is why restraint matters. A smaller contract leaves fewer promises to preserve. Every field and operation should exist because a caller needs it, not because the server happens to store it.

"Permanent" does not mean "frozen"

Useful APIs must evolve. The goal is not to predict every future requirement, and not to publish a huge contract on day one. Both usually make the design worse. It is to make change possible without surprising existing callers, which later chapters cover in full. For now, use one rule in every interview:

Design the smallest contract that completes the caller's job, and assume every published decision will be expensive to reverse.

Key Takeaways

  • An API is a published agreement that lets one program use another program's capability without knowing how it is built.
  • Every API has a provider that operates the capability and a consumer that calls it, and the two are usually separate programs owned by separate teams.
  • One call is a request and a response, carrying a method, a path, headers, a body, and a status code.
  • The contract is all of that plus the promises no single message shows: required fields, failure behavior, retry safety, and what stays true over time.
  • APIs are worth their cost because they let consumers reuse a capability, keep the implementation replaceable, control access, let teams release independently, and let other people build on the product.
  • Web APIs differ by audience, and a private, partner, and public API of the same product need different contracts.
  • REST, gRPC, and GraphQL are three styles for expressing a web API; this course uses REST by default and covers the others with their triggers and costs.
  • An internal rename is a refactor. A published rename is a migration, because you cannot find, contact, or update every caller.
  • Treat names, shapes, status codes, defaults, and behaviors as lasting promises, and design the smallest contract that finishes the caller's job.

You now know what an API is, what its parts are called, and why its published decisions are expensive to reverse. The next lesson covers the four interview formats this skill appears in. It also shows how your first move changes depending on whether you have sixty minutes, fifteen minutes, an existing API to critique, or an interface to implement.

On This Page

  1. The Two Sides of Every API
  1. What One Call Contains
  1. The Vocabulary in One Place
  1. Why Programs Publish an API at All
  1. The Kinds of API You Will Meet
  1. Published Decisions Are Permanent Decisions

"Permanent" does not mean "frozen"

Key Takeaways