News for hackers. Stuff that matters.
Re:How Shopify Manages API Versioning and Breaking Changes by keithwhor on Thursday December 19, 2019 @09:06AM (#21834954)
Hi everyone. As the founder of an API company, this article has me wondering about the semantics of versioning — so I thought I’d ask the community a question. I hope the Shopify API team doesn’t mind!

When you all think about API versioning, what makes the most sense to you — a semver approach (major.minor.patch) a la NPM, or a date-based approach (2020-01-07) a la AWS? Or is some combination of the two desirable?

At Standard Library [0] we both allow people to publish APIs but also publish API proxies on behalf of partners (Stripe, Slack + others) using a semver approach. It’s not perfect but theoretically enforceable (schema parameter additions can be forced to require a minor update, schema parameter removals can be forced to require a major update). We’ve just stuck to this semver approach based on intuition and haven’t had negative feedback about it, but I do like the idea of time-based versioning.

Would love thoughts! If you want to play around you can build your own APIs using https://code.stdlib.com/, which uses the FunctionScript specification [1] to enforce HTTP request schemas.

[0] https://stdlib.com/

[1] https://github.com/FunctionScript/FunctionScript

Re:How Shopify Manages API Versioning and Breaking Changes by Waterluvian on Thursday December 19, 2019 @09:59AM (#21835410)
I don't think there's one right answer, but my opinion is:

- Treat APIs as immutable.

- Any mutation results in a wholly new API version, not a patch or minor update.

- The developer will learn what changed, and how much changed by reading the patchnotes, not looking at which semver numbers changed. This is probably a healthy practice to encourage.

- Don't change APIs so much. The interface should be very carefully designed and tested and shipped like an NES cartridge: consider it impossible to fix once its shipped.

Therefore just start with `1` and increment each time.

The reason I don't like semver is that it's a developer convenience that leads to sloppy practices. You built your product against a specific API. If the API changes, you need to re-run your entire API evaluation, testing, blessing workflow. If the delta is tiny (what would have been a patch change) then yay, your task is likely going to be very simple. But you shouldn't see a bump version update and decide you can cut corners.

Re:How Shopify Manages API Versioning and Breaking Changes by keithwhor on Thursday December 19, 2019 @10:11AM (#21835498)
I don’t disagree with your assessment on semver as it currently exists for, say, NPM packages.

I do think that with web APIs specifically, the surface area is a lot smaller — the HTTP interface is literally all you touch — so semver, in its purest form, is actually completely enforceable as long as you understand the API schema.

Our team has talked a lot about either hard-enforcing or automatically applying semver where applicable. My question to you is — does this sound reasonable, and if you knew a semver contract was actually bound to implementation (i.e. guaranteed and not implied), would you trust it more?

Re:How Shopify Manages API Versioning and Breaking Changes by Waterluvian on Thursday December 19, 2019 @10:42AM (#21835819)
I don't really trust semver insofar as there's nothing to trust, in my opinion. What am I trusting? That I don't have to understand what changed and can take semver's word for it? To me, personally, that's an abdication of my responsibility to know what I'm utilizing and implementing against.

What's the practical value you're hoping to gain by hard-enforcing semver, especially if the surface area of HTTP APIs is a lot smaller? And this isn't a loaded question. I might just not be privy to your team's needs.

Also consider (and this again falls within the realm of personal opinion) the value of achieving _maximum possible statelessness_ as a developer. If I'm reading you right, you're asking me to know and remember, and probably write down somewhere, that your API's versioning means something different than others. So I now have another branching path to maintain: how to behave when your API changes. What I like about the simple numbered API schema is that I can come back to the API usage in a stateless manner. I just see that the number is different and I know what to do: learn what changed and decide if I have to act on it. Of course I could do this by looking at a semver as a unique identifier without semantic meaning, but that kind of leads to my initial point: encourage best practice by not giving the developer a semantic shortcut to which they can abdicate responsibility.

Re:How Shopify Manages API Versioning and Breaking Changes by keithwhor on Thursday December 19, 2019 @10:53AM (#21835949)
I think you misunderstand where I’m coming from with my line of questioning.

I’m asking questions because we provide tools that standardize the API development experience. Semver is trustable if the tools create the contract instead of the developer that decides to build the API. We deliver the tools that create the contract.

In this sense, APIs built and delivered atop our platform don’t need to “encourage best practice,” best practice is — or at least can be — hardcoded in with no potential for footguns.

Your concerns about semver are well-founded. I’m asking questions because I’m pondering aloud if we can fix them and change semver — with respect to APIs — from a social contract to a coded contract, and include tools necessary to inform end-users of API changes. :)

Does that make more sense?

Re:How Shopify Manages API Versioning and Breaking Changes by Waterluvian on Thursday December 19, 2019 @10:58AM (#21836001)
Yeah it does. Thanks for clarifying. I think there's a very complex conversation to be had here, especially since you're working on a meta-level of tooling to ease API development.

With two days before my first vacation of the year, my brain is a pile of mush. I'm going to politely and apologetically bow out of this conversation. =)

Re:How Shopify Manages API Versioning and Breaking Changes by wongarsu on Thursday December 19, 2019 @11:09AM (#21836129)
I don't think semver is easily enforceable. Take for example the discussion in this thread about stripe changing the order in which hooks fired, which completely changed the meaning of a null value in the next_payment_attempt field. Just looking at a traditional API schema wouldn't reveal any change, yet this was a major breaking change to some. Maybe you can create an API schema which encompasses the order in which hooks fire, but that still doesn't help if somebody changes the semantics of a field without changing its name or type.
Re:How Shopify Manages API Versioning and Breaking Changes by setr on Thursday December 19, 2019 @10:39AM (#21835783)
Tbh, it doesn't matter. But the semantics should be such that it doesn't matter -- the user of the API shouldn't care whether it's implementation bounded or not. But Everytime you break that abstraction, trust in the abstraction is necessarily reduced.

Bounding to implementation is just the easiest way out -- if your policies, tests and protocols consistently fail to uphold that abstraction, then the you can fallback to this very simple (presumably innefficient) strategy to do so.

But I, as a dev, just want a stable API, and I don't care how it's done.

Re:How Shopify Manages API Versioning and Breaking Changes by zerkten on Thursday December 19, 2019 @02:24PM (#21838275)
How would your trust be impacted if there was better communication ahead of a breaking change you could almost agree with? i.e. the experience has been well beyond that which you currently expect and have been provided good reasons proactively.

The gap I see a lot starts with a bad versioning strategy and continues through bad API analytics to bad communications for developers.

The API provider should be able to understand all of the individual clients to the point where they can decide to progressively migrate them one-by-one, if necessary. There shouldn't be a need to use metadata like IP addresses or user-agents to try and identify the clients. Unless someone has walked through these scenarios ahead of time, it's difficult manage when issues arise.

Re:How Shopify Manages API Versioning and Breaking Changes by asdkhadsj on Thursday December 19, 2019 @10:51AM (#21835931)
What does a codebase look like with these API versioning exactly?

I feel like code bloat would be hard to maintain. Obviously I could take two endpoint handlers that have the same functionality and move their behavior into a shared function, but there's also tests to consider. As time went on, I'd have a pile of tests running against seemingly random versions.

Eg, `test_blog_create()` might test v1 and v2 of the API as that specific endpoint didn't change, but suddenly in v3 the API _does_ change, so now I need to write a slightly different test to handle that new functionality. `test_blog_create_v3()` or w/e.

I'm not arguing against it, merely noting what I've previously thought about as problematic for implementing versioned APIs.

Thoughts on how best to manage the code base?

Re:How Shopify Manages API Versioning and Breaking Changes by Waterluvian on Thursday December 19, 2019 @11:04AM (#21836086)
Versioning is hard. Versioned APIs are very hard. I'm in an especially tricky spot because we've got customers that might refuse to upgrade our product for years and years, if ever.

Two approaches I've taken, with a blogpost worth of thoughts on them:

1. Every version is a whole new database/webserver stack. You shut the oldest one down when the last customer migrates off it. The bloat is real, but it's dead simple and it works.

2. A single database with a webserver that exposes all the versions. The contract is that the database shall not undergo destructive migrations. Only additive migrations. Or if you must, modify schema in a way that you can deterministically generate every previous API's view. Again, discard older versions when the last customer has been migrated off.

I'm sure you can immediately smell some problems with either of these approaches. Sacrifices are definitely made.

Re:How Shopify Manages API Versioning and Breaking Changes by emilsedgh on Thursday December 19, 2019 @02:44PM (#21838467)
Every version is a whole new database/webserver stack. You shut the oldest one down when the last customer migrates off it. The bloat is real, but it's dead simple and it works.

That means data is different between API versions?

Re:How Shopify Manages API Versioning and Breaking Changes by Waterluvian on Thursday December 19, 2019 @08:15PM (#21840971)
Yes. But that works. Becuase a customer's data lives in only one version. When the customer upgrades their data gets migrated. Weird. Dead simple. Works.
Re:How Shopify Manages API Versioning and Breaking Changes by Corazoor on Thursday December 19, 2019 @03:14PM (#21838765)
There is definitely multiple ways to handle that, but splitting your API into frontend and backend seems to be a common and good approach. The backend is basically the "real" internal API, subject to changes. The frontend consists of nothing more than forwarding functions, that take their input from the outer world and translate it to backend API calls. How you organize Code reuse depends on the language, but inheritance is not a bad way to do it, although you might run into trouble with the size of your hirarchy. You can circumvent that with maps of functions/lambdas, like prototyping in Javascript.

For testing you then have your usual set of tests for the backend, but for the frontend you just test if the translation between public and internal API is correct. Very easy to test for in most cases. If you then organize your tests exactly like your frontend Version, i.e. some kind of inheritance, you only ever have to add tests for the changes in your new Version.

It is definitely more work than just having one ever changing API, but it's not that much of a hassle imho.

Re:How Shopify Manages API Versioning and Breaking Changes by m12k on Thursday December 19, 2019 @09:44AM (#21835277)
I prefer semver, but it's still not exactly what I want. What I'm looking for is the answer to 'how painful/risky is upgrading likely to be?'. I expect an x.x.1 release to be zero/low risk - small fixes only within current api and contract. I expect a 2.x.x release to come with major risk of breakage (and I'll almost always want to wait for 2.0.2-2.0.3 before actually upgrading - and I expect a 1.x.x -> 2.x.x release to have a risk of bigger changes compared to a 5.x.x -> 6.x.x since the latter is expected to have the fundamentals ironed out by now). But there doesn't seem to be much consensus on whether an x.1.x release can have breaking changes or not - or maybe they don't come with as strict a definition of a breaking change as Shopify is using - so I'm left with treating them the same as 2.x.x (though usually I don't wait for x.x.1 in this case).
Re:How Shopify Manages API Versioning and Breaking Changes by gen220 on Thursday December 19, 2019 @10:15AM (#21835534)
I’m pretty sure the semver definition for a x.2.x change is that you’re adding surface area to your interface, in a way that doesn’t overlap with existing surface area, i.e. bytes sent over the wire for x.1.x will result in the same response bytes for x.2.x, all else being equal.

Note that the phrase non-overlapping is where all the complexity is hidden; it’s actually tricky to guarantee that an addition hasn’t changed any existing queries. For example, adding an enum value will mess up clients who query with max(enum_value). Technically, they’re not sending the same bytes, so the change is non-overlapping, but the client might disagree :)

Re:How Shopify Manages API Versioning and Breaking Changes by keithwhor on Thursday December 19, 2019 @09:46AM (#21835292)
Would a tool that easily shows you documentation / schema changes between API versions be useful to you, or create more trust with a SaaS provider if they offered it?
Re:How Shopify Manages API Versioning and Breaking Changes by Navarr on Thursday December 19, 2019 @09:22AM (#21835101)
I do not know any advantage of date-based versioning, other than someone knowing how new it is.

Semver is important for knowing whether or not to evaluate for breakages. You can theoretically combine both of these by making the date the patch version or supplying it as a version metadata

Re:How Shopify Manages API Versioning and Breaking Changes by Znafon on Thursday December 19, 2019 @09:33AM (#21835192)
> I do not know any advantage of date-based versioning

It can be very useful for continuous improvement and handling forward compatibility. Here's how Stripe do it:https://stripe.com/en-fr/blog/api-versioning, we found that very convenient.

Re:How Shopify Manages API Versioning and Breaking Changes by keithwhor on Thursday December 19, 2019 @09:37AM (#21835229)
I think it’s the implied stability, especially for long-standing APIs. S3’s API is 2006-03-01 — meaning there haven’t been breaking changes in over 13 years. This creates a psychological contract with developers that nothing’s changing anytime soon.

The trade off is that AWS has some godawful APIs (DynamoDB has the least intuitive API I have ever worked with). But they’re stable.

If you go with a date-based approach and create a process + contract whereby you guarantee API stability and / or deprecation date, the developer always knows exactly how much time they have before an upgrade.

Re:How Shopify Manages API Versioning and Breaking Changes by solatic on Friday December 20, 2019 @08:01AM (#21843815)
What's the point of a patch release for an API?

If you publish API version 1.0.0, and then internally you fix something and publish 1.0.1 (remember: a patch doesn't change the interface at all), should you continue to serve both the 1.0.0 and 1.0.1 APIs? How are they different from the consumer's perspective? What if your reason to release 1.0.1 is to fix a security issue - in what world is it ethical to continue to serve 1.0.0? If you can discontinue serving 1.0.0 at any time (because of a security patch released with 1.0.1), then you can't offer any long-term durability guarantees for early patch versions, and so indeed, offering older patch versions (when newer patches didn't fix security issues) is more likely to break your consumers when you're forced to discontinue older patch versions for security reasons, than if you refused to serve patch-level variants in the first place.

Because you, as upstream, have no control over whether the pure addition of fields will break downstream (since downstream may or may not be strict about what they accept), you should only offer semantically versioned minor releases if you're willing to guarantee durability for earlier minor versions, and can maintain multiple minor versions of your API in parallel. If not, then be explicit about the potential of your changes to break downstream - use timestamps and document sunset dates.

Re:How Shopify Manages API Versioning and Breaking Changes by bmn__ on Thursday December 19, 2019 @01:36PM (#21837767)
> When you all think about API versioning, what makes the most sense to you — a semver approach (major.minor.patch) a la NPM, or a date-based approach (2020-01-07) a la AWS? Or is some combination of the two desirable?

We're talking about HTTP APIs, right? Then neither. These are solutions with bad trade-offs for the problem at hand.

Version the link relations. This follows the principles that make the Web successful (a.k.a. REST). If that seems weird to you¹, consider the following:

You have a personal homepage type Web site. When you change or add or remove a document, do your users need to upgrade their user agent to keep using the site? Why not?

----

¹ Numerous developers are so enamoured with putting a version number into document URIs that they cannot fathom not doing it. This is another mutilation of the mind à la Dijkstra.

Re:How Shopify Manages API Versioning and Breaking Changes by eapache on Thursday December 19, 2019 @09:38AM (#21835231)
My impression is that semver makes far more sense for published libraries (DLLs or ruby gems or npm packages etc) while date-based makes far more sense for SaaS APIs. The constraints and usage patterns are fairly different between the two.
Re:How Shopify Manages API Versioning and Breaking Changes by kenrose on Thursday December 19, 2019 @09:47AM (#21835307)
One challenge with date based is that it can make your API seem old if it’s really stable. For example, see PagerDuty’s v1 events API:

https://events.pagerduty.com/generic/2010-04-15/create_event...

Customers there would sometimes ask if that API was still relevant given its date is 9+ years old.

In Shopify’s case, where there are quarterly version bumps and deprecation over time, date based makes better sense.

Re:How Shopify Manages API Versioning and Breaking Changes by keithwhor on Thursday December 19, 2019 @09:41AM (#21835258)
What specifically about SaaS API constraints do you think makes a date-based approach more appealing than semver?

My high-level feeling is that it’s just way more difficult to ship a SaaS API than a Ruby Gem, so adding semver to that is just another layer of API management everybody has to agree on. Do you agree with this assessment?

Re:How Shopify Manages API Versioning and Breaking Changes by eapache on Thursday December 19, 2019 @09:51AM (#21835337)
For most published libraries every old version is always available and upgrading is never mandatory. For SaaS APIs the constraints of the business means that very few businesses (Stripe being the notable exception) want to support more than a handful of versions at a time, which results in versions regularly reaching end-of-life and completely disappearing. In this world, upgrading to newer APIs is mandatory and fairly frequent.

The result is that API version handles need to prioritize different information. Libraries need a format that makes it easy to ballpark the size of changes between arbitrary not-strictly-sequential versions. SaaS APIs need a form that makes it easy to infer support windows and end-of-life status.

Re:How Shopify Manages API Versioning and Breaking Changes by ahnick on Thursday December 19, 2019 @10:52AM (#21835934)
> "SaaS APIs need a form that makes it easy to infer support windows and end-of-life status."

You can infer that from the Release Date though. (e.g. Version 3.4.2 Released on 2019-12-17) To me the power of Semver is that it conveys complex relations between version iterations.

For example:

- 3.4.1 -> 3.4.2 is just fixing bugs in existing functionality

- 3.4.2 -> 3.5.0 is an upgrade containing non-breaking changes

- 3.5.0 -> 4.0.0 is an upgrade containing breaking changes

As a developer, Semver + release date seems to convey everything date based versioning does plus I get the advantage of understanding at glance the importance and risk profile of each release.

Note, this system does not reduce my obligation to run my own tests to verify that the version has in fact lived up to its intention (i.e. a minor version bump did not introduce a breaking change). Even though my obligation is not reduced, it does act as a filter to help prioritize development time for evaluation of performing upgrades.

Re:How Shopify Manages API Versioning and Breaking Changes by keithwhor on Thursday December 19, 2019 @09:57AM (#21835393)
Good points.

Do you think a combination of the two is possible, and how do you think that might work?

year.month.minor.patch?

Re:How Shopify Manages API Versioning and Breaking Changes by thdrdt on Thursday December 19, 2019 @09:23AM (#21835115)
Both don't say much without good changelog.

But with semver you can say: ok, I want every new version up to a new minor version (all fixes). While with a date based version you don't know how 'breaking' the changes will be.

Re:How Shopify Manages API Versioning and Breaking Changes by gregmac on Thursday December 19, 2019 @10:52AM (#21835939)
> Both don't say much without good changelog.

This is a good point. Good changelogs, like any documentation, take a lot of effort and so are unfortunately quite rare.

As an API consumer, to me the ideal upgrade-related documentation includes:

* Detailed release notes for each released version

* For non-GA releases like alpha/beta/RC's, describe the changes since the last small release -- typically consumers of a beta are following dev quite closely

* For GA releases, pretend the alpha/beta/etc don't exist at all. Describe the delta from the last GA release. Consumers don't care about the fix for a bug in a beta they never even knew existed.

* When you do breaking changes, provide upgrade guidance, like "If you were doing x before, now you should do y + z instead"

* If appropriate, consider also keeping separate upgrade guidance documentation for major breaking changes, for those laggard consumers that are going from a much older version like 2.x to 4.x. This allows someone to follow more of a checklist to get up-to-date without having to read 900 pages of individual release notes

You can do this with date-based version, but it's much harder as a consumer to figure out unless there's very good documentation. If I'm upgrading from "2.0.4" to "4.1.1", I know as a absolute minimum starting point I will be looking at release notes for "3.0" and "4.0" and from that, I should get a pretty good sense of the overall effort involved. If I'm upgrading from "2016-11-05" to "2019-12-19", how do I do the equivalent evaluation?

Re:How Shopify Manages API Versioning and Breaking Changes by keithwhor on Thursday December 19, 2019 @09:32AM (#21835180)
How often do you feel like you find / consume changelogs when you’re looking at APIs? I feel like they’re either non-existent or non-obvious for most SaaS companies.

Do you feel like you’d trust a company’s API more if you could peruse the API changelog more easily?

Re:How Shopify Manages API Versioning and Breaking Changes by thdrdt on Thursday December 19, 2019 @10:43AM (#21835831)
It's not about trusting a company. It's about wanting to know what will break if you start using a newer version of an API.

And sometimes you also discover new features that can be really useful.

Re:How Shopify Manages API Versioning and Breaking Changes by keithwhor on Thursday December 19, 2019 @11:00AM (#21836023)
That’s fair! From my perspective that’s something that’s building trust with the SaaS provider. We’ve all heard, “ugh! This API is so shitty!” before — I’m fascinated by what tools and products can be built to prevent developers from feeling these pains.

Thanks for the feedback. Can definitely see that changelogs are really underinvested in across the industry, and it’s useful to have people mention how valuable they are.

Re:How Shopify Manages API Versioning and Breaking Changes by k__ on Thursday December 19, 2019 @09:39AM (#21835241)
I never understood why we settled on semver.

If I have a bug, it's a breaking change. If I fix this bug, it's also a breaking change.

Re:How Shopify Manages API Versioning and Breaking Changes by tclancy on Thursday December 19, 2019 @10:15AM (#21835533)
Your presumption of a collective "we" is at the root of the problem: versioning is one of those things in development where the same word can mean very different things to different people (see also: agile, automated testing). Prior to semantic versioning, there was an approach that looked like an agreed-upon standard to consumers of software packages/ libraries/ APIs but was not.

On one extreme you had certain developers (who I am sympathetic to because it's my personality) who were loath to ever label something 1.0 because it implies Doneness and a freedom from bugs that can never be so. On the other side you had people at chop shops who would bump the major version of some boxed product every time they fixed two bugs. Even if you as a good developer did the research to discover that 0.7.6 of Package A was solid and 5 years older than Package B 7.6, there was a good chance someone above you would declare 7.6 > 0.7.6 and that it was paid-for software so "We can get support from them" and force you to work with a shittier product.

So "we" developers do what we almost always do: we cast about for a better solution and landed on one that made the meaning of version numbers opaque to anyone outside the guild of mages writing code.

In short, semantic versioning may suck hard, but it sucks less.

Re:How Shopify Manages API Versioning and Breaking Changes by k__ on Thursday December 19, 2019 @10:55AM (#21835972)
True.

Semver is like unsound type systems or TDD, most of the time it's okay, until it isn't.

Re:How Shopify Manages API Versioning and Breaking Changes by posedge on Thursday December 19, 2019 @12:30PM (#21837059)
Honestly, I don't see what a non-semantic scheme brings to the table. In SemVer, you can (theoretically) infer compatibility from the version number. A date tells you nothing.
Re:How Shopify Manages API Versioning and Breaking Changes by seelmobile on Thursday December 19, 2019 @10:23AM (#21835625)
(Disclosure: I work at Google on public APIs, opinions are my own)

Google's proposed a "stability" semantic as a third option[0]. TL;DR no breaking changes in the Stable channel but you can add backwards-compatible[1] features in-place.

A permanent Beta channel that's a superset of Stable lets users choose how change-tolerant they are. This lets API producers launch features earlier, knowing they will only impact risk tolerant users if breaking changes are needed. Theoretically this reduces the need for breaking changes in Stable, which require a new Major version.

[0] https://aip.dev/181 [1] https://aip.dev/180

Re:How Shopify Manages API Versioning and Breaking Changes by keithwhor on Thursday December 19, 2019 @10:28AM (#21835677)
Do you think it’s possible to achieve the same sort of system by just using semver + release candidates?

For example, 5.x.x is currently stable, so you release 6.0.0-rc1 (2, 3, ...)?

Re:How Shopify Manages API Versioning and Breaking Changes by NicoJuicy on Thursday December 19, 2019 @06:42PM (#21840442)
V1

V2

V3-dev/v3-test/v3-rc - all related to how many changes you expect

V3