Understanding Postel’s Law in Modern API Design
Balancing Robustness, Compatibility, and Security
In the early days of the internet, computers from different universities, research labs, and organizations needed to communicate across unreliable networks using software written by completely different teams. There were no mature standards, no giant cloud providers, and definitely no Stack Overflow to save the day.
Out of this messy, experimental era came a simple but powerful rule that helped the internet grow instead of collapse under incompatibility:
“Be conservative in what you send, be liberal in what you accept.”
— Jon Postel, RFC 793 (TCP)
This idea became known as Postel’s Law, or the Robustness Principle. While it was originally written for TCP (Transmission Control Protocol), its influence spread far beyond networking into APIs, file formats, browsers, and distributed systems.
1. The Core Idea Behind Postel’s Law
Be Conservative in What You Send
- Follow the specification strictly
- Use correct formats and encodings
- Avoid unnecessary or experimental behavior
- Produce predictable, standards-compliant output
Be Liberal in What You Accept
- Handle minor deviations gracefully
- Ignore unknown fields when safe
- Accept equivalent representations
- Avoid crashing over small formatting issues
2. Why This Principle Helped the Internet Survive
In the 1980s and 1990s, software was far less standardized. Different vendors interpreted protocol specs differently. If every system had rejected anything slightly off-spec, networks would constantly fail.
3. Postel’s Law in API Design
Example: Sending Strict, Valid Data
{
"id": 101,
"name": "Ranvijay",
"email": "ranvijay@example.com",
"created_at": "2026-01-29T10:15:00Z"
}
Being conservative means keeping formats consistent and standards-compliant.
Example: Being Liberal in What You Accept
{
"name": "Amit",
"email": "amit@example.com",
"age": "25",
"nickname": "Ami"
}
A tolerant API might convert "25" into a number and ignore the unknown "nickname" field instead of failing the request.
4. Where Postel’s Law Works Well
- Public APIs used by many developers
- Evolving systems with backward compatibility needs
- User-generated content where inputs are unpredictable
5. The Dark Side of Postel’s Law
- Security vulnerabilities from loose validation
- Spec drift when invalid behavior becomes accepted
- Hidden bugs that surface later in production
6. Real-World Example: JSON Type Confusion
{ "is_admin": "false" }
If loosely handled, a string "false" could be treated as truthy in some languages, causing serious security issues.
7. The Modern Interpretation
Today, engineers reinterpret Postel’s Law with more caution: validate carefully, provide helpful error messages, and only allow flexibility when it does not risk correctness or security.
8. Practical Guidelines for API Developers
- Follow standards strictly when sending data
- Allow safe flexibility when receiving
- Reject ambiguous or dangerous input
- Log and monitor invalid data attempts
9. Postel’s Law and Microservices
Internal microservices should generally be stricter than public APIs since teams can coordinate and enforce contracts more reliably.
10. Final Thoughts
Postel’s Law helped the internet grow by promoting interoperability and resilience. But in modern systems where security and correctness are critical, it must be applied thoughtfully and carefully.
The goal is balance — not blind flexibility, and not rigid rejection.
