Analysis of 29 microservice knowledge points you must master in 2020? I don't understand you come to me!

Opening introduction

Microservices (or microservices architecture) is a cloud-native architectural approach in which a single application consists of many smaller components or services that are loosely coupled and independently deployable. These services usually
have their own stack, including databases and data models; they
communicate with each other through a combination of REST APIs, event streams and message brokers;
they are organized by business capabilities, and the lines separating services are usually called bounded contexts.
Although many discussions about microservices have revolved around architectural definitions and characteristics, their value can be more generally understood through fairly simple business and organizational benefits:

  • You can update the code more easily.
  • The team can use different stacks for different components.
  • Components can be scaled independently of each other, reducing the waste and cost of having to scale the entire application, because a single function may face excessive load.

Microservices can also be understood by what they are not. The two most frequently drawn comparisons of microservice architecture are overall architecture and service-oriented architecture (SOA).
The difference between microservices and overall architecture is that microservices consist of many smaller, loosely coupled services to form an application, as opposed to the overall approach of large, tightly coupled applications.
The difference between microservices and SOA may not be clear. Although it is possible to form a technical contrast between microservices and SOA, especially around the role of an enterprise service bus (ESB), it is easier to treat the difference as one of the scope. SOA is an enterprise-wide work that aims to standardize the way all services communicate and integrate with each other, while the microservice architecture is application-specific.
Insert picture description here

text

1. What is Spring Cloud?

In microservices, SpringCloud is a system that provides integration with external systems. It is an agile framework that can build applications quickly and easily. Associated with a limited amount of data processing, it plays a very important role in the microservice architecture.
The following are the core features of Spring Cloud:

  • Versioned/distributed configuration.
  • Service registration and discovery.
  • Services and calls between services.
  • routing.
  • Circuit breaker and load balancing.
  • Distributed messaging.

2. What is Spring Boot?

Spring boot is the main topic of microservice interview questions.
With the addition of new features, Spring becomes more and more complex. Whenever you start a new project, you must add a new build path or Maven dependency. In short, you need to do everything from scratch. Spring Boot is a solution that helps you avoid all code configuration.

3. How to override the default properties of Spring Boot project?

This can be done by specifying properties in the application.properties file.
E.g,

  • In Spring MVC applications, you must specify the suffix and prefix. This can be done by entering the properties mentioned below in the application.properties file.
  • For the suffix-spring.mvc.view.suffix: .jsp
  • For the prefix-spring.mvc.view.prefix: /WEB-INF/

Fourth, the role of Actuator in Spring Boot

It is one of the most important features that helps you access the current state of applications running in a production environment. There are multiple indicators that can be used to check the current status. They also provide endpoints for RESTful web services, which can be simply used to check different metrics.

5. How to implement Spring security in Spring Boot applications?

Implementation requires minimal configuration. All you need to do is spring-boot-starter-security to add starter to the pom.xml file. You also need to create a Spring configuration class that will override the required methods while extending the security in the WebSecurityConfigurerAdapter application. This is some sample code:

package com.gkatzioura.security.securityendpoints.config; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.security.config.annotation.web.builders.HttpSecurity; 
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    
         
@Override    
protected void configure(HttpSecurity http) throws Exception {
    
             
http.authorizeRequests()             
.antMatchers("/welcome").permitAll()             
.anyRequest().authenticated()             
.and()             
.formLogin()             
.permitAll()             
.and()             
.logout()             
.permitAll();     
} 
}

6. Which embedded containers does Spring Boot support?

Whenever you create a Java application, you can deploy it in two ways:
using an external application container.
Embed the container in the jar file.
Spring Boot includes Jetty, Tomcat and Undertow servers, all of which are embedded.
Jetty-Used for a large number of projects, Eclipse Jetty can be embedded in frameworks, application servers, tools and clusters.
Tomcat-Apache Tomcat is an open source JavaServer Pages implementation that can be used well with embedded systems.
Undertow-a flexible and prominent web server, it uses a small single processing program to develop a web server.

7. What does end-to-end testing of microservices mean?

End-to-end testing verifies all processes in the workflow to check that everything is working as expected. It also ensures that the system works in a uniform way to meet business needs.

8. What is Semantic monitoring?

It combines the monitoring of the entire application and automated testing. The main benefit of semantic monitoring is to find out factors that are more profitable for your business.
From a business perspective, semantic monitoring and service layer monitoring can monitor microservices. Once a problem is detected, they can achieve faster isolation and misclassification, thereby reducing the major time required for repair. It classifies the service layer and the transaction layer to identify transactions that are affected by poor availability or performance.

9. How to set up service discovery?

There are multiple ways to set up service discovery. I will choose the one I think is the most efficient, Netflix's Eureka. This is a simple program and will not affect the application much. In addition, it supports multiple types of web applications.
Eureka configuration consists of two steps-client configuration and server configuration.

Client configuration can be done easily using properties files. In clas spath, Eureka searches for an eureka-client.properties file. It also searches for coverage caused by the environment in the environment-specific properties file.

For server configuration, you must first configure the client. After completion, the server starts a client, which is used to find other servers. . By default, Eureka server uses client configuration to find peer servers.

10. Why choose a microservice architecture?

This is a very common microservice interview question, you should be ready! The microservice architecture provides many advantages. Here are a few:

  • Microservices can easily adapt to other frameworks or technologies.
  • The failure of a single process will not affect the entire system.
  • Provide support for large companies and small teams.
  • It can be deployed independently in a relatively short time.

11. Why do I need Reports and Dashboards in microservices?

Reports and dashboards are mainly used to monitor and maintain microservices. There are multiple tools that can help achieve this goal. Reports and dashboards can be used to:

  • Find out which microservices expose which resources.
  • Find out which services are affected when the component changes.
  • Provide a simple point, as long as you need a document, you can access it.
  • The version of the deployed component.

12. Why do people hesitate to use microservices?

I have seen many developers groping on this issue. After all, they will be asked this question when interviewing for the role of microservice architect, so admitting its shortcomings can be a bit tricky. Here are some good answers:

  • They require a lot of collaboration-microservices require a lot of collaboration. Different microservice modules may be scattered in different teams, and teams need to always maintain good synchronization.
  • They need to build a heavy architecture-the system is distributed and there are many architectures involved.
  • They need too much planning to deal with operational overhead-if you plan to use a microservice architecture, you need to be prepared for operational overhead.
  • Skilled professionals are required, who can support heterogeneously distributed microservices.

13. How does PACT work?

PACT is an open source tool. It helps to test the interaction between consumers and service providers. The consumer service developer first writes a test that defines the mode of interaction with the service provider. The test includes the status of the provider, the request body and the expected response. Based on this, PACT created a stub to perform tests against it. The output is stored in a JSON file.

14. Talk about domain-driven design

Mainly focus on core domain logic. Domain-based model checks complex designs. This involves regularly working with domain experts at the company level to solve domain-related issues and improve the application model. When answering this microservice interview question, you also need to mention the core basics of DDD. they are:

  • DDD mainly focuses on the domain logic and the domain itself.
  • The complex design is completely based on the domain model.
  • In order to improve the design of the model and solve any emerging problems, DDD continuously cooperates with experts in the company's field.

15. What is coupling and cohesion?

A measure of the strength of dependencies between components is considered coupling. A good design is always considered to have high cohesion and low coupling.
Interviewers often ask about cohesion. It is also another unit of measurement. It is more like the degree to which the elements within a module remain integrated.
It must be remembered that an important key to designing microservices is the combination of low coupling and high cohesion. When the coupling is low, the service has very little dependence on other services. This maintains the integrity of the service. With high cohesion, it becomes possible to store all relevant logic in the service. Otherwise, the services will try to communicate with each other, which affects overall performance.

16. What is Oauth?

An open authorization protocol, which allows access to the resources of the resource owner by enabling client applications (such as third-party providers Facebook, GitHub, etc.) on the HTTP service. Therefore, you can share resources stored on one site with another site without using its credentials.

OAuth allows third parties like Facebook to use the end user's account information while keeping it safe (not using or exposing the user's password). It is more like an intermediary on behalf of the user, while providing the server with a token to access the required information.

17. Why do we need microservice containers?

To manage microservice-based applications, containers are the simplest choice. It helps users to deploy and develop individually. You can also use Docker to package microservices into container images. Without any additional dependencies or work, microservices can use these elements.

18. What is the method to access RESTful microservices?

Another microservice interview question that is often asked is how to access RESTful microservices? You can do this in two ways:

  • Use load-balanced REST templates.
  • Use multiple microservices.

19. What are the main obstacles to microservice testing?

Speaking of shortcomings, here is another microservice interview question that will revolve around the challenges faced when testing microservices.

Before starting to write test cases for integration tests, testers should have a thorough understanding of all inbound and outbound processes. When independent teams are developing different functions, collaboration may prove to be a very difficult task. It is difficult to find a window of free time to perform a complete regression test. As the number of microservices increases, the complexity of the system also increases. During the transition from a monolithic architecture, testers must ensure that the internal communication between components is not interrupted.

Twenty, common mistakes when transitioning to microservices

Errors often occur not only in development, but also in aspects of the process. Some common errors are:

  • Often developers cannot outline current challenges.
  • Rewrite the existing program.
  • Responsibilities, timelines and boundaries are not clearly defined.
  • Failed to implement and determine the scope of automation from the beginning.

21. What is the basis of microservice design?

This is probably one of the most common microservice interview questions. When answering this question, you need to remember the following:

  • Define the scope.
  • Combine low coupling and high cohesion.
  • Create a service with a unique ID. The unique ID will serve as the source of identification, much like a unique key in a database table.
  • Create the right API and pay special attention during the integration process.
  • Restrict access to data and restrict it to the required level.
  • Maintain a smooth flow between request and response.
  • Automate most processes to reduce time complexity.
  • Keep the number of tables to a minimum to reduce space complexity.
  • Continuously monitor the architecture and fix defects in time.
  • The data storage of each microservice should be separated.
  • For each microservice, there should be an independent build.
  • Deploy the microservice into the container.
  • The server should be considered stateless.

22. What is the use of WebMvcTest annotation in Spring MVC application?

The WebMvcTest annotation is used to unit test Spring MVC applications. We just want to start ToTestController. When this unit test is executed, all other controllers and maps will not be started.

@WebMvcTest(value = ToTestController.class, secure = false):

23. What is a bounded context?

Bounded context is the core mode of domain-driven design. The focus of the DDD strategic design department is to deal with large models and teams. DDD deals with large models by dividing them into different bounded contexts and clarifying their interrelationships.

24. What are the different types of two-factor authentication?

Three types of credentials are required to perform two-factor authentication:

  • One thing you know-such as password, password or screen lock mode.
  • Physical credentials you have, such as OTP, phone or ATM card, in other words, any type of credentials you have in external or third-party devices.
  • Your physical identity-such as voice authentication or biometric security, such as a fingerprint or eye scanner.

25. What is a client certificate?

A digital certificate used by the client system to send an authenticated request to a remote server is called a client certificate. Client certificates play a very important role in many mutual authentication designs, and provide a strong guarantee for the identity of the requester.

26. What is Conway's Law?

Conway's Law states that "The design of the organization of the design system is equivalent to the communication structure within and between organizations."
Interviewers may ask anti-microservice interview questions, such as the relationship between Conway's law and microservices. Some loosely coupled APIs form a microservice architecture. This structure is very suitable for small teams to implement autonomous components. This architecture makes organizations more flexible when reorganizing their work processes.

27. How to configure Spring Boot application logging?

Spring Boot comes with support for Log4J2, Java Util Logging and Logback. It is usually pre-configured for console output. They can be configured by only specifying logging.level in the application.properties file.

logging.level.spring.framework=Debug

28. How will you perform security testing on microservices?

You need to test each part independently. There are three common procedures:

  • Code scanning-to ensure that any line of code has no errors and can be copied.
  • Flexibility-The security solution should be flexible so that it can be adjusted to the requirements of the system.
  • Adaptability-Security protocols should be flexible and updated to deal with new threats from hackers or security breaches.

29. What is idempotence? How is it used?

Idempotence refers to a scenario where you perform a task repeatedly, but the final result remains the same or similar.
Idempotence is mainly used as a data source or remote service. When it receives more than one set of instructions, it only processes one set of instructions.

Off topic

This is the end of this sharing about microservices. Due to space limitations, only a small part of the content is released. Recently, it is the best time to find a job. I want to get more microservice-related questions and interview questions from major vendors. You can click here to get the information, code: qf The
following is a screenshot of some of the information (all the information has been integrated into a document, and pdf is compressed and packaged).

Insert picture description here

Guess you like

Origin blog.csdn.net/S11035762/article/details/108597794