[Interview with experts]——SpringCloud (22 questions in total)

1. What is microservice architecture?

Answer: Microservices architecture is a software architecture pattern that splits large applications into a set of small, independent services, each responsible for a specific business function. These services can be deployed, scaled, and managed independently and typically communicate via HTTP or messaging.

2. What is Spring Cloud?

Spring Cloud is an open source toolset for building distributed systems and microservice architectures . It is based on the Spring framework and provides a set of libraries and tools to solve common problems in distributed systems, such as service discovery, load balancing, configuration management, circuit breakers, distributed tracing, etc.

3.What are the main components in Spring Cloud?

Answer: The main components of Spring Cloud include:

Eureka: Service registration and discovery.
Ribbon: client load balancing.
Feign: Declarative HTTP client.
Hystrix: Circuit breakers and fault-tolerance management.
Zuul: API gateway.
Config: distributed configuration management.
Sleuth: distributed tracing.
Stream: Message-driven microservices.

4. What is service registration and discovery?

Service registration is the process of registering a microservice's network location (such as hostname and port) with a service registry so that other services can discover and call it. Service discovery is the process of querying a service registry for available services at runtime.

5. What is Eureka?

Eureka is Netflix's open source service registration and discovery component, used to build a highly available service registration center. Microservice applications can register to the Eureka server and query it to find instances of other services. Spring Cloud integrates Eureka for service registration and discovery.

6What is load balancing? How to implement client load balancing in Spring Cloud?

Answer: Load balancing is the process of distributing requests to multiple service instances to balance the load. Spring Cloud uses Ribbon to implement client load balancing. Ribbon can be integrated with service registration centers such as Eureka to automatically obtain available service instances and select the instance to be called based on the load balancing algorithm.

7.What is Feign? Have you ever used RPC? What are the pros and cons of both?

Answer: Feign is a declarative HTTP client designed to simplify HTTP communication between microservices. Developers only need to define the interface and use annotations to describe HTTP requests, and Feign will automatically generate specific HTTP client code.

Feign is suitable for service calls of the HTTP protocol, which is lightweight and simple to use;
while RPC is suitable for scenarios that require a high degree of decoupling and high performance requirements, but require writing and maintaining a large amount of interface code.

8. What is a circuit breaker? How does Hystrix work in Spring Cloud?

Answer: A circuit breaker is a pattern used to prevent the propagation of faults in a distributed system. Hystrix is ​​a circuit breaker implementation in Spring Cloud that prevents avalanche effects by monitoring requests to dependent services and stopping requests to that service in the event of a failure.

9. What is an API gateway? What is Zuul in Spring Cloud?

Answer: An API gateway is a server used to manage and route requests for microservices. Zuul in Spring Cloud is an API gateway that can perform routing, filtering, load balancing and other tasks to better manage and protect microservices.

10.What is distributed configuration management? How does Config work in Spring Cloud?

Answer: Distributed configuration management is a way to centrally manage application configurations so that configurations can be shared and dynamically modified across multiple environments. Config in Spring Cloud allows application configuration to be stored on a configuration server and retrieved within the application on demand.

11.What is distributed tracing? How does Sleuth work in Spring Cloud?

Answer: Distributed tracing is a technique used to trace the flow of requests in a distributed system. Sleuth in Spring Cloud implements distributed tracing by adding a unique identifier (Trace ID) and trace segment identifier (Span ID) to each microservice request. Each microservice generates these identifiers and passes them to downstream microservices so that the path a request flows through can be traced.

12.What are message-driven microservices? How to implement message drive in Spring Cloud?

Answer: Message-driven microservices are a way of communicating between microservices through message passing. Spring Cloud uses Spring Cloud Stream to implement message drive. It provides abstract message channels and binders so that microservices can easily integrate message brokers (such as Kafka, RabbitMQ) for asynchronous communication.

13.What are service circuit breakers and service degradation in Spring Cloud?

Answer: A service circuit breaker is a mechanism used to prevent the propagation of faults in a distributed system. When a service fails, a service circuit breaker can disable requests to the service and prevent continuous calls to dependent services.

Service degradation is a way to provide limited but acceptable functionality when a service is unavailable or performs poorly. Hystrix in Spring Cloud provides service circuit breaker and service downgrade functions, allowing developers to define downgrade logic and apply it when needed.

14. How to protect the security of Spring Cloud microservices?

Answer: Spring Security can be used in Spring Cloud to protect the security of microservices. By configuring security policies, authentication, and authorization rules, you can ensure that only authorized users can access protected microservice endpoints.

15.What is Service Mesh? Is service mesh supported in Spring Cloud?

Answer: A service mesh is an infrastructure layer used to manage and control communication between microservices. Spring Cloud itself does not provide service mesh functions, but can be integrated with other service mesh frameworks (such as Istio, Linkerd) to enhance the security, observability and flow control of microservices.

16.How to handle distributed transactions in Spring Cloud?

  • Two-phase commit (2PC): one transaction, one coordinator, multiple participants.
    • Phase 1: Preparation phase. Each participant executes local transactions but does not commit, enters the preparation state, and notifies the coordinator that it is ready.
    • Phase 2: Submission phase, the coordinator confirms that each participant is ready, and then notifies the participants to submit. If any participant fails, a rollback command is sent and each participant performs rollback.
  • TCC (Try-Confirm-Cancel): This is a distributed transaction solution based on a compensation mechanism. Each service provides three operations: Try, Confirm, and Cancel.
    • Phase 1: Participants will reserve necessary resources and execute business logic. If all participants complete successfully, proceed to the next step; otherwise, cancel.
    • Phase 2: In this phase, the coordinator sends a confirmation request to all participants. Participants perform final confirmation and release the resources that have been reserved. If all participants complete successfully, the entire transaction is committed; otherwise, a cancellation is performed.
    • Phase 3: In this phase, the coordinator sends a rollback request to all participations. Participation performs corresponding cleanup work based on rollback requests and releases reserved resources.

17. Do you know what distributed transaction frameworks are?

  • Seata framework: It is an open source distributed transaction solution, mainly used in microservice architecture. The main roles of the Seata framework include transaction coordinator (TC), transaction manager (TM) and resource manager (RM).
  • GTS framework: It is a distributed transaction middleware developed by Alibaba's middleware department, which can provide a one-stop solution for distributed transactions in microservice architecture.

18.What is service monitoring and tracking? How to implement service monitoring and tracking in Spring Cloud?

Answer: Service monitoring and tracing are ways to monitor and analyze the performance and behavior of microservices. Spring Boot Actuator can be used in Spring Cloud to collect information about the application, and Sleuth can be used to implement distributed tracing.

19.What are the advantages of Spring Cloud Config?

Answer: Spring Cloud Config provides a centralized configuration management system. Its advantages include:

Centrally manage configuration and support multi-environment configuration.
Refresh configurations in real time without redeployment.
Configuration files can be managed using a version control system.
Can be integrated with various backend storages (such as Git, SVN, databases).

20.What are trace segments (Span) and traces (Trace) in Spring Cloud Sleuth?

Answer: In Spring Cloud Sleuth, a tracking segment (Span) represents a part of a unit of work, which contains execution information of a piece of code, such as start time, end time, time consumption, etc. Trace is a set of related trace fragments that represent a complete request processing process, including the call chain between multiple microservices.

21. How to implement version management of Spring Cloud microservices?

Answer: Version management of Spring Cloud microservices can be achieved by including version information in the registration information of the service instance. You can then use the service gateway or the client's load balancing policy to control the version routing of requests. Another method is to use Spring Cloud Ribbon's @RibbonClient annotation to implement different versions of load balancing configuration. Version management can also be used in conjunction with the configuration center to dynamically adjust version information.

22. What are the benefits of microservices?

Whether it's solving "developer problems" by aligning services with teams, reducing the risk of adopting new technologies, or easing deployment complexity and improving scalability, adopting microservices brings many benefits. Let's take a closer look:

  • Autonomous teams: Microservices allow small teams to fully own the entire lifecycle of a service. This increases accountability, code quality, and job satisfaction. For most large organizations, this "distribution of people" is one of the main reasons for adopting a microservices approach.
  • Heterogeneity of technologies: Developers could theoretically use different languages ​​and different technologies to build each service. This enables developers to choose the best technology for that specific service, rather than taking a more traditional standardized, one-size-fits-all approach.
  • Reduce the risk of adopting new technologies: Developers can also experiment with new technologies in low-risk services, knowing that if something goes wrong, it won't affect the rest of the system. Since risk is the biggest barrier to adopting new technology, this is a huge advantage.
  • Resilience: When a component fails, it does not necessarily affect the rest of the system. But be aware that an application is only as resilient as its architecture allows. Without good coding practices such as tracing, observability, and circuit breakers, glitches can still cascade in complex systems.
  • Scalability: To scale any one feature, you just scale the microservice, not the entire monolithic application.
  • Ease of deployment: If you update a line of code, you only need to update and redeploy that specific microservice, rather than redeploying the entire monolithic application. Conversely, rolling back a service is much easier than rolling back the entire application. Tools like Docker and Kubernetes have significantly reduced the cost of deployment and rollback.
  • Replaceability: Replacing microservices in an application is much easier than replacing components in a monolithic application.

おすすめ

転載: blog.csdn.net/qq_42785250/article/details/133001577