Micro service interview questions

1. What do you know about microservices?

2. What are the advantages of microservices architecture?

3. What are the features of microservices?

4. What are the best practices for designing microservices?

5. How does the microservices architecture work?

6. What are the advantages and disadvantages of microservices architecture?

7. What are the differences between monolithic, SOA and microservice architectures?

8. What challenges do you face when using microservices architecture?

9. What are the key differences between SOA and microservices architectures?

10. What are the characteristics of micro services?

What is Domain-driven design?

12. Why domain Driven Design (DDD)?

13. What is the ubiquitous language?

What is cohesion?

15. What is coupling?

What is REST/RESTful and what is its purpose?

17. What do you know about Spring Boot?

What is a Spring-booted executor?

19. What is Spring Cloud?

20. What problems does Spring Cloud solve?

21. What is the use of WebMvcTest annotations in Spring MVC applications?

22. Can you give me some key points about breaks and microservices?

23. What are the different types of microservice testing?

24. What do you know about Distributed Transaction?

25. What is Idempotence and where is it used?

26. What is bounded context?

27. What is two-factor authentication?

What are the credential types for two-factor authentication?

29. What is a customer certificate?

30. What is the use of PACT in the microservices architecture?

What is OAuth?

32. What is Conway’s law?

What do you know about contract testing

34. What is end-to-end microservice testing?

35. What is the use of Container in microservices?

36. What is DRY in microservices architecture?

37. What are consumer-driven contracts (CDC)?

38. What is the role of Web RESTful apis in microservices?

39. What do you know about semantic monitoring in microservices architecture?

40. How do we conduct cross-functional testing?

How do we eliminate determinism in testing?

What’s the difference between a Mock or a Stub?

43. What do you know about Mike Cohn’s testing pyramid?

44. What is the purpose of Docker?

What is canary release?

What is continuous integration (CI)?

47. What is continuous monitoring?

What is the architect’s role in microservices architecture?

49. Can we use microservices to create state machines?

50. What is reactive scaling in microservices?

1. What do you know about microservices?

Microservices, also known as microservices architecture, is an architectural style that builds applications as small, autonomous collections of services modeled on business domains.

In layman’s terms, you have to see how bees build their honeycomb by aligning hexagonal wax cells. They started with small pieces of various materials and went on to build a large beehive from them. These cells form patterns that produce sturdy structures that hold specific parts of the hive together. Here, each cell is independent of the other, but it’s also related to other cells. This means that damage to one cell does not damage other cells, so the bees can rebuild those cells without affecting the entire hive.

Figure 1: Cellular representation of microservices – microservices interview questions

Please refer to the picture above. Here, each hexagon shape represents a separate service component. Similar to the work of bees, each agile team builds individual service components using available frameworks and technology stacks of their choice. Like in a beehive, each service component forms a powerful microservice architecture to provide better scalability. In addition, agile teams can address each service component individually with little or minimal impact on the overall application.

2. What are the advantages of microservices architecture?

Figure 2: Advantages of microservices – microservices interview questions

· Independent development – All microservices can be easily developed according to their respective functions

· Standalone deployment — They can be deployed independently in any application based on their services

· Fault isolation – The system can continue to run even if one of the application’s services fails

· Hybrid technology stack — Different languages and technologies can be used to build different services for the same application

· Granular scaling — Individual components can be scaled as needed without all components being scaled together

3. What are the characteristics of micro-services?

Figure 3: Characteristics of microservices – microservices interview questions

· Decoupling — Services within the system are largely separated. As a result, the entire application can be easily built, changed, and extended

· Componentization — Microservices are treated as standalone components that can be easily replaced and upgraded

· Business capabilities — Microservices are very simple and focus on a single function

· Autonomy — Developers and teams can work independently of each other to increase speed

· Continuous delivery — through system automation of software creation, testing, and approval, allowing frequent software releases

· Responsibility — Microservices does not focus on the application as a project. Instead, they see applications as products they are responsible for

· Decentralized governance — Focus on using the right tools to do the right job. This means that there are no standardization patterns or any technical patterns. Developers are free to choose the most useful tools to solve their problems

· Agile — Microservices support agile development. Any new features can be quickly developed and discarded again

4. What are the best practices for designing microservices?

Here are some best practices for designing microservices:

Figure 4: Best practices for designing microservices – microservices interview questions

5. How does the microservices architecture work?

Microservices architecture has the following components:

Figure 5: Microservices architecture – Microservices interview questions

· Clients — Different users from different devices send requests.

· Identity provider — Authenticates user or customer identity and issues security tokens.

· API Gateway — Handles client requests.

· Static content — Holds all the content of the system.

· Management – Balancing services on nodes and identifying failures.

· Service discovery — A guide for finding communication paths between microservices.

· Content delivery network — a distributed network of proxy servers and their data centers.

· Remote services – Enable remote access information that resides on the NETWORK of IT devices.

6. What are the advantages and disadvantages of microservices architecture?

7. What are the differences between monolithic, SOA and microservice architectures?

Figure 6: Comparison between monolithic SOA and microservices – microservices interview question

· A monolithic architecture is similar to a large container in which all the software components of an application are assembled together and tightly packaged.

· A service-oriented architecture is a collection of services that communicate with each other. Communication can involve simple data transfer or two or more services that coordinate some activities.

· Microservices architecture is an architectural style that builds applications as small, autonomous collections of services modeled on business domains.

8. What challenges do you face when using microservices architecture?

Developing smaller microservices sounds easy enough, but the challenges often encountered in developing them are as follows.

· Automation components: It is difficult to automate because there are many smaller components. Therefore, for each component, we must follow the Build, Deploy, and Monitor phases.

· Susceptibility: Maintaining large numbers of components together becomes difficult to deploy, maintain, monitor, and identify problems. It requires good awareness around all the components.

· Configuration management: Sometimes it becomes difficult to maintain the configuration of components in a variety of environments.

· Debugging: It is difficult to find every service that is wrong. Maintaining centralized logging and dashboards to debug problems is critical.

9. What are the key differences between SOA and microservices architectures?

The key differences between SOA and microservices are as follows:

10. What are the characteristics of micro services?

You can list the characteristics of microservices, as follows:

Figure 7: Characteristics of microservices – microservices interview questions

What is Domain-driven design?

Figure 8: DDD principles – Microservices interview questions

12. Why domain Driven Design (DDD)?

Figure 9: We need DDD factors – micro service interview questions

13. What is the ubiquitous language?

If you must define a generic language (UL), it is a common language used by developers and users of a particular domain through which the domain can be easily interpreted.

The ubiquitous language must be very clear so that it puts all team members on the same page and translates in a way that machines can understand.

What is cohesion?

The degree to which elements within a module belong is known as cohesion.

15. What is coupling?

A measure of the strength of dependencies between components is known as coupling. A good design is always considered to have high cohesion and low coupling.

What is REST/RESTful and what is its purpose?

Representational State Transfer (REST)/RESTful Web services are an architectural style that helps computer systems communicate over the Internet. This makes microservices easier to understand and implement.

Microservices can be implemented with or without RESTful apis, but it is always easier to build loosely coupled microservices using RESTful apis.

17. What do you know about Spring Boot?

In fact, as new features are added, springs become more and more complex. If you must start a new Spring project, you must add a build path or add maven dependencies, configure the application server, and add spring configuration. So everything had to start from scratch.

Spring Boot is the solution to this problem. With Spring Boot, you can avoid all boilerplate code and configuration. So, basically think of yourself as if you’re baking a cake, and spring is like the ingredients you need to make a cake, and spring boots are the complete cake in your hand.

Figure 10: Spring Boot factors – microservices interview questions

What is a Spring-booted executor?

Spring Boot executors provide restful Web services to access the current state of running applications in a production environment. With the help of actuators, you can examine various metrics and monitor your application.

19. What is Spring Cloud?

According to Spring Cloud’s official website, Spring Cloud provides developers with tools to quickly build common patterns in distributed systems (such as configuration management, service discovery, circuit breakers, intelligent routing, leadership elections, distributed sessions, and cluster state).

20. What problems does Spring Cloud solve?

Few of the problems we face when developing distributed microservices using Spring Boot are solved by Spring Cloud.

· Complexity associated with distributed systems — including network issues, delay overhead, bandwidth issues, security issues.

· Ability to handle service discovery – Service discovery allows processes and services in a cluster to find and communicate with each other.

· Solve redundancy problems — Redundancy problems often occur in distributed systems.

· Load balancing — Improves workload distribution across multiple computing resources (such as clusters of computers, network links, central processing units).

· Reduce performance issues — Reduce performance issues due to various operational overhead.

21. What is the use of WebMvcTest annotations in Spring MVC applications?

The WebMvcTest annotation is used to unit test the Spring MVC application in cases where the test target is focused only on Spring MVC components. In the snapshot shown above, we just want ToTestController to start. When this unit test is executed, all other controllers and mappings are not started.

22. Can you give me some key points about breaks and microservices?

While you can implement microservices in many ways, REST over HTTP is one way to implement microservices. REST can also be used for other applications, such as Web applications, API designs, and MVC applications, to provide business data.

Microservices are an architecture in which all components of a system are placed into separate components that can be built, deployed, and extended separately. There are certain principles and best practices of microservices that help build resilient applications.

In short, you can say THAT REST is a medium for building microservices.

23. What are the different types of microservice testing?

When using microservices, testing is complicated by having multiple microservices working together. Therefore, tests are divided into different levels.

· At the bottom, we have technology-oriented testing, such as unit testing and performance testing. These are fully automated.

· At the intermediate level, we did exploratory testing such as stress testing and usability testing.

· At the top level, we have very few acceptance tests. These acceptance tests help stakeholders understand and validate software functionality.

24. What do you know about Distributed Transaction?

A distributed transaction is any situation in which a single event results in a mutation of two or more separate data sources that cannot be committed atomically. In the world of microservices, it becomes more complicated because each service is a unit of work, and most of the time multiple services must work together for a business to succeed.

25. What is Idempotence and where is it used?

Idempotence is the property of being able to do something twice in such a way that the end result will remain the same, i.e. as if it had been done only once.

Usage: Use Idempotence in a remote service or data source so that when it receives instructions multiple times, it only processes instructions once.

26. What is bounded context?

Bounded context is the core pattern of domain-driven design. The DDD strategic design department focuses on working with large models and teams. DDD handles large models by dividing them into different bounded contexts and clarifying their relationships.

27. What is two-factor authentication?

Two-factor authentication enables the second level of authentication for the account login process.

Figure 11: Representation of two-factor authentication – microservice interview questions

Therefore, assuming that the user must enter only a username and password, this is considered single-factor authentication.

What are the credential types for two-factor authentication?

The three certificates are:

Figure 12: Certificate types for two-factor authentication – microservices interview questions

29. What is a customer certificate?

A type of digital certificate that a client system uses to make authenticated requests to a remote server is called a client certificate. Client certificates play an important role in many mutual authentication designs and provide a strong guarantee of the identity of the requester.

30. What is the use of PACT in the microservices architecture?

PACT is an open source tool that allows testing of interactions between service providers and consumers, isolated from contracts, to improve the reliability of microservice integration.

Usage in microservices

· For implementing consumer-driven contracts in microservices.

· Test consumer-driven contracts between consumers and providers of microservices.

View upcoming batches

What is OAuth?

OAuth stands for Open Licensing Agreement. This allows access to the resource owner’s resources by enabling client applications (such as third party providers Facebook, GitHub, etc.) on HTTP services. Therefore, you can share resources stored on one site with another without using their credentials.

32. What is Conway’s law?

“The organization of any design system will yield a design whose architecture is a subtext of the organization’s communication architecture.” – Mel Conway

Figure 13: Representation of Conway’s Law — microservice interview problem

The law basically tries to communicate the fact that in order for software modules to work, the whole team should communicate well. Thus, the structure of a system reflects the social boundaries of the organization that produced it.

What do you know about contract testing

According to Martin Flower, a contract test is a test performed at an external service boundary to verify that a contract meets the expectations of consuming a service.

In addition, contract testing does not delve into testing the behavior of the service. Rather, it tests that the input & output of the service call contains the required properties and said response latency, and that throughput is within allowable limits.

34. What is end-to-end microservice testing?

End-to-end testing verifies that each process in the workflow works properly. This ensures that the system as a whole works together and meets all requirements.

In layman’s terms, you can say that end-to-end testing is a test that tests everything after a certain period of time.

Figure 14: Test level – microservice interview questions

35. What is the use of Container in microservices?

Containers are a good way to manage microservices-based applications so that they can be developed and deployed separately. You can encapsulate a microservice in a container image and its dependencies, which you can then use to scroll the microservice of an on-demand instance without any additional work.

Figure 15: Representation of containers and how they are used in microservices-microservice interview questions

36. What is DRY in microservices architecture?

DRY stands for don’t repeat yourself. It basically promotes the concept of reusing code. This leads to developing and sharing libraries, which in turn leads to tight coupling.

37. What are consumer-driven contracts (CDC)?

This is basically a pattern for developing microservices so that they can be used by external systems. When we work with microservices, there is a specific provider that builds it, and there is one or more consumers that use microservices.

Typically, providers specify interfaces in XML documents. But in a consumer-driven contract, each service consumer communicates the interface that the provider expects.

38. What is the role of Web RESTful apis in microservices?

Microservices architecture is based on the concept that all services should be able to interact with each other to build business functions. Therefore, to achieve this, each microservice must have an interface. This makes Web apis a very important enabler of microservices. RESTful apis Are web-based open network principles that provide the most reasonable model for building interfaces between components of a microservice architecture.

39. What do you know about semantic monitoring in microservices architecture?

Semantic monitoring, also known as comprehensive monitoring, combines automated tests with monitoring applications to detect business failure factors.

40. How do we conduct cross-functional testing?

Cross-functional testing is the validation of non-functional requirements, that is, requirements that cannot be implemented as normal functionality.

How do we eliminate determinism in testing?

Nondeterministic tests (NDT) are basically unreliable tests. So, sometimes they might pass, and obviously sometimes they might fail. When they fail, they re-run through.

Some ways to remove uncertainty from tests are as follows:

1, the isolation

2, asynchronous

3. Remote services

4, isolation

5, time,

6. Resource leakage

What’s the difference between a Mock or a Stub?

The stub

· A virtual object to help run tests.

· Provide fixed behavior under certain conditions that can be hard-coded.

· Stub is never tested for any other behavior.

For example, for an empty stack, you can create a stub that returns true only for the empty () method. Therefore, it doesn’t matter if there are elements in the stack.

Laugh at

· A virtual object in which some properties are initially set.

· The behavior of this object depends on the set property.

· You can also test the behavior of objects.

For example, with the Customer object, you can simulate it by setting the name and age. You can set age to 12 and then test the isAdult () method, which will return true if age is greater than 18. Therefore, your Mock Customer object applies to the specified conditions.

43. What do you know about Mike Cohn’s testing pyramid?

Mike Cohn provides a model called Test Pyramid. This describes the types of automated tests required for software development.

Figure 16: Mike Cohn’s Test Pyramid — Microservices interview questions

According to the pyramid, level 1 should have the highest number of tests. At the service layer, the number of tests should be smaller than at the unit test level, but larger than at the end-to-end level.

44. What is the purpose of Docker?

Docker provides a container environment that can be used to host any application. Here, the software application is tightly packaged with the dependencies that support it.

Therefore, this packaged product is called a Container, because it is done by Docker, so it is called a Docker Container!

What is canary release?

Canary Releasing is a technology that reduces the risk of introducing new software versions into production. This is done by slowly rolling out the changes to a small number of users, then publishing them to the entire infrastructure, making them available to everyone.

What is continuous integration (CI)?

Continuous integration (CI) is the process of automatically building and testing code every time a team member commits a version-control change. This encourages developers to share code and unit tests by merging changes into a shared version control repository after each small task is complete.

47. What is continuous monitoring?

Continuous monitoring monitors everything from front-end performance metrics in the browser, to application performance, to host virtualization infrastructure metrics.

What is the architect’s role in microservices architecture?

Architects in microservices architecture play the following roles:

· Determine the layout of the entire software system.

· Help determine partitioning of components. Therefore, they ensure that components are glued to each other, but not tightly coupled.

· Write code with developers to understand the challenges of daily life.

· Advise the team developing microservices on certain tools and technologies.

· Provide technical governance so that the technical development team can follow microservices principles.

49. Can we use microservices to create state machines?

We know that each microservice with its own database is a independently deployable unit of program, which in turn allows us to create a state machine. Therefore, we can specify different states and events for specific microservices.

For example, we can define the Order microservice. Orders can have different states. Transitions to Order state can be isolated events within the Order microservice.

50. What is reactive scaling in microservices?

Reactive Extensions are also known as Rx. This is a design approach where we collect the results by calling multiple services, and then compile the composite response. These calls can be synchronous or asynchronous, blocking or non-blocking. Rx is a very popular tool in distributed systems, as opposed to traditional processes.

SpringCloud interview questions

1. What is Spring Cloud?

The Spring Cloud Streaming application launcher is a Spring integration application based on Spring Boot that provides integration with external systems. Spring Cloud Task, a microservices framework with a short life span, is used to quickly build applications that perform limited data processing.

2. What are the advantages of using Spring Cloud?

When developing distributed micro-services using Spring Boot, we face the following issues

(1) Complexity associated with distributed systems – this overhead includes network issues, latency costs, bandwidth issues, and security issues.

(2) Service discovery – The service discovery tool manages how processes and services in the cluster look up and talk to each other. It involves a catalog of services in which you can register services and then be able to find and connect to services in that catalog.

(3) redundancy – the redundancy problem in distributed system.

(4) Load balancing — Load balancing improves the distribution of workloads across multiple computing resources, such as computers, computer clusters, network links, central processing units, or disk drives.

(5) Performance – Issues Performance issues due to various operational overhead.

(6) Deployment complexity -Devops skill requirements.

3. What does service registration and discovery mean? How is Spring Cloud implemented?

When we start a project, we usually do all the configuration in the properties file. As more services are developed and deployed, adding and modifying these properties becomes more complex. Some services may decline and some locations may change. Manually changing properties can cause problems. Eureka service registration and discovery can help in this situation. Because all services are registered on the Eureka server and lookup is done by calling the Eureka server, there is no need to handle any changes and processing of the service location.

4. What’s the difference between Spring Cloud and Dubbo?

Dubbo is RPC SpringCloud Rest Api

(2) Registry, Dubbo is ZooKeeper, SpringCloud is Eureka, and it can also be ZooKeeper

(3) Service gateway,dubbo itself is not implemented, can only be integrated through other third-party technologies, SpringCloud has Zuul routing gateway, as a routing server, for consumer request distribution, SpringCloud supports circuit breakers, perfect integration with Git configuration file support version control, The transaction bus implements a series of microservice architecture elements such as configuration file update and automatic service assembly.

5. The difference between SpringBoot and SpringCloud?

SpringBoot focuses on developing individual microservices quickly and easily.

SpringCloud is a global microservices coordination and consolidation governance framework, which integrates and manages individual microservices developed by SpringBoot.

Provide integrated services for configuration management, service discovery, circuit breakers, routing, micro proxy, event bus, global lock, decision campaign, distributed session, and so on between microservices

SpringBoot can be independently used for development projects without SpringCloud, but SpringCloud is dependent on SpringBoot.

SpringBoot focuses on developing individual microservices quickly and easily, while SpringCloud focuses on a global service governance framework.

What is the significance of load balancing?

In computing, load balancing can improve workload distribution across multiple computing resources such as computers, computer clusters, network links, central processing units, or disk drives. Load balancing is designed to optimize resource usage, maximize throughput, minimize response time, and avoid overloading any single resource. Load balancing with multiple components rather than a single component may improve reliability and availability through redundancy. Load balancing typically involves proprietary software or hardware, such as multi-tier switches or domain name system server processes.

7. What is Hystrix? How does it achieve fault tolerance?

Hystrix is a delay and fault tolerant library designed to isolate access points to remote systems, services and third party libraries, stopping cascading failures when failures are unavoidable and enabling resilience in complex distributed systems.

Typically for systems developed using a microservice architecture, many microservices are involved. These microservices work with each other.

Consider the following microservices

Suppose that if microservice 9 in the figure above fails, we will propagate an exception using traditional methods. But it can still cause the whole system to crash.

The problem becomes more complicated as the number of microservices increases. The number of microservices can be as high as 1000. This is where Hystrix comes in and we will use hystrix’s Fallback method functionality in this case. We have two services employee-Consumer that use services exposed by Employee-Consumer.

The simplified figure is shown below

Now suppose that for some reason the employee-producer exposed service throws an exception. We defined a fallback method in this case using Hystrix. This backup method should have the same return type as the exposed service. If an exception occurs in the exposed service, the fallback method returns some values.

8. What is Hystrix circuit breaker? Do we need it?

For some reason, the Employee-Consumer exposure service throws an exception. Using Hystrix in this case we define a fallback method. If an exception occurs in the exposed service, the fallback method returns some default values.

If the exception in firstPage Method () continues, the Hystrix circuit will break and the employee users will collectively skip the firtsPage method and call the fallback method directly. The purpose of a circuit breaker is to allow time for the first page method or other methods that the first page method might call and cause an abnormal recovery. What may happen is that, with a low load, the problem that caused the exception has a better chance of recovery.

9. What is Netflix Feign? What are its advantages?

Feign is a Java client interprogramming inspired by Retrofit, JAXRS-2.0, and WebSocket.

Feign’s first goal was to unify the complexity of the constraint denominator into the HTTP apis, regardless of its stability.

In the Employee-consumer example, we use the Employee-Producer REST service exposed using the REST template.

But we have to write a lot of code to perform the following steps

(1) Use functional zones for load balancing.

(2) Get the service instance, and then get the base URL.

(3) Use REST templates to use services. The previous code is as follows

@Controller
public class ConsumerControllerClient {
    @Autowired
    private LoadBalancerClient loadBalancer;
    public void getEmployee() throws RestClientException, IOException {
        ServiceInstance serviceInstance=loadBalancer.choose("employee-producer");
        System.out.println(serviceInstance.getUri());
        String baseUrl=serviceInstance.getUri().toString();
        baseUrl=baseUrl+"/employee";
        RestTemplate restTemplate = new RestTemplate();
        ResponseEntity<String> response=null;
        try{
            response=restTemplate.exchange(baseUrl,
                        HttpMethod.GET, getHeaders(),String.class);
        }
        catch (Exception ex)
            {
            System.out.println(ex);
        }
        System.out.println(response.getBody());
    }Copy the code
The previous code, with opportunities for exceptions like NullPointer, was not optimal. We’ll see how Netflix Feign can be used to make calling easier and cleaner. If the Netflix Ribbon dependency is also in the classpath, then Feign is also responsible for load balancing by default.

What is Spring Cloud Bus? Do we need it?

Consider the following situation: we have multiple applications that use Spring Cloud Config to read properties, and Spring Cloud Config reads those properties from GIT.

The following example shows multiple Employee producer modules fetching Eureka registered properties from the Employee Config Module.

What happens if you assume that the Eureka registration property in GIT changes to point to another Eureka server. In this case, we would have to restart the service to get the updated properties.

There is another way to use executor endpoints/flushes. But we will have to call this URL separately for each module. For example, if Employee Producer1 is deployed on port 8080, http:// localhost: 8080 / refresh is called. Also for Employee Producer2 http://localhost:8081 / refresh, etc. That’s a hassle. This is where Spring Cloud Bus comes in.

Spring Cloud Bus provides the ability to refresh configurations across multiple instances. Therefore, in the example above, if we refresh Employee Producer1, all other required modules are automatically refreshed. This is especially useful if we have multiple microservices up and running. This is achieved by connecting all microservices to a single message broker. Whenever an instance is refreshed, this event subscribes to all microservices listening to this agent, and they are refreshed as well. The refresh of any single instance can be achieved by using endpoint/bus/refresh.

11. Role of SpringCloud circuit breaker

When a service calls another service due to network or its own problems, the caller will wait for the response of the called service. When more services request these resources, more requests wait, resulting in a chain effect (avalanche effect).

The circuit breaker has a fully open state: it cannot be called for a certain number of times within a period of time and there is no sign of recovery after repeated monitoring. The circuit breaker is fully open and the next request will not request the service

Half-open: The circuit breaker will send partial requests to the service if there are signs of recovery within a short period of time. The circuit breaker will close when it is called normally

Off: The service can be invoked when it is in the normal state

12. What is SpringCloudConfig?

In a distributed system, due to a large number of services, a distributed configuration center is required to facilitate unified management and real-time update of service configuration files. In Spring Cloud, there is a distributed configuration center component, Spring Cloud Config, which enables configuration services to be placed in the memory of the configuration service (that is, locally) as well as in a remote Git repository. In the Spring Cloud Config component, there are two roles: Config Server and Config client.

Use:

(1) Add POM dependencies

(2) Add related configurations to the configuration file

(3) Add the @enableconFigServer annotation to the start class

13, Spring Cloud Gateway?

Spring Cloud Gateway is the second generation of Spring Cloud’s official Gateway framework, replacing Zuul Gateway. As a traffic, the gateway plays a very important role in the micro-service system. The common functions of the gateway include routing and forwarding, permission verification, and traffic limiting control.

The RouteLocatorBuilder allows you to add various predicates and filters, based on the rules of the specific request. Filters are the kinds of filters used to make various judgments and changes to the request, processed by a specific route.

Spring Boot interview question

1. What is Spring Boot?

Over the years, Spring has become more complex as new features have been added. Visit the Spring official website page to see the different features of all the Spring projects that can be used in our application. If we had to start a new Spring project, we had to add build paths or Maven dependencies, configure the application server, and add Spring configuration. So starting a new Spring project takes a lot of effort, because we now have to do everything from scratch.

Spring Boot is the solution to this problem. Spring Boot is already built on top of the existing Spring framework. With Spring boot, we avoided all the boilerplate code and configuration that we had to do before. Therefore, Spring Boot can help us use existing Spring functionality more robustly with less effort.

2. What are the advantages of Spring Boot?

The advantages of Spring Boot include:

1. Reduce development and testing time and effort.

2. Using JavaConfig helps avoid using XML.

3. Avoid massive Maven imports and versioning conflicts.

4. Provide advice on developing methods.

5. Start development quickly by providing default values.

6. No separate Web server is required. This means you no longer need to start Tomcat, Glassfish, or anything else.

7. Requires less configuration because there is no web.xml file. Simply add the class annotated with @Configuration, then add the method annotated with @Bean, and Spring will automatically load the object and manage it as before. You can even add @AutoWired to the bean method to make Spring automatically load the required dependencies.

With these properties, you can deliver the environment you are using to your application: -dspring.profiles. active = {enviorvulnerabilities}. After loading the main application properties file, Spring loads subsequent application properties files in (Application {environment}.properties).

3. What is JavaConfig?

The Spring JavaConfig is a product of the Spring community that provides a pure Java method for configuring the Spring IoC container. So it helps to avoid using XML configuration. The advantages of using JavaConfig are:

(1) Object-oriented configuration. Because the configuration is defined as a class in JavaConfig, users can take full advantage of Java’s object-oriented capabilities. One configuration class can inherit from another, override its @bean methods, and so on.

(2) Reduce or eliminate XML configuration. The benefits of externalizing configuration based on dependency injection principles have been proven. However, many developers do not want to switch back and forth between XML and Java. JavaConfig provides developers with a pure Java way to configure a Spring container that is similar in concept to XML configuration. Technically, it is possible to configure the container using only the JavaConfig configuration class, but in practice many people think that mixing JavaConfig with XML is ideal.

(3) Type safety and refactoring friendly. JavaConfig provides a type-safe way to configure the Spring container. Thanks to Java 5.0 support for generics, beans can now be retrieved by type rather than by name, without any casts or string-based look-ups.

4. How do I reload changes on Spring Boot without restarting the server?

This can be done using the DEV tool. With this dependency, you can save any changes and embedded Tomcat will restart. Spring Boot has a development tools (DevTools) module that helps increase developer productivity. One of the major challenges facing Java developers is automatically deploying file changes to the server and automatically restarting the server. Developers can reload changes on Spring Boot without having to restart the server. This will eliminate the need to manually deploy changes every time. Spring Boot did not have this feature when it released its first version. This is the most desirable feature for developers. The DevTools module fully meets the needs of developers. This module will be disabled in production. It also provides a H2 database console to better test applications.

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>Copy the code

5. What is the monitor in Spring Boot?

Spring Boot Actuator is one of the important functions in Spring boot framework. The Spring Boot monitor helps you access the current status of running applications in your production environment. Several metrics must be checked and monitored in the production environment. Even though some external applications may be using these services to trigger alert messages to the people concerned. The monitor module exposes a set of REST endpoints that can be accessed directly as HTTP urls to check status.

6. How to disable THE security of endpoints in Spring Boot?

By default, all sensitive HTTP endpoints are secure, and only users with ACTUATOR roles can access them. Security is the use of standard it. IsUserInRole method implementation. We can use it to disable security. Disabling security is recommended only if an actuator endpoint is accessed behind a firewall.

7. How to run a Spring Boot application on a custom port?

To run Spring Boot applications on custom ports, you can specify ports in application.properties. server.port = 8090

8. What is YAML?

YAML is a human-readable data serialization language. It is usually used for configuration files. Compared to properties files, YAML files are more structured and less confusing if we want to add complex properties to a configuration file. You can see that YAML has hierarchical configuration data.

How to implement Spring Boot application security?

To implement Spring Boot security, we use the spring-boot-starter-security dependency and must add a security configuration. It requires very little code. Configuration class will must extend WebSecurityConfigurerAdapter and override the method.

10. How to integrate Spring Boot and ActiveMQ?

For integrating Spring Boot and ActiveMQ, we use dependencies. It requires very little configuration and no boilerplate code.

How to use Spring Boot to implement paging and sorting?

Using Spring Boot to implement paging is simple. Using Spring Data-jPA, you can implement paged pass-to-repository methods.

12, What is Swagger? Did you implement it with Spring Boot?

Swagger is widely used in visualization apis, using the Swagger UI to provide an online sandbox for front-end developers. Swagger is a tool, specification, and complete framework implementation for generating visual representations of RESTful Web services. It enables documents to be updated at the same rate as the server. When defined correctly by Swagger, consumers can understand and interact with remote services with minimal implementation logic. Thus, Swagger takes the guesswork out of invoking the service.

13. What are Spring Profiles?

Spring Profiles allows users to register beans against configuration files (dev, test, PROd, etc.). Therefore, when the application is running in development, only certain beans can be loaded, while in PRODUCTION, certain other beans can be loaded. Let’s say our requirement is that the Swagger document only works in the QA environment and all other documents are disabled. This can be done using configuration files. Spring Boot makes using configuration files very simple.

14. What is Spring Batch?

Spring Boot Batch provides reusable functions that are important when handling a large number of records, including logging/tracing, transaction management, job processing statistics, job restart, skip, and resource management. It also provides more advanced technical services and capabilities that enable extremely high volume and high performance batch jobs through optimization and partitioning techniques. Both simple and complex bulk batch jobs can leverage the framework to process significant amounts of information in a highly extensible manner.

15. What is a FreeMarker template?

FreeMarker is a Java-based templating engine that initially focused on dynamic web page generation using MVC software architecture. The main advantage of using Freemarker is the complete separation of the presentation layer and the business layer. Programmers can work with application code, while designers can work with HTML page design. Finally, using Freemarker, you can combine these together to give the final output page.

16. How to use Spring Boot to implement exception handling?

Spring provides a very useful way to handle exceptions using ControllerAdvice. We handle all exceptions thrown by the controller class by implementing a ControlerAdvice class.

17. Which Starter Maven dependencies do you use?

The following dependencies are used

spring-boot-starter-activemq

spring-boot-starter-security

This helps to add fewer dependencies and reduce version conflicts.

What is a CSRF attack?

CSRF stands for cross-site request forgery. This is an attack that forces an end user to perform unwanted actions on a currently authenticated Web application. CSRF attacks specifically target state-change requests, not data theft, because the attacker cannot see the response to forged requests.

What are WebSockets?

WebSocket is a computer communication protocol that provides a full-duplex communication channel over a single TCP connection.

1. WebSocket is bidirectional – a WebSocket client or server can send messages.

WebSocket is full-duplex – client and server communication is independent of each other.

3. A single TCP connection – the initial connection uses HTTP, and then the connection is upgraded to a socket based connection. This single connection is then used for all future communications

4. Light – WebSocket message data exchange is much lighter than HTTP.

What is AOP?

In software development, functionality that spans multiple points in an application is called a crossover problem. These crossover issues are different from the main business logic of the application. Thus, separating these crosscutting concerns from business logic is where aspect-oriented programming (AOP) comes in.

What is Apache Kafka?

Apache Kafka is a distributed publish-subscribe messaging system. It is an extensible, fault-tolerant publish-subscribe messaging system that enables us to build distributed applications. This is an Apache top-level project. Kafka is suitable for offline and online messaging consumption.

22. How do we monitor all Spring Boot microservices?

Spring Boot provides monitor endpoints to monitor metrics for individual microservices. These endpoints are useful for getting information about applications, such as whether they are started, and whether their components, such as databases, are functioning properly. However, one of the major disadvantages or difficulties of using monitors is that we have to open the knowledge points of the application separately to understand its state or health. Imagine a microservice that involves 50 applications, and an administrator would have to hit the execution terminals for all 50 applications. To help us deal with this situation, we will use the open source project located in. Built on top of Spring Boot Actuator, it provides a Web UI that enables us to visualize metrics for multiple applications.

The last

2019 common Java interview questions summed up a nearly 500 page PDF document, welcome to follow my official account: Programmer chasing wind, receive these sorted materials!


If you like the article, remember to pay attention to me. Thank you for your support!