General Tech Works
System Note

SYSTEM DESIGN

Why APIs Fail Long Before They Break

Contracts matter more than code paths.

Executive Summary

APIs are integration points that carry implicit contracts on data and time. When these are wrong, failures occur even if the code is correct. For example, an insecure API endpoint can leak user data (as in the Facebook Cambridge Analytica scandal), long before any code crash happens【78†L223-L231】. This article shows why defining trust, timeout, and retry semantics upfront – and treating the API as a careful contract – is vital to preventing failures.

Trust and Timing Assumptions

In a sequence diagram, every call has assumed behavior. We ask: what if the callee is slow? Does the caller wait or fail? What if the callee is malicious or buggy? These questions often go unstated in project specs. But when coders integrate, they find out quickly – the hard way.

For instance, building an API without authentication might work in a test, but in production an attacker can harvest data. Real-world case: the Facebook APIs had no proper authorization checks for certain data fields, and in the Cambridge Analytica scandal, billions of user profiles were exposed【78†L223-L231】. That is not a code bug at runtime; it’s a breach of trust in the API contract.

Similarly, cloud services often impose rate limits. If your code never considered rate limiting, it will silently break under load. In short, many API failures happen long before a timeout – because the contract (security, limits, version compatibility) was incomplete.

Case Studies: Security and Downtime

Consider the Equifax breach: an insecure API allowed attackers to download millions of records without triggering alarms. The API endpoints worked as written, but the trust assumptions were wrong. As Fortanix notes, Facebook, Twitter and Equifax had catastrophic consequences when "improperly secured APIs allowed unauthorized harvesting of sensitive data"【78†L223-L231】.

On the performance side, a company once updated a billing API to change return codes without notice. Integrations broke immediately, not due to code failing, but because clients assumed one format and got another. The outage was not caused by a code crash but by a broken contract.

These examples show that it’s often issues of trust or compatibility that cause an API to fail in practice.

Contracts Over Code

A robust approach is to treat each API call as a contract with defined expectations. For every request, document: timing (timeout, retries), trust (authentication, data validation), and failure modes. In a sequence diagram, the developer explicitly writes error-handling branches instead of assuming "it will work."

In other words, front-load the trouble-shooting. Do security reviews and integration tests early. Mock failures (like 5xx responses) and see how the client handles them. Before deployment, have SLAs and fallbacks in place, rather than discovering these issues in production.

By drawing the sequence diagram of an API call with error states and timeouts, teams often find the same problems they would in real life. For example, one team sketched out a payment API and realized: we didn’t decide what to do if the network is slow. After adding a fallback flow in the diagram, they caught a bug before writing a single line of code.

In summary, most API problems come from unchecked assumptions. Failures often happen in the gaps of trust and timing. Tighten those contracts during design – the code itself will then run smoothly.