The choice of component and service in the era of microservice

Time:2021-10-16

With the increasing complexity of business systems, there are more and more calls between systems. In the process of micro service splitting and iteration, we often need to face the problem of whether to continuously split new independent services or package independent components to provide services in the way of jar package dependency. This paper will discuss the differences between these two different methods in detail Their advantages and disadvantages and applicable scenes, I hope they can inspire you.

1、 Component & service definition

With the rapid development of the company’s Internet business, the complexity of the system is higher and higher, and there are more and more calls between systems. In the process of micro service splitting and iteration, two scenarios are often encountered:

  • In what form do some public function modules in their own system provide services, whether to package all logic and methods and provide them in the form of jar package, or separate a service and provide it through interface;
  • When it comes to calling external system services, there may be many services inside the system that need to call external services, but the calling logic is the same. Then, whether the interface calling logic and method for the external system are encapsulated into a jar package for internal service dependent calls, or whether the interface calling logic and method for the external system are separated into a service independently, Then, the internal services call the external system services by calling this independent service.

For the above two scenarios, we can summarize as follows:ComponentizationandService orientedThere are two different forms of service provision:

Component definition: encapsulate some public function modules in the system or some logical methods called by the external system into an independent jar package. The system in need directly depends on the jar package to use the corresponding services. Here we call it componentization;

As an example of Componentization of common function modules in the system, services a, B and C independently rely on component D to use relevant functions.

The choice of component and service in the era of microservice

The external system service interface calls the componentization example. Services a, B and C all call external service e through component D

The choice of component and service in the era of microservice

Service definition: that is, some public function modules within the system or some logical methods called by the external system are independently divided into a service, and the service exposes a unified interface for all services in need to call. Here we call it servitization.

The service-oriented example of the internal common function module of the system corresponds to the independent splitting of component D in Figure 1 into service D, which provides interfaces to services a, B and C for calling.

The choice of component and service in the era of microservice
The external system service interface calls the service-oriented example, which corresponds to the independent splitting of component D in Figure 2 into service D, and services a, B and C call external system service e by calling service D.

The choice of component and service in the era of microservice
So in actual work, facing different scenarios and problems, which way should we choose? Whether there are relevant reference standards and what problems need our special attention and consideration. Next, we will introduce the advantages, disadvantages and applicable scenarios of component-based and service-oriented in detail.

2、 Advantages, disadvantages and applicable scenarios of componentization

What are the advantages and disadvantages of calling third-party services through jar dependency?

2.1 advantages of componentization

  • High service invocation performance, because the third-party services are called directly by calling the methods in the jar package, the performance loss is less, and the use of this method in scenarios with high performance requirements will have certain advantages;
  • Save server machine costs, because there is no need to deploy services independently, server resources can be saved, especially in the scenario of large server requests, high QPS and the need to deploy a large number of server resources.

2.2 disadvantages of componentization

  • Poor maintainability, once the logical method of calling other services needs to be changed, or the jar package provided by a third party needs to be upgraded, except that the component itself needs to be maintained and upgraded, the services that depend on the component in our own system need to be upgraded together. Over time, sorting and maintenance will be very troublesome;
  • The cost of component upgrading is high and the risk is high, if there are many services that rely on this component in the system, the upgrade cost will be very high. The cost includes the cost of developing, maintaining and upgrading various services, the cost of testing and verification, and the cost of operation and maintenance release. The more services that need to be upgraded and maintained, the higher the cost, and the greater the corresponding risk.

2.3 applicable scenarios of componentization

So what specific scenarios are suitable for component deployment? According to our experience, it is recommended to use componentization if it meets the characteristics of the following scenarios:

  • Some public function processing scenarios within the system do not involve the connection and call at the database resource level, which is suitable for component-based methods;
  • For the external system service invocation scenario, the service concurrency is large, and the service performance is very high. It is mainly some to C services, which require high performance and low delay. It is necessary to minimize the service invocation link. This situation is more suitable to provide the external system invocation logic and methods in a modular way. If the business itself has very high performance requirements, In many cases, performance issues will be given priority and some disadvantages brought by componentization will be tolerated;
  • The company has strict requirements on the cost control of server resources and try to reduce the cost as much as possible. This situation is more common for start-ups or projects, often requiring low-cost and rapid trial and error.

2.4 cases of using componentization

Case 1
The app store has 240 million live users per month and 60 million live users per day. It has very high requirements for the performance of the store server. Many services in the store involve a large number of external system service calls, such as CPD, games, DMP, etc. on the premise of giving priority to user experience and performance, we integrate calls to external systems through componentization, Tolerate some inconvenience in maintenance and upgrading.

The choice of component and service in the era of microservice

2.5 negative cases of componentization

Case 2
Let’s share a negative example of the component-based approach used by the store. Many service modules in the store involve the management of some operation resource bits. Many services need to distribute some operation bit resource materials to the client. At first, various scenarios were not fully considered. The most obvious thing is that the acquisition of these resource materials involves the connection and call of database resources, After using componentization, it will lead to high development and maintenance cost and low iteration efficiency.

The choice of component and service in the era of microservice

3、 Advantages, disadvantages and applicable scenarios of service

3.1 advantages of service

  • After service, resources can be isolated without mutual influence, internal details can be hidden from the caller, and development and deployment can be carried out independently to improve development efficiency;
  • Compared with componentization, the maintainability is better. After service, the services of each module are decoupled. Whether the logical method of calling other services needs to be changed or the jar package provided by a third party needs to be upgraded, only the service itself needs to be upgraded. As long as the interface protocol does not change, other services calling the service do not need to be changed, It is very convenient to maintain;
  • The service upgrade cost is low and the risk is controllable. No matter how many systems rely on the service, we only need to deal with the upgrade of this service. The development and maintenance upgrade cost, test and verification cost and operation and maintenance cost are greatly reduced compared with componentization, and the risk is also small. At present, various jar package security problems occur frequently and need to be upgraded and repaired in time, The advantage of service is more obvious.

3.2 disadvantages of service

  • The service performance is worse than componentization. The more service splitting, the more complex the mutual calls between services, the longer the call link, and the more network requests between services, the worse the performance;
  • The deployment of multi services and multi nodes after service will bring some inherent problems of natural distributed systems, such as consistency, distributed transaction processing, etc. in addition, the overall stability of services will be reduced due to the increase of nodes and the length of service links;
  • After service, more server resource costs will be increased. For each independent deployment of a service on the service call link, in order to ensure service performance, the corresponding number of machine resources of the original service will be increased or more. The finer the service splitting, the higher the cost;

3.3 scenarios applicable to service

So which scenarios are suitable for service deployment? It is recommended to use the service-oriented method if it meets the characteristics of the following scenarios:

  • For some public function modules in your system, if the resource call at the database level is involved, it is recommended to provide them in a service-oriented manner to avoid configuring and maintaining the corresponding database resource information for all services that depend on the public function module, which will be very painful later, such as database change, machine room migration, etc;
  • For external system service calls, if many internal systems depend on external services, but the service concurrency is small, the performance requirements are not high, the service call link length has little impact, and the services with low concurrency and performance requirements are unobstructed, and do not need too many server resources. In this case, it is recommended to package the external system interface calls into independent services, When the call logic to the external system changes or the relevant jar package is upgraded, we only need to upgrade this service, and we do not need to upgrade all relevant services in our own system.

3.4 service use cases

Case 1
In the case of service-oriented public function modules in the system, each module of the application store often has some public filtering logic before returning information to the client, and the processing of these public filtering logic also involves interaction with MySQL and redis. Therefore, these public filtering logic are directly and independently divided into an independent service, At present, the service not only provides services within the project, but also can be used by many businesses of other departments in the company.

Some students may have questions. For services with a large number of users and high requirements for service concurrency and performance, split one service to solve the problem of data resource isolation, but how to solve the problem of performance degradation caused by long service call links, such as the opposite case of Componentization of operation resources mentioned above (example Figure 6), To solve this problem, we can increase the cache at the caller to solve the performance problem, because this business scenario does not require high real-time data.

The choice of component and service in the era of microservice

Some students may have questions. For services with a large number of users and high requirements for service concurrency and performance, split one service to solve the problem of data resource isolation, but how to solve the problem of performance degradation caused by long service call links, such as the opposite case of Componentization of operation resources mentioned above (example Figure 6), To solve this problem, we can increase the cache at the caller to solve the performance problem, because this business scenario does not require high real-time data.

Case 2
For the service-oriented case of external system service invocation, we have an open platform system, which mainly serves developers and has low requirements for system performance. One of the requirements involves external system service invocation, and multiple projects in the open platform system need to invoke the external system service. In order to facilitate subsequent service maintenance and upgrading, It encapsulates the call logic of external system services into an internal service specially used for external system calls, and then calls the external system through the internal service.

The choice of component and service in the era of microservice

4、 Summary

Summarize the advantages and disadvantages of component-based and service-oriented:
The choice of component and service in the era of microservice
To sum up, the two methods of component-based and service-oriented are not absolutely good or bad, and each has its own advantages and disadvantages. The specific method to be used has something to do with our real problem scenario. You can refer to the above analysis and combine your actual project situation to choose the method that suits you. The technology is ultimately to serve the business. In most cases, there is no perfect solution, Only the most suitable solution.

Author:   Vivo Internet server team – Yao Wenyu

Recommended Today

Swift advanced (XV) extension

The extension in swift is somewhat similar to the category in OC Extension can beenumeration、structural morphology、class、agreementAdd new features□ you can add methods, calculation attributes, subscripts, (convenient) initializers, nested types, protocols, etc What extensions can’t do:□ original functions cannot be overwritten□ you cannot add storage attributes or add attribute observers to existing attributes□ cannot add parent […]