Micro-services face questions 20 you have to be back, the interview will be asked

EDITORIAL : I was sailing to the sea , the nickname comes from the name of my girlfriend's name as well. I love technology, open source love, love programming.Technology is open source, knowledge is shared.

This blog is a little summary and record their own learning, if you have the Java , algorithms interested, you can focus on my dynamic, we learn together.

With the knowledge to change the fate, let our family live a better life

EDITORIAL: Under Before learning springcloud we must first understand the common face questions have that piece, then we take the issue to learn this micro-services technology, it will be more understanding springcloud technology. If you have learned springcloud, so while preparing the interview, be sure to look and see these interview questions.

1. What is micro-services?

Micro Services Architecture is an architectural pattern or a kind of architectural style, it advocates a single application into a set of smaller services, each running in its own separate process, co-ordination between services, co-ordination to provide end-users with value. The use of lightweight communication mechanism between the service to communicate with each other (usually HTTP-based API RESTful) . Each service around the specific business to build, and can be independently deployed into a production environment, production-like environment and so on. In addition, you should try to avoid a unified, centralized service management mechanism, for a specific service should be based on the business context, select the appropriate language, tools to build them, can have a very lightweight centralized management to coordinate these services, you can use a different language to write the service, you can use different data storage.

From a technical dimension is :

Micro core service of the application is the traditional stop, according to a split into a service business, completely decoupling, each micro-service function service providing a single service, a service do one thing, from a technical point a small look that is independent of the process, the process is similar to the concept, can start on its own or destroyed separately, they have their own independent database.

2, between the micro-services is how to communicate?

The first : Remote Procedure Call (Remote Procedure Invocation)

Direct calls to access the service through other remote procedure.

Example: REST, gRPC, Apache, Thrift

advantage:

Simple, common. Because there is no middleware agent, a simpler system

Disadvantages:

Only supports the request / response model, does not support the other, such notice, request / asynchronous response, publish / subscribe, publish / asynchronous response
reduces the availability of, because the client and server must both be available in the Request Process

The second : Message

Use asynchronous message communication between services do. Exchanging messages between the message service pipe, so that the communication.

Example: Apache Kafka, RabbitMQ

advantage:

  • The decoupling of client and server, increase the availability of more loosely coupled, message-oriented middleware cache because the message until the consumer can consume
  • Supports many communication mechanisms such notice, request / asynchronous response, publish / subscribe, publish / asynchronous response

Disadvantages:

Messaging middleware additional complexity

3, springcloud and dubbo What are the differences?

Same point:
SpringCloud and Dubbo can be achieved RPC remote call framework that can achieve service governance.

difference:
SpringCloud comparison site is currently set up micro-services framework to integrate distributed common solution to the problems encountered registry Eureka, load balancer Ribbon, client calls and Rest tools Feign, distributed configuration center Config, service protection Hystrix, gateway Zuul gateway, service link Zipkin, message bus bus and so on.

Dubbo achieve internal function is not SpringCloud powerful (family bucket), only to realize service governance, the lack of a distributed configuration center, a gateway, link, bus, etc., if you need to use these components, you need to integrate other frameworks.

Table Spring Cloud and Dubbo feature comparison
function name Dubbo Spring Cloud
Service registry ZooKeeper Spring Cloud Netflix Eureka
Service invocation RPC REST API
Services Gateway no Spring Cloud Netflix Zuul
breaker imperfect Spring Cloud Netflix Hystrix
Distributed Configuration no Spring Cloud Config
Service Tracking no Spring Cloud Sleuth
Message Bus no Spring Cloud Bus
data flow no Spring Cloud Stream
Batch jobs no Spring Cloud Task


4, please talk about the understanding of SpringBoot and SpringCloud

  • SpringBoot focus on quick and easy development of a single individual micro-services.

  • SpringCloud is concerned about the overall coordination of services finishing micro governance framework, it will SpringBoot developed a micro-mer service integration and management together
    to provide services between the various micro, configuration management, service discovery, circuit breakers, routing, micro broker, event bus, global lock, decision-making campaign, distributed session etc. integration services

  • SpringBoot can leave SpringCloud independent use development project, but can not do without SpringBoot SpringCloud, belonging to the dependent relationship.

  • SpringBoot focus on quick and easy development of a single micro-serving individuals, SpringCloud attention to service global governance framework.

Spring Boot can leave Spring Cloud development projects independently, but can not do without Spring Cloud Spring Boot, belonging to the dependent relationship.

5, the problem faced by the distributed system

Complex distributed application architecture dozens of dependencies Each dependency at some point will inevitably fail.

  • Avalanche Service
    When calls between a plurality of micro services, assuming that the micro-micro-service service A calls B and C service micro, micro and micro-service B and C service call other micro service, which is called "fan-out." Call a micro-services link on the fan-out if the response time is too long or is not available, the call to the micro-service A will take up more and more system resources, thereby causing the system to crash, so-called "avalanche effect."

  • For high traffic, a single back-end dependence may lead to all resources on all servers are saturated in a few seconds. Worse than failure, these applications may also cause a delay between the service increases, the backup queue, threads, and other nervous system resources, resulting in the entire system more cascading failure. Which indicate a need for isolation and fault management and delay, so that a single failed dependencies, can not cancel the entire application or system.

For general service depends on protection mainly in the following three solutions:

  • Fuse mode: This model is given with reference to the fuse circuit, the line voltage is too high if a fuse blows, to prevent fires. Into our system, if a target service invocation slow or there is a lot of time expires, blown to call the service, the request for a subsequent call, do not continue to call the target service, direct return, quick release resources. If the goal is to restore the situation improved service calls.

  • Isolation Mode: This mode is like the system as requested by type into one island, when the island was a little light the fire, and will not affect other islands. For example, may be used for different types of requests to the thread pool resource isolation, independently of each other for each type of request, if one type of resource exhaustion request thread, then the type of the subsequent request returned directly, instead of calling up resources. This mode uses scene very much, for example, will open a service, for important services use to deploy a separate server, or again recently to promote multi-center.

  • Limit Mode: The above-described mode and fuse isolation mode belong to a fault-tolerant processing mechanism after an error, while the current limiting mode may be referred to as a preventive mode. Limiting mode is primarily set in advance QPS highest threshold value for each type of request, if the above threshold is set to return directly to the request, instead of calling up resources. This model does not solve the problem of service depends, can only solve the overall problem of resource allocation system, because the request has not been limiting still likely to cause an avalanche effect.

6. What is the service fuse, what is service degradation

Service fuse

A micro-fuse mechanism is to deal with service link protection mechanism avalanche effect.
When a micro-fan-out link service is unavailable or response time is too long, it will downgrade the service, and then blown call the micro-node service, the quick return "wrong" response information. After detecting the micro-node service call response call resume normal link. Hystrix implemented in the framework of SpringCloud by fusing mechanism. Hystrix will monitor the situation between micro service calls, failed calls when a certain threshold value, the default is the call fails 20 times within five seconds will start fusing mechanism. Notes fuse mechanism is @HystrixCommand.

Hystrix service degradation

In fact, a single thread processing thread pool barrier to prevent a single thread request too long, leading to long-term resources occupied and not released, causing the thread pool is completely occupied quickly, crash the service.

Hystrix can solve the following problems:

  • Request timed out demotion, lack of resources thread downgrade, after the downgrade can return custom data
  • Thread pool isolation downgrade, distributed services for different services use different thread pool, so independently of each other
  • Triggered automatically downgrade and recovery
  • Implementing request caching and request merge

7, advantages and disadvantages of micro What are the services? Said pit you encountered in project development?

advantage

  • Each service cohesive enough, small enough, the code can be readily understood that such a focus function or service specific service requirements
  • Development of simple, improve development efficiency, is a single-minded service may only do one thing.
  • Micro-service small team can be developed separately, this small team is 2-5 people development staff.
  • Micro services are loosely coupled, there is a functional significance of service, whether it is in the development stage or deployment phase is independent.
  • Micro service can use a different language development.
  • Ease and third-party integration, micro service allows easy and flexible way to integrate automatic deployment, through continuous integration tools, such as Jenkins, Hudson, bamboo.
  • Micro service easily understood by a developer, modify and maintain, such a small team can be more concerned about the outcome of their work. Without the need to reflect the value of cooperation.
  • Micro service allows you to take advantage of integration of the latest technology.
  • Micro service is just the business logic code, and not HTML, CSS, or other interface components mixed.
  • Each service has its own micro-storage capacity, it can have its own database. There may also be consolidated database.

Shortcoming

  • Developers want to deal with the complexity of distributed systems
  • Multi-service operation and maintenance difficulty, with the increase in service, operation and maintenance of pressure also increased
  • System Deployment relies
  • Inter-service communication costs
  • Data consistency
  • System Integration Testing
  • Performance Monitoring ......

8, you know what micro-services technology stack? Please name a few

  • Service development
    Springboot, Spring, SpringMVC
  • Service configuration and management
    Netflix's Archaius, Ali Diamond, etc.
  • Service registration and discovery
    Eureka, Consul, Zookeeper, etc.
  • Service call
    Rest, RPC, gRPC
  • Service fuse
    Hystrix, Envoy, etc.
  • Load balancing
    Ribbon, Nginx, etc.
  • Service interface calls (to simplify the client calls the service tool)
    Feign etc.
  • Message queue
    Kafka, RabbitMQ, ActiveMQ etc.
  • Service center configuration management
    SpringCloudConfig, Chef, etc.
  • Service Routing (API Gateway)
    Zuul, etc.
  • Service monitoring
    Zabbix, Nagios, Metrics, Spectator, etc.
  • Full Link Trace
    Zipkin, Brave, Dapper, etc.
  • Service deployment
    Docker, OpenStack, Kubernetes etc.
  • Data Flow Development Kit
    SpringCloud Stream (package and Redis, Rabbit, Kafka message transmission, etc.)
  • Event message bus
    Spring Cloud Bus

9. What is the Eureka service registration and discovery

Eureka is a sub-module of Netflix, it is one of the core modules. Eureka is a REST-based services, for location services, the intermediate layer in order to achieve the cloud service discovery and failover. Service registration and discovery services for micro-architecture is very important, with service discovery and registration, just use the identifier of a service, you can access to the service without the need to modify the configuration file of a service call. Functions like the registry dubbo, such Zookeeper.

10. What is the basic structure of Eureka?

Spring Cloud encapsulates Netflix Eureka module developed to implement the service registration and discovery (please compare Zookeeper).

Eureka using the CS design architecture. Eureka Server as a service registration function of the server, which is a service registry.

And other micro-services system, use the client to connect to Eureka Eureka Server and maintain a heartbeat connection. Such systems maintenance personnel can monitor each micro system service is functioning properly by Eureka Server. SpringCloud some of the other modules (such as Zuul) can be found in other micro-services system through Eureka Server, and implementation of relevant logic.

Eureka consists of two components : Eureka Server and Eureka Client

Eureka Server to provide service registry service
After each node starts, it will be registered in EurekaServer, so EurekaServer in the service registry will store all information available information service node, service node can visually see in the interface

EurekaClient is a Java client
To simplify the interaction, the client Eureka Server also includes a built-in polling (round-robin) load load balancing algorithm. After the application starts, it will send a heartbeat to the Eureka Server (default period is 30 seconds). If Eureka Server does not receive a heartbeat nodes in multiple heartbeat period, EurekaServer will put the service node is removed from the service registry (default 90 seconds)

11, registered as a service center, Eureka Zookeeper than good?

CAP famous theory states that a distributed system can not satisfy C (consistency), A (availability) and P (partitions fault tolerance). Since the partition P fault tolerance in a distributed system must be guaranteed, so we can only trade-off between the A and C.

Therefore, Zookeeper ensure that CP, Eureka is the AP.

  • Zookeeper guarantee CP

When the query service list to the registry, we can tolerate registry returned a few minutes before registration information, but can not accept the services directly down out is not available. That is, the Service registration requirements for availability than consistency. But zk is there such a situation, when the master node with other nodes because the network lost contact failure, the remaining nodes will be leader re-election. The problem is that the election leader too long, 30 ~ 120s, and the entire cluster zk are not available during the elections, which led to paralysis during the electoral registration services. In the cloud deployment environment, due to network problems makes zk lost master node cluster is something greater probability occur, although the service will eventually recover, but registered a long time due to the long-term election is not available it will not be tolerated.

  • Eureka assurance AP

Eureka understand this, so the design will give priority to ensuring availability. Eureka each node are equal, hang a few nodes will not affect the normal node, the remaining nodes can still provide registration and inquiry services. The Eureka client when registering with the Eureka or if you find a connection fails, it will automatically switch to the other nodes, as long as there is still a Eureka, we can guarantee registration services are available (to ensure availability), but found the information It may not be current (not guarantee strong consistency).

In addition, there is a self-protection mechanism Eureka, if more than 85% in 15 minutes nodes are not normal heartbeat, then the client is considered Eureka and registration center of a network failure, the following appears Happening:

  1. Eureka no longer remove because for a long time and should not receive heartbeat expired registration service from the list
  2. Eureka is still able to accept registration and query requests for new services, but will not be synchronized to (that is, to ensure that the current node is still available) on other nodes
  3. When the network is stable, the current instance of the new registration information will be synchronized to the other nodes

Therefore, Eureka can be a very good response due to network failure caused the loss of some nodes on the contact, but not as paralysis of the entire registration services like zookeeper.

12. What is the Ribbon load balancing

Spring Cloud Ribbon is based on a set of client load balancing tool Netflix Ribbon implemented.

Simply put, Ribbon Netflix is ​​released open source project, the main function is to provide the client software load balancing algorithm, an intermediate layer connecting the Netflix service together. Ribbon client components, such as a series of perfect CI connection timeout, retry the like. Simply put, it is listed in the configuration file Load Balancer (referred to as LB) all machines behind, Ribbon will automatically help you to connect these machines based on certain rules (such as a simple polling, random connections, etc.). We are also very easy to use load balancing algorithm Ribbon customizable.

13, Ribbon load balancing can be doing?

  • LB (Load Balancing
    LB, that is, load balancing (Load Balance), an application or service in the micro-distributed cluster frequently used.
    Load balancing is simply equal shares of the user's request to allocate the plurality of services, so as to achieve the system HA.
    There are common load balancing software Nginx, LVS, F5 hardware and so on.
    Corresponding middleware, such as: dubbo and SpringCloud both provided us with load balancing, SpringCloud load balancing algorithm can be customized.

  • Centralized LB
    That is separate between the consumer and provider services LB facilities (can be hardware, such as F5, can be software, such as nginx), the facility is responsible for the access request is forwarded to the service provider through a strategy ;

  • LB-process
    LB logic will be integrated into the consumer side, consumer service registry learn from what address is available, and then select a suitable own server from these addresses.

Note: Ribbon belong to LB in the process, it's just a class library, integrated consumer process, consumer to get the address of the service provider through it.

14. What is the Feign load balancing

Feign is a declarative WebService client. Feign make use of Web Service clients written in simpler, its use is to define an interface, then add annotations on top, also supports standard JAX-RS annotations. Feign also supports plug-type encoder and decoder. Spring Cloud to Feign the package, to support the Spring MVC standard annotation and HttpMessageConverters. Feign Ribbon can be used in combination with Eureka and to support load balancing.

Feign is a declarative Web services client, a Web service client makes writing very easy, just create an interface, then you can add annotations on top.

15, Feign can do

Feign designed to make writing Java Http client easier.

When using the foregoing Ribbon + RestTemplate, using RestTemplate http request of the encapsulation process, forming a set of templates of the calling method. But in the actual development, due to the dependence of the call to service may be more than one, the interface is often a multiple call, so usually each micro-service package for some clients like to wrap themselves depend on these services call. So, Feign On this basis, made a further package by him to help us define and implement the definition of dependent services interface. In the realization of Feign, we need to create an interface and use annotations way to configure it (previously marked Dao Interface Mapper above notes, now is a microblogging service interface to the top mark a comment Feign) to complete the service provides an interface to bind parties to simplify the use of Spring cloud Ribbon, the development of automatic packaging service call volume clients.

Feign integrated Ribbon
Use Ribbon maintenance service list information MicroServiceCloud-Dept, and by polling achieve load balancing client. The difference is that with the Ribbon, by feign need only define the service binding interfaces and to methods declarative, elegant and simple implementation of a service call

Feign interface method by calling Rest service (before a Ribbon + RestTemplate), Eureka send the request to the server (http: // MICROSERVICECLOUD-DEPT / dept / list),
find the service interface directly through Feign, due to the time during the service call combines Ribbon technology, it also supports load balancing effect.

16. What is the circuit breaker Hystrix

Hystrix is a distributed system for processing delays and fault-tolerant open source libraries, distributed systems, many rely inevitably call fails, such as overtime, abnormal, Hystrix can guarantee in the case of a dependency problem, It will not result in an overall service to fail, to avoid cascading failures, in order to improve the flexibility of distributed systems.

"Breaker" is a switching apparatus itself , when a service unit fails, the fault monitoring circuit breaker (similar to a blown fuse), and returns to the caller a line with expectations, the response may be processed alternatively (FallBack) instead of waiting for a long time or throw an exception caller can not handle, thus ensuring the caller to the service thread it will not be long, unnecessarily occupied, so as to avoid the spread of the fault in the distributed system, and even avalanche.

17, Hystrix circuit breakers doing?

  • Service downgraded
    Overall resources fast enough, some reluctantly turn off the service, to be ride out the storm, and then turn back

  • Service fuse
    A micro-fuse mechanism is to deal with service link protection mechanism avalanche effect.
    When a micro-fan-out link service is unavailable or response time is too long, it will downgrade the service, and then blown call the micro-node service, the quick return "wrong" response information. After detecting the micro-node service call response call resume normal link. Hystrix implemented in the framework of SpringCloud by fusing mechanism. Hystrix will monitor the situation between micro service calls, failed calls when a certain threshold value, the default is the call fails 20 times within five seconds will start fusing mechanism. Notes fuse mechanism is @HystrixCommand.

  • Limiting service

  • Near real-time monitoring
    In addition to calling isolation dependent services, Hystrix also provides near real-time call monitoring (Hystrix Dashboard), Hystrix will continue to record execution information for all by Hystrix initiated the request, and presented to the user in the form of statistical reports and graphs, including how many successful execution of the request number, the number of failures per second and so on. Netflix realized the monitoring of these indicators by hystrix-metrics-event-stream projects. Spring Cloud also provides integrated Hystrix Dashboard, and monitoring content into visual interface.

18. What is the routing gateway zuul

It contains a request of ZuulroutingwithfilterThe two most important functions:

Wherein the routing function is responsible for forwarding the request to the external micro-specific service instance , is the basis of uniform external access inlet and the filter function is responsible for the processing of a request for intervention, is the basis of requesting a check, and other functions of the service aggregator .Zuul integration and Eureka, will register itself as Zuul applications in Eureka service governance, and access to other messaging services from Eureka in the micro, that the future of micro-access services are obtained by Zuul after the jump.

Note: Zuul service will eventually enrolled at Eureka

+ + = Proxy provides routing filter three functions

19, what is SpringCloud Config Distributed Configuration Center

SpringCloud Config offers a centralized service for the micro-architecture of the micro-service external configuration support, configuration external configuration server provides a centralized environment for all of the different micro-services applications.

20, the center distributed configuration can Why?

  • Centralized management profiles
    Different configurations in different environments, dynamic configuration updates, such as the deployment environment sub dev / test / prod / beta / release
  • Dynamically adjust the configuration during operationNo longer need to write the configuration file on each machine service deployment, unified service will pull their configuration information to the configuration center
  • When a configuration change occurs, the service does not require restartYou can sense the change in the configuration of the new configuration and application configuration information exposed as REST interface
Published 73 original articles · won praise 795 · views 50000 +

Guess you like

Origin blog.csdn.net/weixin_43570367/article/details/103809848