Skip to main content

API Fundamentals

How services expose functionality to clients and to each other, and the design decisions that make APIs reliable and easy to evolve.

WebSockets

Every API pattern covered so far in this module shares one assumption: the client asks, the server answers, and the connection's job is done. WebSockets break that assumption on purpose — they establish a single, long-lived connection over which either side can send a message to the other, at any time, without the other side having asked first. That's the difference between an ordering system where you have to keep asking "is it ready yet?" and one where the kitchen taps you on the shoulder the moment it is.

Idempotency

An operation is idempotent if performing it multiple times has exactly the same effect as performing it once. Setting a light switch to "on" is idempotent — flipping it to "on" five times leaves it exactly as on as flipping it once. Pressing "add one item to cart" is not — pressing it five times adds five items. This one property turns out to be one of the most load-bearing concepts in distributed API design, because it's the difference between "safe to retry" and "dangerous to retry."