hemerajs / hemera

🔬 Writing reliable & fault-tolerant microservices in Node.js https://hemerajs.github.io/hemera/
MIT License
806 stars 70 forks source link

microservice versioning #46

Closed pocesar closed 7 years ago

pocesar commented 7 years ago

What would be the opinionated way on versioning the microservices? How to have 3-4 versions running side-by-side?

StarpTech commented 7 years ago

One way is to archive it with a suffix in the topic name e.g

topic:math:v1

or in the pattern of your Server Methods

{
topic: "math",
cmd:" add", 
Version: "1"
}

or you have different NATS Server for different API Version.

StarpTech commented 7 years ago

It's up to the use case.

pocesar commented 7 years ago

right now I use semver for services (without the patch), and my service locator can deal with version pinning or version ranges, like '<=1.1' or '^1.1', so, asking for a version '^1.0' would yield access to any available 1.0 and 1.1 versions, could this be done?

just to explain why I use semver, since minor versions are backward compatible always, I can use blue/green without having to worry older services breaking when 1.0 goes offline and replaced by 1.1 for example

StarpTech commented 7 years ago

At first I recommend you to get familiar with NATS https://nats.io/documentation/ NATS is pub/sub system. In hemera every service is located by his topic name. If you want provide a service with different versions you can represent it with the topic name

On service level:

hemera.add({ topic: "math:v1.0" })

or with a wildcard

hemera.add({ topic: "math:v1.*" })

Wildcards in Nats: https://nats.io/documentation/internals/nats-protocol/

On application level

You can also express you different version with a different pattern so that your service is always accessible via the same topic. I prefer this solution because you have the most flexbility and less effort but this orientates on the complexity of both versions.

hemera.add({
topic: "math",
cmd:" add", 
version: "1"
})

or with regex

hemera.add({
topic: "math",
cmd:" add", 
version: /1\.[0-9]/
})

On server level

E.g different regions should only have access to api version 1.0. You can connect those clients with a different NATS server which exposed a restricted set of services. After a certain period of time you can also combine both server to a cluster. This use case is very special but possible.

You have three options how to deal with versioning.

StarpTech commented 7 years ago

I will update the docs with this topic

StarpTech commented 7 years ago

Update the docs I close this issue.