What is the best practice to adapt for versioning in a Microservice Based Architecture, in terms of supporting multiple versioned deployment of the same service during runtime a
What is the best practice to adapt for versioning in a Microservice Based Architecture
One strategy that I use in my microservice project is to version through routing.
We use JSON RPC 2.0 so it's a little different from REST but it can be applied.
We only use major versioning and try to live with the old and the new version at the same time to let the time to consumer to be updated.
Things to take care of
Avoid having more than two versions of a service in production (really hard to manage if you have some model updates).
Find a way to tell the consumer that the version there are using is deprecated.
I know that some microservice architecture lives without versioning but it means that you have a strong coupling between consumer and producer so I may not recommand this approach.
To answer the second question
how the consumers would be able to use different versions?
It sounds not possible because a consumer should only use one version at a time.
If you want it to know that the version is available to use it at runtime you can walk through feature flipping coupled with a service discovery.
Your consumer will ask regularly to a service discovery if the route x exists. If true then use the feature, otherwise continue with the current version. It could works but it is kinda tricky to manage.