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

Isolating services by business logic

Once persistence-based services are isolated, the next step is to evaluate existing components for microservices with respect to business logic. Apart from dropping the Registration Component in favor of separate services for consumer and provider, a new service called lookup can be created to consolidate all the search operations into one service and allow users to search across application entities, as shown in the following diagram. Since databases of consumers, providers, services, and orders cannot be shared with lookup services, it can keep a denormalized (https://en.wikipedia.org/wiki/Denormalization) view of these databases containing only the fields that need to be searched.

Geolocation-based queries will also be limited to lookup services, so there is no need to maintain a separate geolocation service; instead, the Lookup Service itself can query for the geolocation.

Since geolocations rarely change, the Lookup Service can cache them and maintain a database of well-known and already queried geolocations as well for better performance.

The Alerting Component can be isolated as a separate service as it will be required by multiple services, including OrderService Consumer, and Service Provider, to send alerts to the users. Alerts may be sent via SMS or email, and the Alerting Service can use external services to send the alerts. Since alerts must not be overwhelming for users, the Alerting Service can group by user all the alerts that are requested in a short period of time and send them as a single notification message.

Do not attempt to aggressively start disintegrating your components into microservices. Focus on the business capabilities and not on features and use cases. For example, instead of creating a separate service for sending emails and sending SMS, it is recommended to create a single Alerting Service with both capabilities.