[Java Advanced Camp] Microservice Interview

1. What is microservice?
For now, there is no unified, standard definition for the microservice industry.

But generally speaking, the microservice architecture is an architectural pattern or an architectural style, which advocates dividing a single application into a group of small services, each of which runs in its own independent process, between services Coordinate and cooperate with each other to provide users with the most total value. Services communicate with each other using a lightweight communication mechanism (usually an HTTP-based RESTful API). Each service is built around a specific business and can be independently built in a production environment or a production-like environment. In addition, a unified and centralized service management mechanism should be avoided. For a specific service, an appropriate language and tool should be selected according to the business context to construct it. A very lightweight centralized management can be used to To coordinate these services, the services can be written in different languages ​​or use different data stores.

2. How do microservices communicate independently?

3. What are the differences between SpringCloud and Dubbo?
insert image description here

The biggest difference: SpringCloud abandons Dubbo's RPC communication and adopts the REST method based on HTTP.
Overall, both have their own advantages. Although the latter service calls the function, it also avoids the problems caused by the native RPC mentioned above. Moreover, REST is more flexible than RPC. The service provider and caller rely only on a paper contract, and there is no code-level dependency. This is more appropriate in the microservice environment that emphasizes rapid evolution.
The difference between the brand machine and the assembly machine: It is obvious that SpringCloud is more powerful than dubbo, with wider coverage, and can be perfectly integrated with other Spring projects such as SpringFramework, SpringBoot, SpringData, SpringBatch, etc. These are crucial for microservices. The microservice architecture built with Dubbo is like assembling a computer. We have a high degree of freedom in choosing each link, but in the end it may affect the whole because of the memory quality, but this is not a problem for experts. And SpringCloud is like a brand machine. Under the integration of Spring Source, a lot of compatibility tests have been done to ensure that the machine has higher stability.
When faced with the selection of the microservice infrastructure framework, Dubbo and SpringCloud can only choose one of the two.

4. SpringBoot and SpringCloud, please talk about your understanding of them?
1), SpringBoot focuses on the rapid and convenient development of individual microservices.
2), SpringCloud is a framework that focuses on global microservice coordination, organization, and governance. It integrates and manages the monomers developed by SpringBoot.
3), SpringBoot can leave SpringCloud to use development projects independently, but SpringCloud cannot do without SpringBoot, which is a dependency.

5. What is a service circuit breaker? What is service degradation?
The fuse mechanism is a microservice link protection mechanism to deal with the avalanche effect. When a microservice of the fanout link is unavailable or the response time is too long, the service will be degraded, and then the call of the microservice of the node will be cut off, and an "error" response message will be returned quickly. When it is detected that the microservice call response of the node is normal, the call link is resumed. In the SpringCloud framework, the fuse mechanism is implemented by Hystrix. Hystrix will monitor the status of calls between microservices. When the failed call reaches a certain threshold, the default is 20 calls within 5 seconds. If it fails, the fuse mechanism will be activated. The annotation of the fuse mechanism is @HystrixCommand
service degradation, which is generally considered from the overall load. That is, when a service is broken, the server will no longer be called. At this time, the client can prepare a local fallback callback and return a default value. In this way, although the level has dropped, it is usable anyway, which is better than hanging up directly.

6. What are the advantages and disadvantages of microservices? Tell me about the problems you encountered in project development
Advantages: 1) Each service is cohesive enough, small enough, and the code is easy to understand so that it can focus on a specified business function or business requirement.
2) The development is simple and the development efficiency is improved. A service may be dedicated to only one thing.
3) Microservices can be developed by small teams, which can consist of 2 to 5 developers.
4) Microservices are loosely coupled and functionally meaningful services that are independent in both the development and deployment phases.
5) Microservices can be developed in different languages.
6), easy for third-party integration, microservices allow easy and flexible integration of automatic deployment, through continuous integration integration tools, such as Jenkins, Hudson, etc.
7) Microservices are easy to be understood, modified and maintained by a developer, so that small teams can pay more attention to their own work results. There is no need to demonstrate value through cooperation.
8) Microservices allow you to incorporate the latest technologies.
9) The business logic code of microservice knowledge will not be mixed with HTML and CSS and other interface components.
10) Each microservice has its own storage capacity, and can have its own database or a unified database.
Disadvantages: 1) Developers have to deal with the complexity of distributed systems.
2) It is difficult to operate and maintain multiple services. With the increase of services, the pressure of operation and maintenance is also increasing.
3) System deployment dependencies.
4) Communication costs between services.
5), data consistency.
6), system integration test.
7), performance monitoring...

7. What microservice technology stacks do you know? Please provide one or two examples.
Microservice technology stacks (technologies used to implement various functions) are as follows:
insert image description here

8. Both Eureka and zookeeper can provide service registration and discovery functions. Please talk about the difference between the two?
1), Zookeeper guarantees CP (C: Consistency, P: Partition fault tolerance), Eureka guarantees AP (A: High availability)
(1), when querying the service list from the registry, we can tolerate the information returned by the registry It is information a few minutes ago, but it cannot be tolerated to be directly down and unavailable. That is to say, the service registration function has relatively high requirements for high availability, but zk will have such a situation that when the master node loses contact with other nodes due to network failure, the remaining nodes will re-elect the leader. The problem is that it takes too long to select a leader, 30 to 120s, and the zk cluster is not available during the selection period, which will cause the registration service to be paralyzed during the selection period. In a cloud deployment environment, it is highly probable that the zk cluster will lose the master node due to network problems. Although the service can be restored, the long-term unavailability of the registration caused by the long selection time cannot be tolerated.
(2) Eureka guarantees the availability. Each node of Eureka is equal. If a few nodes hang up, it will not affect the work of normal nodes. The remaining nodes can still provide registration and query services. However, when Eureka's client registers with a certain Eureka or finds that a connection failure occurs, it will automatically switch to other nodes. As long as one Eureka is still there, the registration service can be guaranteed to be available, but the information found may not be the latest. In addition, Eureka also has a self-protection mechanism. If more than 85% of the nodes do not have a normal heartbeat within 15 minutes, then Eureka believes that a network failure has occurred between the client and the registration center. At this time, the following situations will occur:
①. Eureka is not removing services that should expire because they have not received a heartbeat for a long time from the registration list.
②, Eureka can still accept registration and query requests for new services, but will not be synchronized to other nodes (that is, to ensure that the current node is still available)

       ③、当网络稳定时,当前实例新的注册信息会被同步到其他节点。

Therefore, Eureka can well deal with the situation that some nodes lose contact due to network failure, instead of paralyzing the entire microservice like Zookeeper.
Click on the business card below to get the information

Guess you like

Origin blog.csdn.net/m0_54861649/article/details/126605372