Microservices with Clojure
上QQ阅读APP看书,第一时间看更新

Direct lookup

Although microservices have their own isolated persistence, an application implemented using microservices may need to share data among a set of services to perform tasks. In a monolithic environment, since there is a common database, it is easier to share data and maintain consistency using transactions. In a microservices environment, it is not recommended to provide direct access to the database managed by a service, as shown in the following diagram:

For example, when a user places a new order, the Order Service may need access to the delivery address; that is, the user address from the User Service. Similarly, once the order is placed, the User Service would like to update the total orders placed till date by the user in its database. Since the user database is maintained by the User Service and the Orders Database is maintained by the Orders Service, these two services will get the required details via the APIs exposed by the other service only. They should not be allowed to directly update or access databases maintained by another service. This helps in always maintaining a single copy of the user and order databases that is not accessible to any other microservice directly.