Tolerant reader
Embracing the Tolerant Reader Pattern in API Integration
As we continuously improve and evolve our public API to meet the ever-changing requirements and enhance functionality, integrators, and clients must adapt to these changes seamlessly. One pattern that aids in achieving this resilience is the Tolerant Reader.
What is a Tolerant Reader?
The Tolerant Reader pattern is a concept in system integration that suggests when consuming data from another service, the client should be designed to handle possible changes, such as additional fields or minor structure changes, gracefully. This pattern aids in making the integration more resilient and forward-compatible, reducing the need for immediate changes or upgrades from the client side with every minor update in the data or service.
Real-world Scenario
Consider you are calling the GET /organizations/{{id}}
. Initially, the response might look like this:
Later on, we decide to include a doingBusinessAs
and address
fields to the response:
Clients implementing a Tolerant Reader pattern will handle the extra fields (doingBusinessAs
and address
) gracefully, regardless of whether their current implementation needs it or not.
Implementing a Tolerant Reader
Below is the Python code snippet updated to consider the changes in the payload, specifically handling the additional doingBusinessAs
and the nested address
object.
In this snippet, the get
method of the dictionary is used to fetch values. If a new field like phoneNumber
is added to the API response, the code will still function correctly by safely accessing the new field without throwing an error if it's absent.
Conclusion
Adopting a Tolerant Reader pattern when integrating with APIs can significantly reduce maintenance effort and improve the system's resilience to changes. It ensures your applications gracefully handle additional information and remain functional without frequent updates, thus providing a smoother integration experience.
Last updated