Skip to main content

In the world of business resource APIs, stability is a key aim. However, continuous improvement often necessitates changes that can potentially disrupt existing systems and processes. To avoid a "big-bang" coordinated cut-over, it becomes necessary to support multiple versions of an API. In this article, we will explore the best practices for managing API versions effectively and maintaining stability while allowing for progress and innovation.

Versioning APIs Using Versioned URLs

Versioned URLs are widely used for managing API versions. This scheme, although somewhat limiting, is uncomplicated and easy for clients to comprehend and control which API versions they interact with. In a specification-first managed API environment, using versioned URLs as the default versioning mechanism ensures a low-risk approach. To implement versioned URLs, only the MAJOR version should be included as part of the URI. The format should follow 'v{MAJOR}', for example, '/membership/v1/applicants'. The version number should come before the resource name in the path and should never appear between the resource name and the resource ID. Minor and patch versions, assuming SemVer versioning, should not be included in the URI as these changes are typically backwards-compatible.

Employing Semantic Versioning for API Models and Specifications

API models and specifications should be managed using semantic versioning, which follows the format {MAJOR}.{MINOR}.{PATCH}. Ideally, domain modeling tooling should handle semantic versioning across all derivative artifacts. To ensure consistency, the following rules should be applied when incrementing the API version number:

  • MAJOR version: When incompatible or breaking API changes are made.
  • MINOR version: When functionality is added in a backwards-compatible manner.
  • PATCH version: When backwards-compatible bug fixes are made.
    By adhering to semantic versioning, it becomes easier to communicate the nature of changes made in each version of the API.

Backwards Compatibility: Ensuring Seamless Upgrades

Backwards compatibility is a crucial aspect of managing API versions. It allows for seamless upgrades without disrupting existing integrations. Minor version changes are considered backwards compatible, as they do not introduce changes that would break existing client implementations. Some examples of backwards compatible changes include:

  • Addition of a new field (non-mandatory) to a representation
  • Addition of a new operation
  • Addition or removal of HATEOAS links
  • Additional support of a new media type (e.g. Accept: application/pdf)
    On the other hand, certain changes are not backwards compatible and may require a major version increment. These changes include:
  • Removal of fields from representations
  • Changes of field data types (e.g. string to boolean)
  • Removal of an operation
  • Removal of media type support
  • New or tightened API security definitions
    Carefully considering the impact of changes and their compatibility ensures a smooth transition for API consumers.

Test Environment Break-Fixes and Incrementing Minor Versions

Managing break-fixes in test environments can sometimes pose challenges, especially when deploying them to yet-unpromoted APIs. In such cases, instead of incrementing the major version number, it is recommended to increment the minor version number. API analytics can then be used to identify and notify active API consumers who may be impacted by these changes. This approach allows for timely resolution of issues without causing unnecessary disruptions.

Replacing a Major API Version: Justify, Document, and Socialize

Introducing a new major API version can have a significant impact on all consumers. Therefore, before deciding to introduce a new major version, API owners should thoroughly explore alternatives and consider the potential consequences. Documenting this decision as an Architecture Decision and discussing the impacts in agile planning forums helps ensure that all stakeholders are aware of the changes.

Decouple Cut-over: Transitioning to the New API Version

When deploying a new major version, it is important to treat it as a separate API. Consumers must explicitly subscribe to the new version in order to use it. With each new major version, older versions should be deprecated, allowing existing consumers to transition smoothly. However, maintaining multiple versions can introduce complexity in development and support efforts.

Communicate a Retirement Schedule: Minimizing Disruption

To ensure a smooth transition and minimize any disruptions, it is crucial to identify API consumers and communicate a deprecation and retirement schedule well in advance. Most API management platforms provide support for API deprecation and client notification. By giving sufficient notification, consumers can plan and migrate to the new version accordingly.

Retire and Remove the API: Final Steps

Once all subscribers have transitioned to the new version or when the scheduled retirement date arrives, a change should be made to retire the old API. It is important to note that retiring an API is not the same as removing it. Retirement allows for reversibility, while removing an API entails completely phasing out support for the old version. These steps ensure a clean and systematic approach to managing API versions.

Managing API versions requires a delicate balance between stability and progress. By following best practices, such as using versioned URLs, semantic versioning, ensuring backwards compatibility, and communicating changes effectively, businesses can achieve a seamless transition to new API versions while maintaining stability. With careful planning and execution, API versioning becomes a tool for continuous improvement, enabling businesses to evolve and adapt to changing needs.

Integrate People, Process and Technology