I'm developing this project using Spring and hosting in AWS EC2 instances. As few new requirements coming up, I have to change my API contracts. But I don't want to break the current clients. So, I'm trying to implement some REST APIs with versioning. So that whenever I update the endpoints the consumer applications won't crash. But I'm confused on how to do the API versioning. I thought of two ways.
Create a next version endpoint in the same server,(in spring using RequestMaping("/v1/api1"),RequestMaping("/v2/api1") something like this.)
Other wise completely run the v2 APIs in new server instance but keep the same API endpoint footprint and use AWS APIGateway as a proxy and configure the versioning there, then route to old server and new server depending on the version number in the request.
But the first approach will lead to lot of code duplication and code management messy I believe. Because we are keeping the same functionality with variations.
In the second approach I have to keep two set of instances for bot versions if me Version increases then It's hard to manage those instances, specially, when I will have around 15 micro-service instances. And it'll not be cost effective also. Because my company is a startup , so I need to consider this fact also.
Is there any best practices regarding API versioning and managing multiple version of endpoints? I'm open for any suggestions and guidelines. If multiple server is the solution also, I'm open to reconsider the cost limitations. I need the best solution for this problem.