Tolerant Reader
An integration pattern where a consumer reads only the data it needs from a message and ignores everything else, so the provider can evolve without breaking it.
Also known as: Tolerant Reader Pattern
Category: Software Development
Tags: software-development, software-architecture, api-design, patterns, compatibility, distributed-systems
Explanation
The Tolerant Reader pattern, named by Martin Fowler, is Postel's Law applied to service consumers. When you read a response from another system, take only the fields you need and make as few assumptions as possible about the rest. Unknown fields, extra elements, a different field order: none of that should make your code fail.
**How it works**:
- **Read only what you use**: If you need the customer name and the total, extract those two values. Don't bind the whole payload to a strict class that rejects anything unexpected
- **Ignore unknown elements**: A new field in the response is not an error. It's the provider evolving
- **Assume little about structure**: Find values by name or by path, not by position
- **Fail on what matters**: If a field you do need is missing or malformed, fail clearly. Tolerant doesn't mean accepting garbage
**Why it matters**:
Services change at different speeds. If every consumer validates the full response against a strict schema, then every additive change on the provider side becomes a breaking change for somebody. The provider is stuck coordinating releases with all its consumers. A tolerant reader removes that coupling: the provider adds a field, and nothing happens.
**The trap**:
Strict schema validation on the consumer side looks like rigor, but it mostly detects changes that don't concern you. Generated clients that reject unknown properties are the usual culprits.
**Limits**:
- Tolerance on the reading side says nothing about what you send. Stay strict there
- It protects against additions, not against removals or changes of meaning. Pair it with Consumer-Driven Contracts so the provider knows which fields are in use
- For security-sensitive input, tolerance needs boundaries. Ignoring an unknown field is fine. Guessing what a malformed one meant is not
Related Concepts
← Back to all concepts