I have read several times that a Microservice should be an independent software unit. But what does that mean exactly and is it really achievable for each business case? Does that mean that I can run a microservice stand alone without any other microservice and use the full functionality of that microservice? Or do I get the idea wrong of independent microservices?
ProductCatalog microservice for example:
Yes this microservice can run independently. I can start it and perform different CRUD operations for my products without the need to run another microservice. Further I can also use this service to define different product categories and so on. Of course the microservice has its own database. This microservice has no dependency to other services and stands for its own.
Same goes for a
Customer microservices which stores the corresponding data of the customers of the system. Further it is also responsible for the user authentication.
But what about a
This microservice performs a checkout to purchase one or more products for one user with a given paymethod. To perform a checkout the service requires a request containing the products the customer and maybe the prefered paymethod. When running this service independently it would be possible to perform a checkout for products which may not exists in the
ProductCatalog as there is no dependency to the
ProductCatalog microservice and therefore no verification is possible. This would or can lead to a data integrity problem. If there would be a verification against the
ProductCatalog microservice the
Checkout microservice would not run independently.
So my question is if this is the case when saying that microservices should be independent units of software. Or do I miss something here?
Personally, I think that the microservices should run independently. This makes testing and development much easier. However, I am concerned about data integrity and the fact that this may result in redundant data. For example the transaction history in the Check-out Service: The products there may have different or fewer data than the products in the
ProductCatalog microservice Service. Since not all data is required for the checkout itself. To make this clear: Transaction history means that Customer X has bought [A,B,C] Product with Paymethod YZ.
PS: I am aware that the validation can take place in an API Gateway / Aggregator or similar. The API Gateway / Aggregator is a facade for bundling the microservice backends. The clients communicate with the API Gateway and not directly with the microservice backends.