Becoming skilled in Spring Boot and Microservices is key to building scalable and efficient applications. Spring Boot is a powerful framework that makes Java development easier, while Microservices architecture allows you to create and manage complex systems by breaking them down into smaller, independent services.
Here is some Most Asked Spring Boot and Microservices Interview Questions you Must Prepare
What are the advantages of microservices?
Microservices are easily communicated with different databases, programming languages, technologies, and other frameworks.
It reduces the deployment time and based on their services, they can be individually deployed in any application.
If any issue with any microservice it does not shut down entire system and still continues the function.
Microservices communicate different languages and technologies can be used to build different services of the same application.
What is Spring cloud?
Spring Cloud provides tools for developers to quickly build some of the common patterns in distributed systems or Microservices projects(eg: configuration management, intelligent routing)
Spring Cloud is a system in Microservices that integrates external systems, It allows microservices framework to build applications which perform restricted amounts of data processing.
What are the features of microservices?
Microservices are treated as independent components that can be easily replaced and upgraded
Services within a system are largely decoupled. So the application as a whole can be easily built, altered, and scaled
Developers and teams can work independently of each other, thus increasing speed
Allows frequent releases of software, through systematic automation of software creation, testing, and approval
Microservices are very simple and focus on a single capability
The focus is on using the right tool for the right job. That means there is no standardized pattern or any technology pattern. Developers have the freedom to choose the best useful tools to solve their problems
Microservices do not focus on applications as projects. Instead, they treat applications as products for which they are responsible
Microservices support agile development. Any new feature can be quickly developed and discarded again
It offers decentralized data management, DevOps implementation, technical independence, service distribution based on business capabilities, hidden component complexity, and multiple, individually deployable components.
What are the advantages of using Spring Boot for microservices?
It automatically configures various components based on classpath dependencies, reducing the need for manual configuration.
Spring Boot provides a range of features and defaults, reducing the amount of code and configuration required to develop microservices.
Spring Boot integrates well with cloud platforms and provides support for building cloud-native microservices.
Spring Boot includes embedded servers like Tomcat, Jetty, or Undertow, making it easy to deploy microservices as standalone JAR files.
How does microservice architecture works?
Mainly microservice architecture works client, Api gateway, services and database process.
The following various steps used for microservices
Clients – Different users from various devices send requests.
Identity Providers – Authenticates user or clients identities and issues security tokens.
API Gateway – Handles client requests.
Static Content – Houses all the content of the system.
Management – Balances services on nodes and identifies failures.
Service Discovery – A guide to find the route of communication between microservices.
Content Delivery Networks – Distributed network of proxy servers and their data centers.
Remote Service – Enables the remote access information that resides on a network of IT devices.
Explain monolithic architecture?
All software components of an application are inside a single instance/package/unit is known as monolithic architecture in other words Monolithic architecture is a traditional way of making software, in which all of an application’s parts and functions are tightly tied together and packaged as a single unit.
What are the characteristics of monolithic architecture?
Single Codebase: The entire application is developed and maintained within a single code repository.
Tight Coupling : Components and modules within the application are tightly interconnected, making it difficult to modify or replace individual parts without impacting the entire system.
Scalability Challenges : Scaling a monolithic application can be challenging as all components need to be scaled together, even if only a specific part requires more resources.
Monolithic Deployment : The application is deployed as a whole, which can lead to longer deployment cycles and increased downtime during updates.
Technology Stack : Monolithic applications often use a uniform technology stack for the entire system.
Development and Testing : The development and testing of monolithic applications can become complex and time-consuming as the codebase grows.
Failure Impact : A failure in one component can potentially bring down the entire application.
What is load balancing in Spring Cloud?
It improves workload distribution across multiple computing resources. It aims to maximize throughput, optimize resource use, avoid overloading a single resource and minimize response time.
What are the main components of microservices?
Core Services
Components- Clients
Identity Providers
Containers and Clustering
IAC(Infrastrucre as code conception)
Service registry
API Gateway
Security delivery
Message bus
Monitoring and logging
Service discovery and load balancing
Continuous integration and continuous deployment (CI/CD)
What are the problems solved by Spring Cloud?
The complexity associated with distributed systems
Solved redundancy issues
Ability to handle Service Discovery
Reduces performance issues
Load balancing
What is the purpose of an API gateway in microservices?
The general purpose of API gateway is handles the client requests.
It is a combine multiple backend microservices responses into a single response to fulfill client request.
API gateway translate client request from one protocol to another protocol used by underlying microservices.
According to load balance the gateway distributes incoming request across multiple instances of the same microservice to ensure optimal resource utilization and high availability
It improves the performance for cache responses and reduces redundant requests
API gateway handle authentication and authorization for security.
An API gateway is a single entry point for all incoming requests to the microservices. It acts as a reverse proxy, routing requests to the appropriate service and handling tasks such as authentication and rate limiting.
What is End to End Microservices Testing?
End-to-end testing validates every process in the workflow is functioning properly. This ensures that the system works together as a whole and satisfies all requirements.
What is ‘dumb pipe’ in microservices?
Dumb pipes is no further actions can be taken place in this communication. It just carries the data across a channel, and it is replaceable. The infrastructure of dumb is it can only act as a message router, and it has no other functions.
What are the difference between SOA(Service oriented architecture) and Microservices architecture?
SOA is monolithic architecture, whereas Microservices is full-stack.
SOA involves sharing data storage between services, while in Microservices, each service can have independent data storage.
SOA is a less scalable architecture, while Microservices is a highly scalable architecture.
SOA focuses on application service reusability, while Microservices focus more on decoupling.
What are the advantages of microservices?
We have various types of microservices tools in market but the following tools are mostly used:
Spring boot, Docker, Kubernetes, postman, Prometheus, and AWS cloudwatch etc.
What are the characteristics of microservices?
There are six main characteristics of microservices architecture
multiple components
business approach
simple routing
decentralized
failure resistant
evolutionary.
Some more characteristics of microservices.
Organized on business capabilities
Essential messaging frameworks
Decentralized Governance
Infrastructure Automation
Decentralized data management
What is the difference between microservcies and monolithic architecture?
Monolithic Architecture is similar to a big container where all the software components of an application are assembled together and tightly coupled where as Microservice Architecture that structures an application as a collection of small autonomous services, modeled around a business domain and it is loosely coupled.
In microservices when changes done in single model it does not affect other microservices but any changes in the data model affect the entire database in monolithic.
Microservices service starts fast compare to monolithic
Microservices mainly focused on products but not projects, In Monolithic put emphasize over the whole project.
What is cohesion?
Cohesion means connection between two or more elements of module that have same function. A module with strong cohesion it effectively execute a given function without require any connection with other modules. This enhances high cohesiveness functionality.
Write securing communication between microservices?
The following some securing communication between microservcies
UPI gateways
Service mesh
API security
Transport layer security
Secure service to service communication
What are client certificates?
A type of digital certificate that is used by client systems to make authenticated requests to a remote server.It plays a vital role in many mutual authentication designs, providing strong assurances of a requester’s identity.
How microservices handle security and authentication?
Through various mechanisms of microservices is protection of sensitive data and unauthorized access
In real time microservices handle security and authentication in API gateway, secure mesh, TLS and Role based access control.
What are the benefits of using kubernates for microservices?
Kubernetes simplifies the deployment and management of containers. It handles scaling, load balancing, and self-healing.
Kubernetes supports multiple replicas of services, ensuring high availability and fault tolerance.
Kubernetes can automatically scale services based on CPU utilization or custom metrics to optimize resource usage.
Kubernetes provides built-in service discovery and DNS resolution for communication between services.
What is coupling?
The measure of the strength of the dependencies between components is said to be coupling. A good design is always said to have High Cohesion and Low Coupling.
Coupling is a relationship between software modules as well as how dependent or interdependent one module is on other.
We have three coupling groups
Very connected module or high reliant
Uncoupled module
Weekly coupled module
What are different types of Tests for Microservices?
According to microservices architecture tests are divided into three categories
The first test is the bottom level test that performs general test like unit and performance tests.
At the middle level, experimental tests like usability and stress tests are there.
Moreover, at the top level, acceptance testing takes place. Tests at all levels are automated.
What are service registration and discovery in microservices spring cloud?
If any Manuel deploy service are increased for adding or configuration modify are more complex and it create issues after service goes down. So these types of issues are handled by eureka service register and discover.
Service registration and discovery is a mechanism that allows microservices to register themselves with a service registry and discover other services. Service registries maintain a registry of available services, including their network locations and metadata. Service discovery clients can query the registry to obtain the necessary information to communicate with other services.
Service registration: When a microservice starts up, it registers itself with a service registry (e.g., Consul, Eureka) by providing essential information like its network location, API endpoints, and health status.
Service discovery: When a microservice needs to communicate with another microservice, it queries the service registry to discover the network location and endpoint details of the target service.
This dynamic discovery allows microservices to locate and interact with each other without hardcoding their locations or relying on static configurations. As new instances of services are deployed or removed, the service registry is updated accordingly. This ensures seamless communication within the containerized environment.
What is circuit breaking in microservices and how is it implemented in Spring Boot?
Circuit breaking implements circuit-breaking patterns to prevent cascading failures and avoid overloading unhealthy services in other words it is a design pattern used to handle and prevent cascading failures in microservice architectures. It involves monitoring the calls to external services and, if a certain threshold of failures is reached, tripping a circuit breaker to stop further requests and return a fallback response.
In Spring Boot, circuit breaking can be implemented using libraries like Netflix Hystrix or Resilience4j, which provide annotations and configuration options to define circuit breakers and fallback behaviors.
What is spring webFlux?
Spring WebFlux is a reactive, non-blocking web framework for building modern, scalable web applications in Java.
What is Spring Cloud OpenFeign?
Feign is a declarative web service client. It makes writing web service clients easier.
To use Feign create an interface and annotate it. It has pluggable annotation support including Feign annotations and JAX-RS annotations.
Feign also supports pluggable encoders and decoders. Spring Cloud adds support for Spring MVC annotations and for using the same HttpMessageConverters used by default in Spring Web.
Spring Cloud integrates Eureka, as well as Spring Cloud LoadBalancer to provide a load-balanced HTTP client when using Feign.
How to Enable Feign Client using @EnableFeignClients?
First, we need to enable feign client inside the application by using '@EnableFeignClients' annotation in the main class.
Example:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableFeignClients
public class NITApplication {
public static void main(String[] args) {
SpringApplication.run(NITApplication.class, args);
}
}
Scope @ NareshIT:
NareshIT’s Spring Boot and Microservices Online Training program offers in-depth, practical experience in modern backend development, giving you the skills needed to build scalable, cloud-based applications.
Becoming a proficient Spring Boot and Microservices developer requires a deep understanding of how these technologies empower the creation of scalable, efficient, and modular applications. Spring Boot serves as a robust framework for simplifying Java development, while Microservices architecture allows for building and managing complex systems as a collection of independent, loosely-coupled services.
Why Invest in Spring Boot and Microservices?
By mastering Spring Boot and Microservices, you’ll not only gain a solid foundation in modern Java application development but also position yourself as a key player in any team, capable of delivering cutting-edge solutions that drive business success.
Here are some Top 30+ Spring Boot and Microservices Interview Questions for Freshers:
What is Spring Boot?
Spring boot is a java based Spring framework to make it easy to develop stand-alone(build micro services) application. Most of the spring boot applications need minimal configuration. It has auto-configuration and embedded application server support like tomcat, jetty, etc.
How Spring boot differ from Spring?
Spring frame work contains manual configuration but Spring boot having auto-configuration and Spring requires external server/container where as Spring boot having Stand-alone application with embedded server.
Spring boot having In-memory database where as Spring requires external database.
What are the advantages of Spring Boot?
It requires minimum configuration.
Easy to understand and develop spring application
It increases productivity and reduce development time.
It offers an easy way to create Spring-based applications using Java or Groovy.
Avoid complex XML configurations and only a few annotations are required to do the configuration.
What are the features of Spring Boot?
Create stand-alone using Spring applications
Provide opinionated 'starter' dependencies to simplify your build configuration
No need to required WAR file to deploy application into Embed Tomcat, Jetty.
Automatically configure Spring and 3rd party libraries whenever possible
Provide production-ready features such as metrics, health checks, and externalized configuration
Absolutely no code generation and no requirement for XML configuration
What are the Key components of Spring Boot?
auto-configuration.
starter POMs.
CLI.
Actuators.
What are the Spring Boot Annotations?
Some Important Spring boot Annotations
@Conditional
@EnableAutoConfiguration
@SpringBootApplication
@AutoConfiguration
@EnableCaching
What is Spring Initializr?
Spring Initializr is used to create new or skeleton of Spring Boot project or application
Steps to create Spring project using Spring Initializr
Go to https://start.spring.io and launch Spring Initializr.
choose a dependency management tool (either Maven or Gradle), a language (Java, Kotlin or Groovy), a packaging scheme (Jar or War), version and dependencies
Once all of the details are entered, select the Generate Project button to generate and download a Spring Boot project. Following that, unzip the downloaded zip file and transfer it into your preferred IDE.
Next open Eclipse and import the file.
Select File -> Import -> Existing Maven Project in Eclipse. On the next page, navigate to or type in the path to the folder where you extracted the zip file. Maven will take some time to download all the dependencies and initialize the project after you select Finish.
What are the properties of Spring Boot?
Spring Boot provides various properties that can be configured in the application.properties file and it contains default values.
Spring Boot has many properties that can be used to configure the behavior of the application and commonly commonly used properties in Spring Boot include spring.datasource.url, server.port, spring.profiles.active etc.
How to disable Specific Auto-Configuration?
By using @EnableAutoConfiguration(exclude = .class file) annotation to disable Auto-Configuration.
For example we create a class named as SpringTestApplication, so the following annotation to disable Specific Auto-Configuration.
@EnableAutoConfiguration(exclude = SpringTestApplication.class).
How does spring boot work?
Spring boot works automatic configuration of your application based on dependencies, based on development need to add specific annotations. Spring boot contains mainly @SpringBootApplication annotation and main method to run application.
By using @ Configuration annotation which calls all the beans in the classpath and initializes those classes.
What is thyme leaf?
Thyme leaf is a popular templating engine used in Spring Boot applications for build dynamic web pages. Moreover, it is humanly readable and developers can use it to create templates that can be rendered in HTML.
What are the Spring boot Starters are available?
Mostly used Spring boot starters
spring-boot-starter: core starter, including auto-configuration support, logging and YAML
spring-boot-starter-aop: for aspect-oriented programming with Spring AOP and AspectJ
spring-boot-starter-data-jpa: for using Spring Data JPA with Hibernate
spring-boot-starter-security: for using Spring Security
spring-boot-starter-test: for testing Spring Boot applications
spring-boot-starter-web: for building web, including RESTful, applications using Spring MVC
What is the starter dependency of the Spring boot module?
Mostly used Spring boot starter dependencies are
Security starter.
Data JPA starter.
Web starter.
Test Starter.
Mail starter.
Thymeleaf starter
How to use thyme leaf?
In implementation we use Thymeleaf in a Spring Boot application you should include the thymeleaf-spring-boot-starter dependency in POM.xml file of your project.
The following dependency add to your project to implement Thymeleaf.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
How @SpringBootApplication annotation works internally?
The @SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration, and @ComponentScan with their default attributes. Spring Boot enables the developer to use a single annotation instead of using multiple.
@SpringBootApplication = @Configuration + @EnableAutoConfiguration + @ComponentScan
What is @RestController annotation in Spring Boot?
@RestController is a Spring Boot annotation and it is a combination of @Controller and @ResponseBody, used to create RESTful web services. It converts the response to JSON or XML.
What are the key dependencies of Spring Boot?
Most impotant key dependencies are
spring-boot-maven-plugin
spring-boot-starter-test
spring-boot-starter-parent
Spring-boot-starter-web
spring-boot-starter-security
spring-boot-starter-actuator
What is the difference between @RestController and @Controller in Spring Boot?
@Controller class is uesed to Map of the model object to view or template and make it readable format but @RestController simply returns the object and object data is directly written in HTTP response as JSON or XML.
What is Spring Actuator?
Spring actuator is an additional feature of Spring that helps you to monitor and manage your application when you push it to production.
How to enable Actuator in Spring boot application?
By using spring-boot-starter-actuator dependency in pom.xml to enable actuator in Spring boot application.
<dependency>
<groupId> org.springframework.boot</groupId>
<artifactId> spring-boot-starter-actuator </artifactId>
</dependency>
How to Change the Default Port in Spring Boot?
There are many ways to change default port in spring boot
Using a properties file – We can define this in an application.properties (or application.yml) file using the property server.port.
Programmatically – In our main @SpringBootApplication class, we can set the server.port on the SpringApplication instance.
Using the command line – When running the application as a jar file, we can set the server.port as a java command argument.
List what are the advantages and ways to load the YAML file instead of the properties file in the Spring Boot application.
YAML is an acronym for “YAML Ain’t Markup language” and has the following properties:
Human-friendly, provide more clarity
Suitable for hierarchical data configuration
Support for enhancing maps, lists, and scalar types.
There are two classes from the spring framework that extend YamlProcessor,
that are used to load YAML documents.
YamlPropertiesFactoryBean class can load YAML as properties.
YamlMapFactoryBean class will load YAML as Map
What are the Difference between RequestMapping and GetMapping?
RequestMapping used to configure base path and not for any further levels. @GetMapping is used to overcome drawbacks of @RequestMapping.
@RequestMapping is class level annotation wher as @GetMapping uses get mapping annotation rather than requestmapping.
What are actuator enpoints?
Actuator endpoints allow developers to monitor and interact with the application. There are built-in endpoints already available as well as one can create customized endpoints. We can enable or disable these endpoints as per our needs.
What is List actuator provided endpoints for monitoring Spring boot application?
The list of Actuator endpoints for Spring Boot are:
Beans
Configprops
Health
Httptrace
Heapdump
Threaddump
Mapping
Info
Shutdown
How to enable debugging log in spring boot application?
Spring boot enable debug logging feature will display useful information related to Spring boot container initialization on a console, and check which beans have been created using which configuration.
The following are the options to enable logging in Spring boot application.
Set debug=true or trace=true in application.properties
OR
Set debug=true in application.yml file
OR
pass parameter java -jar demo.jar –debug before starting the application using jar command.
What are the steps to deploy the Spring Boot application as a WAR?
Step 1: Add plugin in pom.xml as follows
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
Step 2: The packaging element in pom.xml must be set to war to build a WAR file as
<packaging>war</packaging>
What are the steps to deploy the Spring Boot application as a JAR?
Step 1: Add plugin in pom.xml as follows
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
Step 2: The packaging element in pom.xml must be set to jar to build a JAR file as
<packaging>jar</packaging>
What is a shutdown in the actuator?
A shutdown is an endpoint that helps application to be shut down properly. This feature is not enabled by default.
However, you can use it by setting command: management.endpoint.shutdown.enabled=true in your application.properties file.
How do you Add filter to an application?
There are three ways to add filter to Spring Boot application:
Using FilterRegistrationBean.
By implementing Filter interface.
Using MVC controller.
What is @pathVariable?
@PathVariable annotation helps you to extract information from the URI directly.By defining placeholders in the request mapping URL, you can bind those placeholders to method parameters annotated with @PathVariable.
Example:
@RestController
@RequestMapping("/students")
public class NIT {
@GetMapping("/{studentId}")
public ResponseEntity<User> getStudentDetails(@PathVariable Long studentId) {
return ResponseEntity.ok(student);
}
}
What is @RequestParam?
@RequestParam annotation enables you to extract data from the query parameters in the request URL.
Example:
@RestController
@RequestMapping("/students")
public class NIT {
@GetMapping("/search")
public ResponseEntity<List<Student>> searchUsers(@RequestParam("name") String name) {
return ResponseEntity.ok(students);
}
}
What is the difference between @PathVariable and @RequestParam?
@RequestParam is used to capture query parameters or form parameters from the URL, while @PathVariable is used to capture values from the URL path.
What is MicroServices?
Microservice is a architecture is approach to software development application divided into small independent services that communicate with other well defined APIs.
Microservices architectures make applications easier to scale and faster to develop, enabling innovation and accelerating time-to-market for new features.
Microservice architecture is provides loosely coupled services that can be independently deployed and maintenance.
Scope @ NareshIT:
NareshIT's Spring Boot and Microservices Online Training program delivers comprehensive, hands-on experience in modern backend technologies, equipping you with the expertise to develop scalable, cloud-native applications.
Practical Projects: Immerse yourself in real-world applications through phase-end and capstone projects, where you’ll design and deploy microservices architectures, gaining valuable, real-time development experience.
Industry-Expert Instructors: Benefit from the knowledge of experienced professionals, with a curriculum that reflects the most current trends and best practices in Spring Boot and Microservices.
End-to-End Learning: The program offers a deep dive into microservices development, covering everything from conceptual design to deployment using Spring Boot, ensuring you’re well-prepared to build robust, scalable applications.
Certification of Achievement: Upon completing the course, you'll receive a prestigious industry-recognized certificate, affirming your skills and proficiency in Spring Boot and Microservices development.