How Are Microservices and Applications Related?
Applications are dependent upon a microservice. Also, microservice to microservice are dependent. Knowing these relationships is key in keeping an application running without issues. Typically, microservices are used for the back-end database interactions. For example, a user profile microservice would handle the Create, Retrieval, Update and Deletion of the user profile data. In theory, there should be one microservice for each CRUD action. I find that this is too fine grained. Putting a functional box around the data makes it easier to handle in the long run. I approach this process as I do with Object Oriented Programming(OOP). They both encapsulate methods needed to interact with the object inside the object itself. Microservices should be treated in a similar manner.
Microservices can be independent upon the application. For example, it doesn’t need to know what the application (consumer) is doing with the data it provides. But an application (consumer) needs to know about the microservice that it is interacting with. They have inputs and outputs that the application (consumer) needs to understand in order interact. The application could break if the microservice now takes a new required parameter that didn’t take in the past. This same dilemma will occur between microservices if one a consumer of another. For example, user profile interacts with address GPS microservice.
Let’s Look at an Example
A common scenario:
1. Web page displays the User Profile
2. User Profile micro-service retrieve the user data from the database
Currently the microservice requires the userid as input and will return First Name, Last Name and Phone Number (XXX-XXX-XXXX).
The Web page knows from the documentation the format of the data coming back, specifically the phone number will be area code dash number.
A new requirement needs the country code and for the area code to be split out from the rest of the phone number. The input is the same but the output has changed. The microservice can be altered and deployed independently from the application. All of the cases for these test out fine since they will be checking the new requirement for the phone number.
The Web page on the other hand is dependent upon knowing the inputs and outputs of the micro-service. The web page will break due to the changed output if it is not updated to handle the new format and deployed at the same time as the micro-services.
Are microservices and applications independent of each other? No! Applications are dependent upon them! Knowing these relationships is key in keeping an application running without issues. Dependency management from Builds and application packaging from ARA will highlight which microservices are being consumed by other applications and micro-services. Given this relationship list we can scope out the impact of a change and make necessary changes to keep everything running smoothly.
Backwards compatibility is another key to success and will help this issue but at times backwards compatibility needs to be broken for the greater good. Dependency management and application packaging will provide the tools understand the impact of change. Knowing what is impacted enables you to make the necessary coding changes and make sure everything is deployed as a complete package (application changes in conjunction with microservice changes).