API and Protocol Design Principles
78. Postel’s Law (Robustness Principle)
Definition. Be conservative in what you send and liberal in what you accept; use cautiously, as excessive permissiveness can create security and interoperability issues.
Rationale. Tolerant readers and strict writers maximize interoperability across implementations. But over-tolerance can mask errors and open security holes, so apply with care.
Example. Accept extra unknown fields in requests (ignore them) but never emit malformed or ambiguous output.
Anti-pattern / failure mode. Accepting anything and producing inconsistent output; “liberal acceptance” leading to injection or parsing bugs. Review signal: security issues from over-permissive parsing.
Related. Principle of Least Surprise (#79), API Consistency (#82), tolerant readers (Adapter).
79. Principle of Least Surprise
API-surface scope — the API counterpart of Least Astonishment (#10).
Definition. API behavior should be predictable; design interfaces that match caller expectations.
Rationale. Surprising behavior causes misuse and bugs. Predictable APIs reduce cognitive load and make integration reliable.
Example. A delete() method should remove the resource, not archive it silently.
Anti-pattern / failure mode. Methods whose names imply one thing but do another; inconsistent return types. Review signal: callers wrap calls in defensive checks.
Related. Postel’s Law (#78), API Consistency (#82), predictable contracts (Facade).
80. Backward Compatibility
Definition. New versions should preserve existing client behavior where required; avoid breaking callers unnecessarily.
Rationale. Clients depend on current behavior; breaking changes force costly upgrades and erode trust. Preserving compatibility keeps the ecosystem stable.
Example. Add new optional fields rather than renaming or removing existing ones.
Anti-pattern / failure mode. Removing or renaming fields in a minor release; changing semantics without version bump. Review signal: client breakage on upgrade.
Related. Semantic Versioning (#81), API Consistency (#82), matching families (Abstract Factory).
81. Semantic Versioning (SemVer)
Definition. Communicate compatibility through version numbers: major for breaking, minor for additive, patch for fixes.
Rationale. Version numbers convey change impact, letting consumers decide when to upgrade. Consistent SemVer builds trust and automates dependency management.
Example. Bump major for a removed endpoint, minor for a new optional field, patch for a bug fix.
Anti-pattern / failure mode. Breaking changes in patch releases; version numbers that don’t reflect impact. Review signal: consumers cannot predict upgrade risk.
Related. Backward Compatibility (#80), API Consistency (#82), stable contracts (Stable Abstractions).
82. API Consistency Principle
Definition. Use consistent naming, semantics, and error handling; a uniform API is easier to learn and use.
Rationale. Inconsistency forces users to memorize special cases and increases errors. Uniformity reduces cognitive load and support burden.
Example. Use the same error format and status codes across all endpoints.
Anti-pattern / failure mode. Mixed naming conventions, inconsistent pagination, varied error shapes. Review signal: separate documentation per endpoint for basics.
Related. Principle of Least Surprise (#79), Convention over Configuration (#20), uniform entry points (Facade).
83. Statelessness Principle
Definition. Keep request processing independent of hidden session state where appropriate; stateless services scale and fail over more easily.
Rationale. Hidden state ties requests to specific instances, complicating scaling and failover. Stateless processing lets any instance handle any request.
Example. Pass auth tokens per request rather than relying on server-side sessions.
Anti-pattern / failure mode. Server-side session state that must be replicated or sticky-routed. Review signal: scaling requires session affinity.
Related. Self-Describing Messages (#84), Location Transparency (#107), decoupled events (Event-Driven).
84. Self-Describing Messages
Definition. Messages should carry enough information to be interpreted correctly; include metadata needed for parsing and routing.
Rationale. Without metadata, receivers must guess format or meaning. Self-describing messages enable independent evolution and routing.
Example. Include content-type, version, and correlation id in message headers.
Anti-pattern / failure mode. Opaque payloads with no version or type info. Review signal: consumers break when producers change format.
Related. Statelessness (#83), API Consistency (#82).