In this article, I have collected top 10 spring boot microservices interview questions and their answers frequently asked by interviewers. If you want to learn more about microservice architecture with spring boot, you could follow my previous article create microservices application using spring boot.
Microservices Interview Questions
- What is Spring Boot?
- What is a microservices architecture?
- What are the advantages and disadvantages of microservices?
- What is Spring Cloud?
- Spring Cloud annotations and configuration?
- What Netflix projects did we use?
- How do you setup Service Discovery?
- How do you access a RESTful microservice?
- What is Eureka?
1. What is Spring Boot?
Spring Boot is a way to ease to create stand-alone application with minimal or zero configurations. It is approach to develop spring based application with very less configuration. It provides defaults for code and annotation configuration to quick start new spring projects within no time. It leverages existing spring projects as well as Third party projects to develop production ready applications. It provides a set of Starter Pom’s or gradle build files which one can use to add required dependencies and also facilitate auto configuration.
Spring Boot automatically configures required classes depending on the libraries on its classpath. Suppose your application want to interact with DB, if there are Spring Data libraries on class path then it automatically sets up connection to DB along with the Data Source class. For more detail about Spring Boot.
2. What is a microservices architecture?
Microservices architecture allows to avoid monolith application for large system. It provide loose coupling between collaborating processes which running independently in different environments with tight cohesion. For more detail.
3. What are the advantages and disadvantages of microservices?
Microservices Advantages
- Smaller code base is easy to maintain.
- Easy to scale as individual component.
- Technology diversity i.e. we can mix libraries, databases, frameworks etc.
- Fault isolation i.e. a process failure should not bring whole system down.
- Better support for smaller and parallel team.
- Independent deployment
- Deployment time reduce
Microservices Disadvantages
- Difficult to achieve strong consistency across services
- ACID transactions do not span multiple processes.
- Distributed System so hard to debug and trace the issues
- Greater need for end to end testing
- Required cultural changes in across teams like Dev and Ops working together even in same team.
Popular Tutorials
4. What is Spring Cloud?
- It is building blocks for Cloud and Microservices
- It provides microservices infrastructure like provide use services such as Service Discovery, Configuration server and Monitoring.
- It provides several other open source projects like Netflix OSS.
- It provides PaaS like Cloud Foundry, AWS and Heroku.
- It uses Spring Boot style starters
- There are many use-cases supported by Spring Cloud like Cloud Integration, Dynamic Reconfiguration, Service Discovery, Security,Client side Load Balancing etc. But in this post we concentrate on following microservices support
- Service Discovery (How do services find each other?)
- Client-side Load Balancing (How do we decide which service instance to use?)
5. Spring Cloud annotations and configuration?
- @EnableEurekaServer annotation allows us to register microservices to the spring cloud.
- @EnableDiscoveryClient annotation also allows us to query Discovery server to find miroservices.
- Spring provide smart RestTemplate for service discovery and load balancing by using @LoadBalanced annotation with RestTemplate instance.
6. What Netflix projects did we use?
Eureka created by Netflix, it is the Netflix Service Discovery Server and Client. Netflix Ribbon, it provide several algorithm for Client-Side Load Balancing. Spring provide smart RestTemplate for service discovery and load balancing by using @LoadBalanced annotation with RestTemplate instance.
7. How do you setup Service Discovery?
Spring Cloud support several ways to implement service discovery but for this I am going to use Eureka created by Netflix. Spring Cloud provide several annotation to make it use easy and hiding lots of complexity. For more detail click here.
8. How do you access a RESTful microservice?
- Load Balanced RestTemplate
- If there are multiple RestTemplate you get the right one.
- It can used to access multiple microservices
9. What is Eureka?
Eureka is the Netflix Service Discovery Server and Client. Eureka Server is using Spring Cloud.
Registering with Eureka
When a client registers with Eureka, it provides meta-data about itself such as host and port, health indicator URL, home page etc. Eureka receives heartbeat messages from each instance belonging to a service. If the heartbeat fails over a configurable timetable, the instance is normally removed from the registry.
Example eureka client:
@Configuration @ComponentScan @EnableAutoConfiguration @EnableEurekaClient @RestController public class Application { @RequestMapping("/") public String home() { return "Hello world"; } public static void main(String[] args) { new SpringApplicationBuilder(Application.class).web(true).run(args); } }
For full example of microservices with spring boot click here.
Spring Boot Related Topics
- Spring Boot Interview Questions and Answers
- Introduction to Spring Boot
- Essentials and Key Components of Spring Boot
- Spring Boot CLI Installation and Hello World Example
- Spring Boot Initializr Web Interface
- Spring Boot Initializr With IDEs
- Spring Boot Initializr With Spring Boot CLI
- Installing Spring Boot
- Developing your first Spring Boot application
- External Configurations for Spring Boot Applications
- Logging Configuration in Spring Boot
- Spring Boot and Spring MVC
- Working with SQL Databases and Spring Boot
- MySQL Configurations
- Spring Data JPA using Spring Boot Application
- Spring Boot with NoSQL technologies
- Spring Cache Tutorial
- Spring Security Tutorial with Spring Boot
- Spring Boot and MongoDB in REST Application
- Complete Guide for Spring Boot Actuator
- Microservices with Spring Boot
Full of spelling mistakes and grammar mistakes. Not good
Send me the latest Articles in Spring
eureka client example helped me a lot.