Did you know? Research improves critical thinking skills.

SPRING BOOT + MICROSERVICES (DEEP)

Spring Boot + Microservices Interview Questions

Microservices Basics

1. What is Microservices?

Microservices is an architecture where application is divided into small independent services communicating via REST or messaging.

2. Monolithic vs Microservices

MonolithicMicroservices
Single applicationMultiple small services
Single deploymentIndependent deployment
Tightly coupledLoosely coupled

3. Advantages of Microservices

  • Independent scaling
  • Fault isolation
  • Technology flexibility
  • Fast deployment

Service Discovery

4. What is Eureka Server?

Eureka is a service registry where microservices register themselves.

5. Register Client with Eureka

@EnableEurekaClient @SpringBootApplication public class OrderServiceApp { public static void main(String[] args){ SpringApplication.run(OrderServiceApp.class,args); } }

6. Why Service Discovery?

Helps dynamic location of services instead of hard-coded URLs.


API Gateway

7. What is API Gateway?

Single entry point for all microservices.

8. Spring Cloud Gateway Example

spring: cloud: gateway: routes: - id: order-service uri: http://localhost:8081 predicates: - Path=/order/**

9. Benefits of API Gateway

  • Centralized routing
  • Security
  • Logging
  • Rate limiting

Load Balancing

10. What is Load Balancer?

Distributes traffic among multiple instances.

11. Spring Cloud LoadBalancer

@LoadBalanced @Bean public RestTemplate restTemplate(){ return new RestTemplate(); }

Inter-Service Communication

12. RestTemplate vs WebClient

RestTemplateWebClient
SynchronousAsynchronous
BlockingNon-blocking

13. Feign Client

@FeignClient(name="user-service") public interface UserClient{ @GetMapping("/users/{id}") User getUser(@PathVariable int id); }

Centralized Configuration

14. Config Server

Externalizes configuration from microservices.

15. Config Server Setup

@EnableConfigServer @SpringBootApplication public class ConfigServerApp { }

Fault Tolerance

16. Circuit Breaker

Prevents cascading failure.

17. Resilience4j Example

@CircuitBreaker(name="orderService", fallbackMethod="fallback") public String callService(){ return restTemplate.getForObject(url,String.class); } public String fallback(Exception e){ return "Service down"; }

Security

18. OAuth2 & JWT

Used for authentication and authorization.

19. JWT Flow

  1. User logs in
  2. JWT generated
  3. Client sends token with request
  4. Service validates token

Distributed Tracing

20. Sleuth & Zipkin

Track request across multiple services.

21. Trace Example

Request ID is passed to all services.


Monitoring

22. Actuator

/actuator/health /actuator/metrics

23. Prometheus & Grafana

Used for metrics visualization.


Messaging

24. Kafka vs RabbitMQ

KafkaRabbitMQ
High throughputMessage broker
Stream processingQueue based

25. Kafka Producer Example

kafkaTemplate.send("topic","Hello Message");

Deployment

26. Docker in Microservices

Each service runs inside container.

27. Dockerfile Example

FROM openjdk:17 COPY target/app.jar app.jar ENTRYPOINT ["java","-jar","app.jar"]

28. Kubernetes

Used for container orchestration.


Best Practices

29. Database per Service

Each microservice should have its own database.

30. Stateless Services

Services should not store session state.



Source: sureshtechlabs.com


Share this post:

WhatsApp Facebook Twitter Telegram