Microservices Interview Questions and Answers 2023

Microservices Interview Questions and Answers

We cannot deny the importance of Microservices in the current market scenario and there are good reasons for this. Microservices are providing faster software, more innovation, better software at a low cost. Therefore more and more software engineers are trying to make a career in Microservices. Here in this article, we have listed frequently asked Microservices interview questions.

We have divided the Microservices interview questions into the below sections:

 

Basic Microservices Interview Questions

  1. What do you understand by Microservices?
  2. What are the advantages of Microservices?
  3. Explain the architecture of Microservices
  4. Explain the important features of Microservices
  5. What are the common challenges during Microservices implementation?
  6. Name and explain various popular tools used for creating Microservices architecture

 

Concepts Microservices Interview Questions

  1. Explain the differences between Microservices, Monolithic, and SOA.
  2. What are Coupling and Cohesion in Microservices?

 

Spring Boot Microservices Interview Questions

  1. What do you know about Spring Boot?
  2. What is Spring Cloud in Microservices?
  3. How to implement Spring Security into a Spring Boot application?
  4. How to perform exception handling in Microservices?

 

Security Microservices Interview Questions

  1. What is the Open Authorisation Protocol?

 

API Microservices Interview Questions

  1. Why use RESTful API in Microservices?
  2. What is Idempotence in Microservices?

 

Basic Microservices Interview Questions

 

1. What do you understand by Microservices?

Microservices is an architecture and approach where many small services constitute a large and complex application.  One service has a single and precise functionality to perform equipped with a defined interface to interact with other services. These small services can be independently deployed, maintained, tested, and are scalable. A single small service/ module/ process is a microservice.

 

The Microservices architecture is built around a business domain where the services communicate with each other. Different teams have ownership of different services/ modules.


Explore the Job Openings in APAC

 

2. What are the advantages of Microservices?

  • Independently deployable small services
  • Independently developed small services
  • The use of different technologies results in technology flexibility
  • Scaling of single service as per need provides independent scalability
  • Faster deployment of small modules results in faster delivery
  • Easy to understand small modules
  • Easier maintenance of individual services
  • Lightweight messaging makes data communication and coordination between modules easy. E.g. REST API
  • If one of the services fails in the application other services keep running. The amendment can be made only in the failed service without any impact on the other services hence it provides failure minimisation.

 

3. Explain the architecture of Microservices

The Microservices architecture has the below four main components:

 

  • API layer: This layer is the entry of all types of requests from clients. This layer enables the services to interact with each other through HTTP, TCP UDP protocols.
  • Logic layer: The logic of the application is present in this layer to provide resolution of the business requirement. It can be written in different programming languages for different microservices.
  • Database layer: Each microservice has its own database storage.
  • Container orchestration: To maintain the Microservices as separate entities they are run in their own containers.

 

Architecture of Microservices
Image from docs.oracle.com
 

4. Explain the important features of Microservices

  • Loosely coupled: Microservices as independent and connected to each other through messaging systems e.g. REST, HTTP, etc.
  • Reusable: The same microservice can be used for a mobile client, desktop client, another microservice, or some other system leading to reusability.
  • Stateless: Microservices do not maintain or store state. It means that they take a request from the client, process it, and then send the response. However, we can deliberately store a state in case of a ‘stateful microservice’.
  • Lightweight: Microservices are small and use lightweight containers to hold them. Also, for communication, they use lightweight messaging protocols.
  • Polyglot: The logical layer or the programming can be done in any programming language.

 

5. What are the common challenges during Microservices implementation?

  • Diverse technologies: We use different technologies for different Microservices. While maintaining this may cause issues because the team member performing maintenance may not be aware of the technology used.
  • Complex communication: In a Microservice architecture, multiple independent services communicate with each other. Therefore the dependencies are coded into the infrastructure configuration. Hence, the system communication can be very complex to maintain.
  • Testing: Each team focuses on their individual microservice and tests them as a separate entity. Hence, the integration testing of the whole Microservice application is complex and often goes missing.
  • Management: With an increase in the number of Microservices, managing them could be a challenge.
  • Monitoring: In distributed systems like Microservices the root cause of an issue is spanned across multiple Microservices. In such a case, it is challenging to find the root cause of the problem. To find the issue we need proper monitoring and tracking of the request. We need special tools which will help us to understand the dependencies and correlation of services within the whole system.
  • Fault tolerance: It is important to design an application for fault tolerance. To prepare the Microservices for external and internal failures is challenging due to the complex architecture.
  • Migration: The process of migration from monolithic to a microservices-based application requires better planning. Because we will introduce new networks and connections, also the tasks will be broken into smaller modules.
  • Complex operations: A microservice-based application needs testing in several testing environments and then subsequently in production. The recovery, security, and maintenance are challenging for Microservices.

 

6. Name and explain various popular tools used for creating Microservices architecture

  • Operating System: Linux
  • Programming language: Java, Python, Elixir
  • Orchestration: Kubernetes, Swarm
  • API management and testing: Postman, API Fortress, Tyk
  • Messaging: RabbitMQ, Amazon Simple Queue Service (SQS), Apache Kafka
  • Monitoring: Prometheus, Logstash, Graylog
  • Containers: Docker
  • Toolkits: fabric8, Seneca
  • Architectural Framework: goa, Kong
  • Serverless tools: Serverless, Kubeless, AWS Lambda, Claudia


Test your coding skills here

 

Concepts Microservices Interview Questions

 

1. Explain the differences between Microservices, Monolithic, and SOA.

 

Difference between Microservices, SOA, and Monolithic.
Image from velvetech.com
 

Microservices SOA Monolithic
Contains small-sized services. Contains small services and large enterprise applications also. Contains a very huge single application.
Uses a lightweight protocol REST/ API for communication. Uses standard protocol SOAP for communication. No standard protocol.
Services can be scaled independently without affecting other services. Scalability is complex due to dependency between components. Scalability is very complex due to the complex structure of the application.
Developers can develop their services independently in any language based on the requirement of the task. Component reusability helps the developers in the development of applications. The whole application is written using a single framework/ language. Hence selection of the best framework for a particular task is not possible.

 

2. What are Coupling and Cohesion in Microservices?

Microservices has small services serving as individual modules and to communicate with each other they use protocols. In a poor design, they may be excessively dependent on each other with a lot of communication happening between them. Another case could be where the methods of the same module are working in isolation with each other without any communication. We would want to avoid both situations.

 

Cohesion and Coupling
Image from i.stack.imgur.com
 

Coupling: It is the degree to which the modules are dependent, interacting with each other. Hence, coupling works across modules. It can be achieved by designing good interface boundaries.

 

Cohesion: It is the degree to which the methods/ elements of a module serve a common purpose together. Hence, cohesion works within a module.

 

An ideal Microservices architecture will aim for high cohesion and low coupling to achieve below:

  • Related code/methods should be present in the same module.
  • Each module should work independently with minimum required communication between them.

 

Cohesion and Coupling in Microservices
Image from dzone.com


Explore the Job Openings in APAC

 

Spring Boot Microservices Interview Questions

This section contains Spring Boot microservices interview questions together with Spring Cloud, Spring Security, exception handling, and logging.

 

1. What do you know about Spring Boot?

Spring boot is a Java-based, open-source framework which helps in creating production-ready and stand-alone applications. Spring boot applications can be written without the need of setting up the whole Spring configuration. Therefore, Spring Boot is easier to understand, faster to develop, and increases productivity.

 

More about Spring Boot here.

 

2. What is Spring Cloud in Microservices?

It is an open-source module of Spring which helps in quickly developing and deploying the distributed applications on the cloud. Spring Cloud in Microservices provides tools to create patterns for distributed systems rapidly. E.g., service discovery, circuit breakers, configuration management, intelligent routing, etc.

 

More about Spring Cloud here.

 

3. How to implement Spring Security into a Spring Boot application?

To secure the application from unauthorised access we use Spring Security in microservices. To configure  Spring security into an application we add the Spring Security on the classpath. This way Spring Boot will automatically secure all HTTP endpoints with basic security. Spring Security in Microservices can be further changed by making enhancements to the security settings.

 

Step 1: Define dependencies in Maven or Gradle as below:

  • Maven users can define POM dependencies as below in pom.xml.

  • Gradle dependencies are defined as below in the build.gradle file.

 

Step 2: Create a config class which extends WebSecurityConfigurerAdapter and overrides its methods - configure(), userDetailService() etc.

Complete code snippets here.

 

4. How to perform exception handling in Microservices?

In case of an exception in service, we need to properly handle it and return a response to convey details about the exception.

 

ExceptionHandler for Controller based exceptions

It is a Spring annotation which helps us in handling the exceptions thrown during the execution of Controller operations. This can be used on methods of @ControllerAdvice classes to apply an ExceptionHandler on multiple controllers. It can be applied to all the controllers or a subset of them.

 

ResponseEntityExceptionHandler class of Spring

It provides basic exception handling methods, we can override them to provide a more sophisticated error response.

We can create new methods for exception handling using ResponseEntityExceptionHandler as our base class.

 

Security Microservices Interview Questions

 

1. What is the Open Authorisation Protocol?

Open Authorisation Protocol or OAuth is an authorisation protocol which has two versions - OAuth 1.0 and OAuth 2.0. It is an open standard for interacting with protected data on the internet. Through OAuth protocol end-user’s account information is used by third-party applications like Facebook without exposing the user's credentials.

 

OAuth 1.0 works on cryptography and therefore it is difficult to implement by the programmers. OAuth 2.0 is easier to implement but due to the use of HTTP/TLS the security can be compromised. Hence it becomes important to work on security features properly while using OAuth 2.0.

 

Example of OAuth authorisation protocol: Google API’s via OAuth 2.0.


Test your coding skills here

 

API Microservices Interview Questions

 

1. Why use RESTful API in Microservices?

An API(Application Programming Interface) defines the rules, protocols, commands, permissions for the users/applications to access the data or service. In the case of Microservices API define the rules for data sharing, access permissions, and other commands. RESTful API is HTTP based type of API which is widely used in Microservices.

 

RESTful API in Microservices acts as a glue to hold the different services of the application together.

 

RESTful API is used in Microservices because:

  • It provides the means of communication between services.
  • It is a way of accepting some inputs, performing a complex calculation, and returning the result.
  • It is language independent.
  • It is a stateless protocol.
  • Works on CRUD with simple commands:

Create: POST command

Read: GET command

Update: PUT command

Delete: DELETE command

 

2. What is Idempotence in Microservices?

If an action(call) is repeated multiple times and the server state(or result) remains the same after every call then this action is idempotent. It means that after one call or multiple calls we receive the same result.

 

It is important that Microservices must have the idempotence property because there are scenarios where APIs get duplicate requests. In such scenarios, the system should be fault-tolerant and should not give erroneous results.

 

E.g. REST requests- GET, HEAD, OPTIONS, TRACE are idempotent because they do not change the resource state at the server. They are just accessing the existing state/ data.

 

REST request POST is NOT idempotent, because every time we POST a request we are making changes in the server state by adding new resources. Hence, the result of every POST request will differ.

 

Microservices is used by most of the technology and social media giants today. A career in microservices can be really rewarding and therefore we have compiled the most frequently asked questions for easy preparation. Here we conclude the article and hope that you find it helpful in preparing for microservices interviews.

 

Other Backend Technology Interview Questions and Answers

C Programming Language Interview Questions | PHP Interview Questions | .NET Core Interview Questions | NumPy Interview Questions | API Interview Questions | FastAPI Python Web Framework | Java Exception Handling Interview Questions | OOPs Interview Questions and Answers | Java Collections Interview Questions | System Design Interview Questions | Data Structure Concepts | Node.js Interview Questions | Django Interview Questions | React Interview Questions | Key Backend Development Skills | Data Science Interview Questions | Python Interview Questions | Java Spring Framework Interview Questions | Spring Boot Interview Questions.

Related Articles

HACKERBUCK AWARDED