Versioning is broken by design
Issue The current versioning scheme incorrectly implements semantic versioning (semver). Under semver, a major version increase breaks backward compatibility, meaning that client code needs to be updated. In case of autorest-generated SDKs, however, major updates may be impossible to use with any amount of client code updating. That is because SDKs take dependencies of runtimes that themselves introduce breaking changes. If a client application needs to use SDK1 that has a dependency on Microsoft.Rest.ClientRuntime.dll v1 and at the same time SDK2 that has a dependency on Microsoft.Rest.ClientRuntime.dll v2, that application would be impossible to implement.
Background In .NET, there are several versioning strategies that are well understood, each having its own pros and cons.
- Always having one version of a component - any updates are done in-place. This is the most common strategy, jokingly called "DLL hell" because of the potential of one component's upgrade to break another component that shares the same dependency. This approach requires strict backward compatibility rules: interfaces implemented by the components cannot have members removed; interfaces implemented by the client cannot have members added, etc.
- Having several versions of components side-by-side. This was once a preferred .NET strategy, but it works best when components are installed in the GAC. It is sometimes referred to as "side-by-side hell" because of the bloat and maintainability concerns. Outside of the GAC, the possibility of having several versions of an assembly in an app-domain still exists, but is very complex to implement and is definitely discouraged. One workaround for that is to include version number in the assembly name when introducing breaking changes, e.g. Microsoft.Rest.ClientRuntime.v1.dll vs. Microsoft.Rest.ClientRuntime.v2.dll.
- Not having dependent components. Autorest-generated SDKs do not really need a common runtime. REST interfaces are simple by design and runtimes will never become complex for that reason. The biggest drawback is not having a common exception type to catch when handling failures for multiple SDKs in the same try/catch block, but that is a minor inconvenience.
Recommendation I recommend that AutoRest stick with in-place updates for runtimes but stick to 100% backward compatibility. Things like retry strategies and OData-style query string parsing do not need to break backward compatibility. Types where it may be desirable to break backward compatibility should move out of the runtime and into the generated code (e.g. IAzureClient). Getting rid of runtimes altogether is another good approach which is very reliable and cheap because it does not require setting up a system for ensuring backward compatibility.
:+1:
This is causing real customer pain right now. I like the idea of keeping things that are likely to change in the generated code rather than a shared library. However, there is a lot of value in keeping types like CloudException in a common library -- we just need to be much more disciplined about backward compatibility.
@stankovski @devigned @Azure/adx-sdk-team Would love to hear your thoughts on this.
Ok, this is going to be a little bit of "Water is wet", so I apologize ahead of time.
Generating a ton of code because of repetition via generating the runtime over and over is not desirable and a design philosophy we decided on after much debate. We aspire to make the code as close to what you would write by hand as possible.
Breaking changes in the runtime are to be avoided as much as possible, and will continue to be.
@brjohnstmsft it is true making breaking changes can hurt customers, but only the customers that need to take a dependency on the new code. There is no reason to absolutely cause this unless the client library also needs to use the new version of the dependency. If the pain is too great, then one could use the old version and not require customers to update to the new major version.
One is not forced to take the major version update unless they need the new features.
One is not forced to take the major version update unless they need the new features
They do not necessarily have the choice - some old SDKs may be using api-versions that are no longer supported and they need to move forward, while others are still using old runtimes. Your design philosophy is right, but the practice does not follow it. The guidance that every SDK lock itself to just one major version of the runtime will be the doom of AutoRest, since it is only sustainable within one team. A lot of customer pain is inflicted by nice-to-have features (e.g. GenerateClientRequestId property on IAzureClient) which had workarounds. This is only happening because the AutoRest team presently also owns generating maintaining most SDKs and thanks to that, relatively few customers are hurt.
Breaking changes in the runtime are to be avoided as much as possible, and will continue to be.
This is a misstatement. Microsoft.Rest.ClientRuntime.Azure has increased its major version twice in just six months! Making it a rule to specify upper bounds on NuGet dependencies kills the usefulness of NuGet.
This is a misstatement. Microsoft.Rest.ClientRuntime.Azure has increased its major version twice in just six months!
The entire AutoRest project is less than a year old (Feb. 20th is first commit). There is churn in young projects. It's the nature of software engineering. It's hard to expect otherwise.
Making it a rule to specify upper bounds on NuGet dependencies kills the usefulness of NuGet.
You most definitely should have a ceiling on the major version of your dependencies. I'd even say it's good practice to have a ceiling on minor as well.
It's up to you, but by no means would I invite breaking changes into a project by leaving an open ceiling on dependencies. That's precisely why we have semantic versions.
Here's guidance from a co-creator of NuGet http://blog.davidebbo.com/2011/01/nuget-versioning-part-2-core-algorithm.html
When an upper bound makes sense
In most cases, simply specifying a minimum version is the way to go, as illustrated above. This does not imply that upper bounds shouldn't be specified in some cases.
In fact, an upper bound should be specified whenever a component is known not to work past a certain version of a dependency. [...] But the key thing here is that the incompatibility has to be known before such range is used. e.g. if at the time A is written, X 2.0 doesn't even exist, it would be wrong to set a range of [1.1,2.0).
In his blog post, David presents a well-articulated explanation of the rationale behind that guidance. What is your counter-argument?
I cannot recall a single instance when I could not upgrade a component because of incompatibility with another. JSON.NET does not have this problem, nor does Microsoft.OData because they take care to not create impactful backward incompatibilities. To take a specific instance of a break introduced by the recent release - the addition of GenerateClientRequestId property to IAzureClient - it is definitely a backwards compatibility break. However, if at the same time a virtual property with the same name was added to the ServiceClient class, that break would not have been impactful.
Here's the semver guidance - if you want to iterate fast, you need to use major version 0 and need to evaluate carefully the impact of your changes.
Enough of the theory. Here's a practical question. Let us say I've been using an SDK A build with version X of the runtime. Today I decide to incorporate SDK B that targets version Y, but there is no version of SDK A for that runtime. Is this an "out of scope" scenario for your team? Imagine a world in which a package built with JSON.Net v6 could not coexist with JSON.Net v7! How's AutoRest runtime different?
.NET makes versioning difficult across the board :-(. I'm not for or against changes here, just pointing out the obvious - with so many services and different components, things are going to be a challenge.
I remember the challenges that binding redirects introduced into these projects at one point during the migration to .NET 4.5+.
An alternative for management operations is likely going to be to go straight to ARM templates, is that an option for folks?
@iouri-s I don't agree with the supposition that an upper bound on major version is a bad thing. According to semver 2.0 a major version increment is a breaking change by definition.
MAJOR version when you make incompatible API changes semver 2.0
One can't tell the future when setting a dependency's upper bound. Though, one can be certain that if the dependency is following semantic versioning, a major version increment indicates a breaking change. Based on that, it's a gamble that your libraries in the wild will not suffer catastrophic failures from a major version increase if you have no upper bound.
Bottom line, not specifying an upper bound on major version is an inherently unsafe practice. That's why many, if not most, dependency managers in other languages will give the developer a warning if an upper bound is not specified.
An alternative for management operations is likely going to be to go straight to ARM templates, is that an option for folks?
@jeffwilcox, that's always a good option (imho).
A lot of customer pain is inflicted by nice-to-have features (e.g. GenerateClientRequestId property on IAzureClient) which had workarounds.
The reason for including these "nice-to have" features was to minimize future breaking changes. We knew we were going to have breaking changes in HttpOperationException so we have bundled the other breaking changes together. I wish we have written perfect software from the first time, but the unfortunate reality is that breaking changes do happen.
As @jeffwilcox has mentioned, the versioning story in .NET is not perfect and we have to have a strategy for when the breaking changes do happen.
The current strategy is to follow semantic versioning combined with bracketed versions in NuGet and have breaking changes not more than once a year (yes, we have revved ClientRuntime more than once in the past year, however there were no clients using it prior to Microsoft.Rest.ClientRuntime.Azure v 2.0). This strategy allows us to ensure client compatibility for the latest API versions and avoid runtime exceptions. It also allows our customers to have common exception types to catch and interfaces to access. The main drawback of this strategy is that it forces us to re-publish all clients when the ClientRuntime has a major version change and it also makes it impossible for users to mix older clients with newer ones.
The alternative strategy would be to have multiple ClientRuntime packages for each major version. This strategy would enable mix and match scenario but would have its own drawbacks. First of all this is not a very common pattern among packages in NuGet and goes against the semver (that breaking change is indicated by a major version change but a package ID change). Also, type names or namespaces would have to be unique (to allow for side-by-side scenario) which would make the API look ugly and the customers would need to have deep knowledge of the clients to know which exception types to catch. Finally this would mean an increased maintenance cost for us when critical non-breaking bugs need to be fixed across multiple versions of ClientRuntimes.
An alternative for management operations is likely going to be to go straight to ARM templates, is that an option for folks?
@jeffwilcox, that's always a good option (imho).
@jeffwilcox @devigned That is only a workaround for management libraries. Not all SDKs that take a dependency on ClientRuntime are for resource management (like Search for example).
@stankovski The side-by-side thing is pretty extreme. The only example I can think of is OData, which really had no choice because versions 3 and 4 of the protocol have to co-exist but are very different. Restricting breaking changes to once a year sounds like a reasonable compromise to me.
@jeffwilcox - are you questioning the need for client libraries in general and specifically AutoRest? ARM templates only handle PUT operations. There's also GET, DELETE, POST and PATCH. Besides, some developers just prefer imperative programming.
If you break compatibility, you should increase the major version. It is, however, your choice to break compatibility or not, and so far you have been doing it frequently (in other words, without regard for your customers). If the runtime had version 0, that would be perfectly fine, but with v 2-> v 3 transition it is not. Also, all breaks are not created equal, and the last break affected 100% of customers as one cannot instantiate the client, which is as severe as it gets. Common sense dictates that while backwards compatibility is not very important in a standalone product, it is pretty important in runtimes and extremely important in runtime dependencies (or runtimes for runtimes), this is why you should seek inspiration in existing successful runtimes, such as json.net. However, your approach to versioning is an abrupt departure from existing practices and prescriptions of NuGet architects. As a customer, I reported the issue and as an engineer who had used countless runtimes and participated in building several, I gave you recommendations. I pointed out scenarios that were broken and asked how they were going to be handled. Instead, @devigned mentions "philosophy" and "debate" which are of no relevance to me as a customer. The practice of locking upper versions appears extremely uncommon and goes directly against existing guidance. Same goes for creating incompatible runtimes (and especially "runtimes for runtimes"). The only way to go in these scenarios is to never break compatibility (so you'd stay as v1 forever). This would restrict innovation and necessarily create runtimes that over time, do not look as pretty as ones designed from scratch with prescience for all the future requirements. This is the reason many runtimes have IBlah2 and IBlah3. You are making good points about namespace clash etc. There are workarounds that we all know, but no solution is perfect. If you decide that there is really no way to introduce a new feature in a compatible way, and increment the major version of your runtime, you have to assume that many customers will be unable to upgrade and will stay on the old version. You may also find out that some customers prefer the old version because they have a different opinion the cost/benefit of the transition than you. I hope I made it clear that the version lock created by the current strategy is, in my opinion, absolutely inacceptable. You have heard all my arguments and I will not be wasting any more of your time by rephrasing what I already said. This is your project, build it as you see fit.
Closing the issue as I think we've covered this pretty well.