Microservices interview questions


1. What Is Spring Cloud?

Probably, the first microservices interview question that you may encounter. Spring Cloud in Microservices, is a system that provides integration with external systems. It is a short-lived framework that builds an application in a fast manner. Being associated with the finite amount of data processing, it plays a very important role in Microservice architecture.

For typical use cases, Spring cloud provides some out of the box experience and a set of extensive features mentioned-below:

·         Versioned and distributed configuration

·         Discovery of service registration

·         Service to service calls

·         Routing

·         Circuit breakers and load balancing

·         Cluster state and leadership election

·         Global locks and distributed messaging

2. What Is Spring Boot?

Spring boot is a major topic under the umbrella of microservices interview questions.
With the new functionalities that have been added, Spring keeps getting more complex. Whenever you are starting a new project, it is mandatory to add a new build path or Maven dependencies. In short, you will need to do everything from scratch. Spring Boot is the solution that will help you to avoid all the code configurations. 

3. How Do You Override a Spring Boot Project’s Default Properties?

This can be done by specifying the properties in the application.properties file.
For example, in Spring MVC applications, you have to specify the suffix and prefix. This can be done by entering the properties mentioned below in the application.properties file.

  • For suffix – spring.mvc.view.suffix: .jsp
  • For prefix – spring.mvc.view.prefix: /WEB-INF/

4. Role of Actuator in Spring Boot

Essentially, Actuator brings Spring Boot applications to life by enabling production-ready features. These features allow us to monitor and manage applications when they’re running in production.

Integrating Spring Boot Actuator into a project is very simple. All we need to do is to include the spring-boot-starter-actuator starter in the pom.xml file:

<dependency>
    <groupId>org.springframework. boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Spring Boot Actuator can expose operational information using either HTTP or JMX endpoints. Most applications go for HTTP, though, where the identity of an endpoint and the /actuator prefix form a URL path.

Here are some of the most common built-in endpoints Actuator provides:

•auditevents: Exposes audit events information

•env: Exposes environment properties

•health: Shows application health information

•httptrace: Displays HTTP trace information

•info: Displays arbitrary application information

•metrics: Shows metrics information

•loggers: Shows and modifies the configuration of loggers in the application

•mappings: Displays a list of all @RequestMapping paths

•scheduledtasks: Displays the scheduled tasks in your application

•threaddump: Performs a thread dump

5. How Is Spring Security Implemented In a Spring Boot Application?

Minimal configuration is needed for implementation. All you need to do is add the spring-boot-starter-securitystarter in the pom.xml file. You will also need to create a Spring config class that will override the required method while extending the WebSecurityConfigurerAdapter to achieve security in the application. Here is some example code:

import org.springframework.context.annotation.Configuration;import org.springframework.security.config.annotation.web.builders.HttpSecurity;import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;@Configurationpublic 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 Are Supported by Spring Boot?

Whenever you are creating a Java application, deployment can be done via two methods:

  • Using an application container that is external.
  • Embedding the container inside your jar file.

Spring Boot contains Jetty, Tomcat, and Undertow servers, all of which are embedded.

  • Jetty – Used in a wide number of projects, Eclipse Jetty can be embedded in framework, application servers, tools, and clusters.
  • Tomcat – Apache Tomcat is an open source JavaServer Pages implementation which works well with embedded systems.
  • Undertow – A flexible and prominent web server that uses small single handlers to develop a web server.

7. What Do You Mean by End-To-End Testing of Microservices?

End-to-end testing validates all the processes in the workflow to check if everything is working as expected. It also ensures that the system works in a unified manner, thereby satisfying the business requirement.

8. What Is Semantic Monitoring?

It combines monitoring of the entire application along with automated tests. The primary benefit of Semantic Monitoring is to find out the factors which are more profitable to your business.

Semantic monitoring along with service layer monitoring approaches monitoring of microservices from a business point of view. Once an issue is detected, they allow faster isolation and bug triaging, thereby reducing the main time required to repair. It triages the service layer and transaction layer to figure out the transactions affected by availability or poor performance.

9. How Can You Set Up Service Discovery?

There are multiple ways to set up service discovery. I’ll choose the one that I think to be most efficient, Eureka by Netflix. It is a hassle free procedure that does not weigh much on the application. Plus, it supports numerous types of web applications.

Eureka configuration involves two steps – client configuration and server configuration.
Client configuration can be done easily by using the property files. In the class path, Eureka searches for a eureka-client.properties file. It also searches for overrides caused by the environment in property files which are environment specific.

For server configuration, you have to configure the client first. Once that is done, the server fires up a client which is used to find other servers. The Eureka server, by default, uses the Client configuration to find the peer server.

10. Why Would You Opt for Microservices Architecture?

This is a very common microservices interview question which you should be ready for! There are plenty of pros that are offered by a microservices architecture. Here are a few of them:

  • Microservices can adapt easily to other frameworks or technologies.
  • Failure of a single process does not affect the entire system.
  • Provides support to big enterprises as well as small teams.
  • Can be deployed independently and in relatively less time.

11. Why Would You Need Reports and Dashboards in Microservices?

Reports and dashboards are mainly used to monitor and upkeep microservices. There are multiple tools that help to serve this purpose. Reports and dashboards can be used to:

  • Find out which microservices expose what resources.
  • Find out the services which are impacted whenever changes in a component occur.
  • Provide an easy point which can be accessed whenever documentation is required.
  • Versions of the components which are deployed.
  • To obtain a sense of maturity and compliance from the components.

12. Why Do People Hesitate to Use Microservices?

I have seen many devs fumble over this question. After all, they’re getting asked this question when interviewing for a microservices architect role, so acknowledging its cons can be a little tricky. Here are some good answers:

  • They require heavy investment – Microservices demand a great deal of collaboration. Since your teams are working independently, they should be able to synchronize well at all times.
  • They need heavy architecture set up – The system is distributed, the architecture is heavily involved.
  • They need excessive planning for handling operations overhead – You need to be ready for operations overhead if you are planning to use a microservices architecture.
  • They have autonomous staff selection – Skilled professionals are needed who can support microservices that are distributed heterogeneously.

13. How Does PACT Work?

PACT is an open source tool. It helps in testing the interactions between consumers and service providers. However, it is not included in the contract, increasing the reliability of the application. The consumer service developer starts by writing a test which defines a mode of interaction with the service provider. The test includes the provider’s state, the request body, and the response that is expected. Based on this, PACT creates a stub against which the test is executed. The output is stored in a JSON file.

14. Define Domain Driven Design

The main focus is on the core domain logic. Complex designs are detected based on the domain’s model. This involves regular collaboration with domain experts to resolve issues related to the domain and improve the model of the application. While answering this microservices interview question, you will also need to mention the core fundamentals of DDD. They are:

  • DDD focuses mostly on domain logic and the domain itself.
  • Complex designs are completely based on the domain’s model.
  • To improve the design of the model and fix any emerging issues, DDD constantly works in collaboration with domain experts.

15. What Are Coupling and Cohesion?

Coupling can be considered to be the measurement of strength between the dependencies of a component. A good microservices application design always consists of low coupling and high cohesion.

Interviewers will often ask about cohesion. It is also another measurement unit. More like a degree to which the elements inside a module remain bonded together.

It is imperative to keep in mind that an important key to designing microservices is a composition of low coupling along with high cohesion. When loosely coupled, a service knows very little about other services. This keeps the services intact. In high cohesion, it becomes possible to keep all the related logic in a service. Otherwise, the services will try to communicate with each other, impacting the overall performance.

16. What Is OAuth?

Open Authorization Protocol, otherwise known as OAuth, helps to access client applications using third-party protocols like Facebook, GitHub, etc., via HTTP. You can also share resources between different sites without the requirement of credentials.

OAuth allows the account information of the end user to be used by a third-party like Facebook while keeping it secure (without using or exposing the user’s password). It acts more like an intermediary on the user’s behalf while providing a token to the server for accessing the required information.

17. Why Do We Need Containers for Microservices?

To manage a microservice-based application, containers are the easiest alternative. It helps the user to individually deploy and develop. You can also use Docker to encapsulate microservices in the image of a container. Without any additional dependencies or effort, microservices can use these elements.

18. What Are the Ways to Access RESTful Microservices?

Another one of the frequently asked microservices interview questions is how to access RESTful microservices? You can do that via two methods:

  • Using a REST template that is load balanced.
  • Using multiple microservices.

19. What Are Some Major Roadblocks for Microservices Testing?

Talking about the cons, here is another one of the microservices interview questions you may be ready for, will be around the challenges faced while testing microservices.

  • Testers should have a thorough understanding of all the inbound and outbound processes before they start writing the test cases for integration testing.
  • When independent teams are working on different functionalities, collaboration can prove to be quite a struggling task. It can be tough to find an idle time-window to perform a complete round of regression testing.
  • With an increasing number of microservices, the complexity of the system also increases.
  • During the transition from monolithic architecture, testers must ensure that there is no disruption between the internal communication among the components.

20. Common Mistakes Made While Transitioning to Microservices

Not only on development, but mistakes also often occur on the process side. And any experienced interviewer will have this in the queue for microservices interview questions. Some of the common mistakes are:

  • Often the developer fails to outline the current challenges.
  • Rewriting the programs that are already existing.
  • Responsibilities, timeline, and boundaries not clearly defined.
  • Failing to implement and figure out the scope of automation from the very beginning.

21. What Are the Fundamentals of Microservices Design?

This is probably one of the most frequently asked microservices interview questions. Here is what you need to keep in mind while answering to it:

  • Define a scope.
  • Combine loose coupling with high cohesion.
  • Create a unique service which will act as an identifying source, much like a unique key in a database table.
  • Creating the correct API and taking special care during integration.
  • Restrict access to data and limit it to the required level.
  • Maintain a smooth flow between requests and response.
  • Automate most processes to reduce time complexity.
  • Keep the number of tables to a minimum level to reduce space complexity.
  • Monitor the architecture constantly and fix any flaw when detected.
  • Data stores should be separated for each microservice.
  • For each microservice, there should be an isolated build.
  • Deploy microservices into containers.
  • Servers should be treated as stateless.

You can also follow this article explaining 9 Fundamentals to a Successful Microservice Design.

22. Where Do We Use WebMVC Test Annotation?

WebMvcTest is used for unit testing Spring MVC applications. As the name suggests, it focuses entirely on Spring MVC components. For example,
@WebMvcTest(value = ToTestController.class, secure = false):
Here, the objective is to only launch ToTestController. Until the unit test has been executed, other mappings and controllers will not be launched.

23. What Do You Mean by Bounded Context?

A central pattern is usually seen in domain driven design. Bounded context is the main focus of the strategic design section of DDD. It is all about dealing with large teams and models. DDD works with large models by disintegrating them into multiple bounded contexts. While it does that, it also explains the relationship between them explicitly.

24. What Are the Different Types of Two-Factor Authentication?

There are three types of credentials required for performing two-factor authentication.

1.     A thing that you know – like password or pin or screen lock pattern.

2.     A physical credential that you have – like OTP or phone or an ATM card, in other words, any kind of credential that you have in an external or third-party device.

3.     Your physical identity – like voice authentication or biometric security, like a fingerprint or eye scanner.

25. What Is a Client Certificate?

This is a type of digital certificate usually used by client systems for making a request that is authenticated by a remote server. It plays an important role in authentication designs that are mutual and provides strong assurance of the identity of a requester. However, you should have a fully configured backend service for authenticating your client certificate.

26. What Is Conway’s Law?

Conway’s Law states, “organizations which design systems … are constrained to produce designs which are copies of the communication structures of these organizations.”

The interviewer may ask a counter microservices interview question, like how is Conway’s Law related to microservices. Well, some loosely coupled APIs form the architecture of microservices. The structure is well suited to how a small team is implementing components which are autonomous. This architecture makes an organization much more flexible in restructuring its work process.

27. How to Configure Spring Boot Application Logging?

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

logging.level.spring.framework=Debug

28. How Would You Perform Security Testing on Microservices?

Before answering this microservices interview question, explain to the interviewer that microservices cannot be tested as a whole. You will need to test the pieces independently. There are three common procedures:

·         Code scanning – To ensure that any line of code is bug-free and can be replicated.

·         Flexibility – The security solution should be flexible so that it can be adjusted as per the requirements of the system.

·         Adaptability – The security protocols should be flexible and updated to cope up with the new threats by hackers or security breaches.

You can also check out this article explaining the influence of Microservices architecture on security.

29. What Is Idempotence and How Is it Used?

Idempotence refers to a scenario where you perform a task repetitively but the end result remains constant or similar.

Idempotence is mostly used as a data source or a remote service in a way that when it receives more than one set of instructions, it processes only one set of instructions.