|
| 1 | +--- |
| 2 | +id: 185 |
| 3 | +state: approved |
| 4 | +created: 2024-10-22 |
| 5 | +placement: |
| 6 | + category: compatibility |
| 7 | + order: 40 |
| 8 | +--- |
| 9 | + |
| 10 | +This topic describes the versioning strategies used by Google APIs. In |
| 11 | +general, these strategies apply to all Google-managed services. |
| 12 | + |
| 13 | +## Guidance |
| 14 | + |
| 15 | +All Google API interfaces **must** provide a _major version number_, which is |
| 16 | +encoded at the end of the protobuf package, and included as the first part of |
| 17 | +the URI path for REST APIs. In the event an API needs to make an incompatible |
| 18 | +change, consult [AIP-180][] and [AIP-181][] for necessary steps based on the |
| 19 | +stability level of the surface in question. |
| 20 | + |
| 21 | +Note: The use of the term "major version number" above is taken from |
| 22 | +[semantic versioning][]. However, unlike in traditional semantic versioning, |
| 23 | +Google APIs **must not** expose minor or patch version numbers. For |
| 24 | +example, Google APIs use `v1`, not `v1.0`, `v1.1`, or `v1.4.2`. From a user's |
| 25 | +perspective, major versions are updated in place, and users receive new |
| 26 | +functionality without migration. |
| 27 | + |
| 28 | +A new major version of an API **must not** depend on a previous major version of |
| 29 | +the same API. An API surface **must not** depend on other APIs, except for in |
| 30 | +the cases outlined in [AIP-213][] and [AIP-215][]. |
| 31 | + |
| 32 | +Different versions of the same API **must** be able to work at the same time |
| 33 | +within a single client application for a reasonable transition period. This time |
| 34 | +period allows the client to transition smoothly to the newer version. An older |
| 35 | +version **must** go through a reasonable, well-communicated deprecation period |
| 36 | +before being shut down. |
| 37 | + |
| 38 | +For releases which have [alpha or beta stability][AIP-181], APIs **must** append |
| 39 | +the stability level after the major version number in the protobuf package and |
| 40 | +URI path using one of these strategies: |
| 41 | + |
| 42 | +- Channel-based versioning (recommended) |
| 43 | +- Release-based versioning |
| 44 | +- Visibility-based versioning |
| 45 | + |
| 46 | +### Channel-based versioning |
| 47 | + |
| 48 | +A *stability channel* is a long-lived release at a given stability level that |
| 49 | +receives in-place updates. There is no more than one channel per stability level |
| 50 | +for a major version. Under this strategy, there are up to three channels |
| 51 | +available: alpha, beta, and stable. |
| 52 | + |
| 53 | +The alpha and beta channel **must** have their stability level appended to the |
| 54 | +version, but the stable channel **must not** have the stability level appended. |
| 55 | +For example, `v1` is an acceptable version for the stable channel, but `v1beta` |
| 56 | +or `v1alpha` are not. Similarly, `v1beta` or `v1alpha` are acceptable versions |
| 57 | +for the respective beta and alpha channel, but `v1` is not acceptable for |
| 58 | +either. Each of these channels receives new features and updates "in-place". |
| 59 | + |
| 60 | +The beta channel's functionality **must** be a superset of the stable channel's |
| 61 | +functionality, and the alpha channel's functionality **must** be a superset of |
| 62 | +the beta channel's functionality. |
| 63 | + |
| 64 | +#### Deprecating API functionality |
| 65 | + |
| 66 | +API elements (fields, messages, RPCs) **may** be marked deprecated in any |
| 67 | +channel to indicate that they should no longer be used: |
| 68 | + |
| 69 | +```proto |
| 70 | +// Represents a scroll. Books are preferred over scrolls. |
| 71 | +message Scroll { |
| 72 | + option deprecated = true; |
| 73 | +
|
| 74 | + // ... |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +Deprecated API functionality **must not** graduate from alpha to beta, nor beta |
| 79 | +to stable. In other words, functionality **must not** arrive "pre-deprecated" |
| 80 | +in any channel. |
| 81 | + |
| 82 | +The beta channel's functionality **may** be removed after it has been deprecated |
| 83 | +for a sufficient period; we recommend 180 days. For functionality that exists |
| 84 | +only in the alpha channel, deprecation is optional, and functionality **may** be |
| 85 | +removed without notice. If functionality is deprecated in an API's |
| 86 | +alpha channel before removal, the API **should** apply the same annotation, and |
| 87 | +**may** use any timeframe it wishes. |
| 88 | + |
| 89 | +### Release-based versioning |
| 90 | + |
| 91 | +**Important:** This pattern is not commonly used for new services. There are |
| 92 | +existing services that follow it, but Channel-based Versioning is the preferred |
| 93 | +mechanism. |
| 94 | + |
| 95 | +An *individual release* is an alpha or beta release that is expected to be |
| 96 | +available for a limited time period before its functionality is incorporated |
| 97 | +into the stable channel, after which the individual release will be shut down. |
| 98 | +When using release-based versioning strategy, an API may have any number of |
| 99 | +individual releases at each stability level. |
| 100 | + |
| 101 | +Note: Both the channel-based and release-based strategies update the _stable_ |
| 102 | +version in-place. There is a single stable channel, rather than individual |
| 103 | +stable releases, even when using the release-based strategy. |
| 104 | + |
| 105 | +Alpha and beta releases **must** have their stability level appended to the |
| 106 | +version, followed by an incrementing release number. For example, `v1beta1` or |
| 107 | +`v1alpha5`. APIs **should** document the chronological order of these versions |
| 108 | +in their documentation (such as comments). |
| 109 | + |
| 110 | +Each alpha or beta release **may** be updated in place with backwards-compatible |
| 111 | +changes. For beta releases, backwards-incompatible updates **should** be made by |
| 112 | +incrementing the release number and publishing a new release with the change. |
| 113 | +For example, if the current version is `v1beta1`, then `v1beta2` is released |
| 114 | +next. |
| 115 | + |
| 116 | +Alpha and beta releases **should** be shut down after their functionality |
| 117 | +reaches the stable channel. An alpha release **may** be shut down at any time, |
| 118 | +while a beta release **should** allow users a reasonable transition period; we |
| 119 | +recommend 180 days. |
| 120 | + |
| 121 | +### Visibility-based versioning |
| 122 | + |
| 123 | +[API visibility][] is an advanced feature provided by Google API infrastructure. |
| 124 | +It allows API producers to expose multiple external API views from one internal |
| 125 | +API surface, and each view is associated with an API _visibility label_, such |
| 126 | +as: |
| 127 | + |
| 128 | +```proto |
| 129 | +import "google/api/visibility.proto"; |
| 130 | +
|
| 131 | +message Resource { |
| 132 | + string name = 1; |
| 133 | +
|
| 134 | + // Preview. Do not use this feature for production. |
| 135 | + string display_name = 2 |
| 136 | + [(google.api.field_visibility).restriction = "PREVIEW"]; |
| 137 | +} |
| 138 | +``` |
| 139 | + |
| 140 | +A visibility label is a case-sensitive string that can be used to tag any API |
| 141 | +element. By convention, visibility labels should always use UPPER case. |
| 142 | +An implicit `PUBLIC` label is applied to all API elements unless an explicit |
| 143 | +visibility label is applied as in the example above. |
| 144 | + |
| 145 | +Each visibility label is an allow-list. API producers need to grant visibility |
| 146 | +labels to API consumers for them to use API features associated with the labels. |
| 147 | +In other words, an API visibility label is like an ACL'ed API version. |
| 148 | + |
| 149 | +Multiple visibility labels **may** be applied to an element by using a |
| 150 | +comma-separated string (e.g. `"PREVIEW,TRUSTED_TESTER"`). When multiple |
| 151 | +visibility labels are used, then the client needs only _one_ of the visibility |
| 152 | +labels (logical `OR`). |
| 153 | + |
| 154 | +By default, the visibility labels granted to the API consumer are used to verify |
| 155 | +incoming requests. However, a client can send requests with an explicit |
| 156 | +visibility label as follows: |
| 157 | + |
| 158 | +``` |
| 159 | +GET /v1/projects/my-project/topics HTTP/1.1 |
| 160 | +Host: pubsub.googleapis.com |
| 161 | +Authorization: Bearer y29.... |
| 162 | +X-Goog-Visibilities: PREVIEW |
| 163 | +``` |
| 164 | + |
| 165 | +A single API request can specify at most one visibility label. |
| 166 | + |
| 167 | +API producers can use API visibility for API versioning, such as |
| 168 | +`INTERNAL` and `PREVIEW`. A new API feature starts with the `INTERNAL` label, |
| 169 | +then moves to the `PREVIEW` label. When the feature is stable and becomes |
| 170 | +generally available, all API visibility labels are removed from the API |
| 171 | +definition. |
| 172 | + |
| 173 | +In general, API visibility is easier to implement than API versioning for |
| 174 | +incremental changes, but it depends on sophisticated API infrastructure support. |
| 175 | +Google Cloud APIs often use API visibility for Preview features. |
| 176 | + |
| 177 | +[AIP-180]: https://aip.dev/180 |
| 178 | +[AIP-181]: https://aip.dev/181 |
| 179 | +[AIP-213]: https://aip.dev/213 |
| 180 | +[AIP-215]: https://aip.dev/215 |
| 181 | +[api visibility]: https://github.com/googleapis/googleapis/blob/master/google/api/visibility.proto |
| 182 | +[semantic versioning]: https://semver.org/ |
0 commit comments