BAT interview sharing: 26 interview questions for microservices (including answer analysis)

1. What is Micoreservice?

The core of microservices is to split the traditional one-stop application into one service according to the business, and completely decouple it.Each microservice provides a single business function service, and one service only does one thing; from a technical perspective It looks like a small and independent process, similar to the concept of a process; each microservice can be started or destroyed independently, and has its own independent database.

 

2. What are the advantages and disadvantages of microservices?

advantage:

1. Each service is cohesive enough, small enough, and the code is easy to understand, so that it can focus on a specific business function or business requirement;

2. Development is simple, and development efficiency is improved. A service may only do one thing;

3. Microservices can be independently developed by a small team, which can consist of 2-5 developers;

4. Microservices are loosely coupled and are functionally meaningful services, whether they are in the development phase or the deployment phase are independent;

5. Microservices can be developed in different languages;

6.Easy to third-party integration, microservices allow for easy and flexible integration of automatic deployment, through continuous integration tools, such as: Jendis, Hudson;

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, without the need to cooperate to reflect value;

8. Microservices are just business logic codes and will not be mixed with other interface components such as HTML and CSS;

9. Each microservice has an independent storage capacity, which can be managed by its own database or by a unified database.

Disadvantages:

1. Developers have to deal with the complexity of distributed systems;

2. Multi-operations and maintenance are difficult. With the increase of services, the pressure of operation and maintenance is also increasing;

3. System deployment dependency;

4. System integration test;

5. Communication cost between services;

6. Data consistency;

7. Performance monitoring;

...Wait.

Third, the difference between microservice and microservice architecture?

1. Microservices emphasize an individual, and each individual does his own thing;

2. The microservice architecture emphasizes the whole, which assembles individual microservices to provide external services.

4. What are the microservice technology stacks?

Technology stack: a collection of multiple technologies;

1. Service development: SpringBoot, Spring, SpringMVC;

2. Service configuration and management: Archaius of Netflix, Diamond of Alibaba, etc.;

3. Service registration and discovery: Eureka, Zookeeper;

4. Service call: Rest, RPC, gRPC;

5. Service fuse: Hystrix, Envoy;

6. Service load balancing: Ribbon, Nginx;

7. Service interface call: Feign;

8.Message queue: Kafaka, RabbitMQ, ActiveMQ;

9. Message configuration center management: SpringCloudConfig, Chef

10. Service monitoring: Zabbix, Nagios, Metrics, Spectator;

11.Service routing (API gateway): Zuul;

12. Full link tracking: Zipkin, Brave, Dapper

13. Service deployment: Docker, OpenStack, Kubernetes;

14. Data stream operation development kit: SpringCloud Stream;

15. Event message bus: SpringCloud Bus;

...Wait.

5. Why choose SpringCloud as the microservice architecture?

Selection basis:

1. Overall solution (SpringCloud framework has a one-stop overall solution for the whole family bucket, similar to IKEA, all homes from kitchen to bedroom to bathroom can be purchased in one place, convenient and fast), and the framework is mature high;

2. The community is hot and there are many people using it;

3. Maintainability;

4. Learning curve, etc.;

6. What is SpringCloud?

SpringCloud is a tool set for quickly building distributed systems based on SpringBoot. It provides a one-stop solution for microservices based on SpringBoot, including service registration and discovery, configuration center, full link monitoring, service gateway, load balancing, Components such as fuses; In addition to highly packaged open source components based on Netflix, there are also some neutral open source components.

 

7. What is the "family bucket" of microservices?

The one-stop solution under the distributed microservice architecture is a collection of various microservice architecture landing technologies, commonly known as the microservice "family bucket".

8. The relationship between SpringBoot and SpringCloud?

1.SpringBoot focuses on the rapid and convenient development of individual individual microservices;

2.SpringCloud is a global microservice coordination and governance framework that integrates and manages the individual microservices developed by SpirngBoot, providing configuration management, service discovery, circuit breakers, routing, and microagents between each microservice. , Event bus, global lock, decision-making campaign, distributed conversation and other integrated services;

3. SpringBoot can leave SpringCloud to independently use the development project, but SpringCloud cannot do without SpringBoot, the two belong to a dependency relationship.

Nine, the difference between SpringCloud and Dubbo?

1. The biggest difference between the two is that SpringCloud abandoned Dubbo's RPC communication and adopted the HTTP REST method;

2. Strictly speaking, these two methods have their own advantages and disadvantages. Although to a certain extent, REST sacrifices the performance of service calls, but it also avoids the problems caused by native RPC; moreover, REST is more flexible than RPC , The dependency of the service provider and the caller only relies on a contract, and there is no strong dependency at the code level, which is more suitable in the microservice environment that emphasizes rapid evolution;

3.Dubbo only implements service governance, and SpringCloud's sub-projects cover many components under the microservice architecture. Service governance is only one aspect of it; but Dubbo provides various filters, and various core elements can be extended by Filter To perfect.

10. How is the registration and discovery of microservices played?

The registration and discovery of microservices are implemented through Eureka components. Eureka contains two major contents: Eureka Server and Eureka Client;

Eureka Server provides service registration services. After each node is started, it will be registered in Eureka Server. In this way, the service registry in Eureka Server will store the node information of all available services, and the information of service nodes can be seen directly in the interface ; Eureka Client is a Java client used to simplify the interaction of Eureka Server. The client also has a built-in load balancer that uses a round-robin load algorithm; after the application is started, it will report to Eureka Server Send heartbeat (the default period is 30s); if Eureka Server does not receive the heartbeat of a node in multiple heartbeat periods, Eureka Server will remove the service node from the service registry (default 90 seconds).

Note: Just add @EnableEurekaServer annotation to EurekaServer7001_App main startup class!

11. How is Eureka better than Zookeeper as a service registry?

1.Eureka abides by the AP principle, and Zookeeper abides by the CP principle;

2.According to the CAP theory, a distributed system cannot satisfy consistency, availability and partition fault tolerance at the same time. Since partition fault tolerance must be guaranteed in a distributed system, we can only weigh between consistency and availability;

3.Zookeeper adopts CP, and nodes adopt master-slave. Once the host is down, it will make a decision among multiple slaves to elect one slave as the master, but the election time is between 30-120s, which is too long, which will cause the cluster during the election. Unavailability, which led to the paralysis of the entire registry;

4.Eureka adopts AP, all nodes are equal, there is no master-slave, if one node hangs, it will automatically switch to the next available node, as long as there is an Eureka node running normally, the registry can be guaranteed to be available; just query The information received may not be up to date (strong consistency is not guaranteed);

5. In addition, Eureaka also has a self-protection mechanism; therefore, Eureka can deal with the situation that some nodes lose contact due to network failures, and will not paralyze the entire registration service like Zookeeper.

12. Eureka protection mechanism?

1. The Eureka self-protection mechanism is a security protection measure to deal with network abnormalities. Its architectural philosophy is to prefer to retain all microservices (both healthy and unhealthy microservices), and not to blindly log out any healthy microservices. Using the self-protection mode can make the Eureka cluster more robust and stable;

2. By default, if Eureka Server does not receive the heartbeat of a microservice instance within a certain period of time, Eureka Server will log out the instance (default 90 seconds), but when the network fails, the microservice and Eureka Server will The above behavior may become very dangerous because the service itself is actually healthy, and the service should not be cancelled at this time;

3. Eureka solves this problem through the "self-protection mode"-when Eureka Server loses too many clients in a short time (a network partition failure may occur), then the node will enter the self-protection mode; once it enters this mode , Eureaka Server will protect the information in the registry, and will no longer delete the data in the service registry (and will not log out any microservices). When the network failure is restored, the Eureka Server node will automatically exit the self-protection mode.

13. What is the traditional ACID?

A (Atomicity) atomicity;

C (Consistency) consistency;

I (Isolation) isolation;

D (Durability) Durability.

14. What are CAP?

C (Consistency) strong consistency;

The same data is copied to the same everywhere in the distributed system;

A (Availability) availability;

All nodes active in the distributed system can process operations and query accordingly;

P (Partition Tolerance) partition fault tolerance;

Between the two replication systems, if an unplanned network connection problem occurs, for this situation, there is a set of fault tolerance design to ensure;

The core of the CAP theory is that a distributed system cannot satisfy consistency, availability, and partition fault tolerance at the same time, and can only achieve two at the same time.

15. What is Ribbon?

SpringCloud Ribbon is a set of client-side soft load balancing tools based on Netfix Ribbon.

16. What is load balancing?

Load Balance is simply to spread the user's requests evenly across multiple services, so as to achieve the HA of the system, that is, high availability;

Classification: Centralized LB, In-process LB.

17. What is Feign?

Feign is a declarative WebService client, with built-in Ribbon load balancing, and its interface-oriented programming, which elegantly and simply implements service calls, making it easier to write WebService clients.

 

18. Problems faced by distributed systems?

The application in the complex distributed system structure has dozens of dependencies, and each dependency will face inevitable dependency failure at some point.

19. What is a service avalanche?

When calling between multiple microservices, suppose that microservice A calls microservices B and C, and microservices B and C call other microservices. This is called "fan-out"; if one of the fan-out links is If the call of microservice is unavailable or the response time is too long, the call to microservice A will occupy more and more system resources, which will cause the system to crash. The so-called "avalanche effect" (a kind of unavailability of service providers) The process of causing the unavailability of the service caller and gradually enlarging the unavailability).

20. What is Hystrix?

Hystrix is ​​an open source library (based on Netfix) used to deal with the delay and fault tolerance of distributed systems; in distributed systems, many dependencies will inevitably fail, such as timeouts, exceptions, etc., Hystrix can guarantee that there is a problem with a dependency. Under the circumstances, it will not cause the overall service failure, avoid cascading failures, and improve the resilience of the distributed system; the circuit breaker is a kind of switching device, when a service unit fails, the fault monitoring of the circuit breaker (similar to a fuse Fuse), return an expected and processable alternative response (FallBack) to the caller, instead of waiting for a long time or throwing an exception that the caller cannot handle, so as to ensure that the service caller's thread will not be Long time, unnecessary occupation, thus avoiding the spread of faults in distributed systems and even avalanches.

21. What can Hystrix do?

Service degradation, service fusing, service current limit, service monitoring.

22. What is a service circuit breaker?

The fuse mechanism is a microservice link protection mechanism to deal with the avalanche effect; when a microservice of the fan-out link is unavailable or the response time is too long, the service will be degraded, and then the microservice call of the node will be fuse, quickly Return wrong response information; When it is detected that the node microservice call response is normal, the call link is restored; In the Spring Cloud framework, the fuse mechanism is implemented by Hystrix, and Hystrix will monitor the call status between services, and when the failed call reaches a certain threshold , It will start the fuse mechanism, the default is to call 20 times within 5 seconds; (the annotation of the fuse mechanism is @HystrixCommand)

23. What is service degradation?

1. When the server pressure increases sharply, according to the actual business situation and traffic, some services and pages are strategically not processed or processed in a simple way, thereby releasing server resources to ensure the normal operation of core transactions;

2. Service degradation is generally considered from the overall load, that is, when a service is blown, the server will no longer be called. At this time, the client can prepare a local fallback callback and return a default value; in doing so, although the service level It has dropped, but it can still be used anyway, which is better than the service directly hanging;

3. The service degradation processing is done on the client side and has nothing to do with the server side.

24. What is service monitoring (Hystrix Dashboard)?

In addition to calls to dependent services, Hystrix also provides quasi-real-time call monitoring (Hystrix Dashboard). Hystrix will continuously record all execution information initiated by Hystrix and display it to users in the form of statistical reports and graphics. It includes information such as how many requests, how many successes, and how many failures are executed per second, and is transformed into a visual interface.

25. What is Zuul?

Zuul (Routing Gateway) contains two important functions of request routing and filtering;

The routing function is responsible for forwarding external requests to specific microservice instances, which is the basis for realizing a unified entry for external access; while the filtering function is responsible for intervening in the processing of requests, which is the basis for realizing request verification, service aggregation and other functions .

26. What is the SpringCloud Config distributed configuration center?

SpringCloud Config provides centralized external configuration support for microservices in the service architecture. The configuration server provides a centralized external configuration for all environments of different microservice applications, centralized management of configuration files, and configuration information in the form of a REST interface Exposed.

If you need information about the Java architect, you can "add my assistant VX to receive free architecture video materials", remember to like and forward! ! ! 

                                                               

Guess you like

Origin blog.csdn.net/a159357445566/article/details/108735687