![]() |
VOOZH | about |
Spring Cloud interview questions are commonly asked to check your understanding of microservices architecture and how Spring-based services communicate in a distributed system. They mainly focus on service discovery, API Gateway, load balancing, centralized configuration, and fault tolerance using popular Spring Cloud components.
Spring Cloud is a set of tools and frameworks used to build microservice-based applications in Spring Boot. It provides ready-made solutions for common distributed system problems like service discovery, configuration management, load balancing, and fault tolerance.
We use Spring Cloud in microservices because it provides built-in solutions for common problems that occur in distributed systems, like service discovery, load balancing, centralized configuration, and fault tolerance. It makes microservices communication easier and more reliable.
Service Discovery is a mechanism where microservices can find and communicate with each other automatically without hardcoding IP addresses or ports. In Spring Cloud, this is commonly done using Eureka Server, where services register themselves and other services discover them.
Eureka Server is a service registry in Spring Cloud where all microservices register themselves so that other services can discover them easily. It acts like a central directory that stores service names and their running instances (IP + port).
Eureka Client is a microservice that registers itself with the Eureka Server and also discovers other services from the registry. It sends heartbeat signals to the server so the registry knows the service is running.
Spring Cloud Gateway is an API Gateway used in microservices to route client requests to the correct backend service. It acts as a single entry point and also provides features like filtering, security, logging, and load balancing.
We need an API Gateway because it works as a single entry point for all microservices, so clients donβt need to directly call multiple services. It simplifies communication and handles common features like routing, security, and monitoring in one place.
Load Balancing in Spring Cloud means distributing incoming requests across multiple instances of the same microservice to improve performance, scalability, and availability. Spring Cloud uses Spring Cloud LoadBalancer (earlier Ribbon was used) to automatically pick a healthy service instance.
OpenFeign is a declarative REST client in Spring Cloud used for calling other microservices easily. Instead of writing RestTemplate or WebClient code, you just create an interface and Spring Cloud automatically generates the REST call implementation.
RestTemplate is a traditional way to call REST APIs where you manually write the request code. Feign Client is a declarative REST client where you only define an interface, and Spring Cloud handles the implementation automatically.
| Feature | RestTemplate | Feign Client |
|---|---|---|
| Type | Manual REST client | Declarative REST client |
| Code | More boilerplate | Less code (interface-based) |
| Integration | Limited | Best with Eureka + LoadBalancer |
| Readability | Medium | High |
| Microservices usage | Older approach | Modern and preferred approach |
Spring Cloud Config Server is used to manage centralized configuration for all microservices in one place. Instead of keeping separate application.properties files in every service, configs are stored in a Git repository (or other storage) and fetched dynamically.
Spring Cloud Config Client is a microservice that connects to the Config Server and fetches its configuration from the centralized repository at startup. This allows all services to use shared and external configuration instead of keeping properties locally.
Centralized configuration means keeping all microservices configuration in one common place (like Spring Cloud Config Server + Git). It makes managing and updating properties easier across multiple services.
Circuit Breaker is a fault-tolerance pattern used in microservices to prevent system failure when one service is down or responding slowly. In Spring Cloud, Circuit Breaker is commonly implemented using Resilience4j, which stops calling the failing service temporarily and returns a fallback response.
Hystrix was an older Netflix library used for circuit breaker in microservices, but it is now discontinued. Resilience4j is the modern alternative used in Spring Cloud for fault tolerance and resilience patterns.
| Feature | Hystrix | Resilience4j |
|---|---|---|
| Status | Discontinued | Actively maintained |
| Type | Netflix library | Lightweight Java 8 library |
| Integration | Older Spring Cloud | Best supported in new Spring Cloud |
| Features | Circuit breaker + fallback | Circuit breaker, retry, rate limiter, bulkhead, timeout |
| Performance | Heavier | Lightweight and modular |
A fallback method is an alternative method that gets executed when the main service call fails due to timeout, error, or service downtime. It helps the application return a safe response instead of crashing or showing an error to the user.
Rate Limiting is a feature used to control how many requests a client can send within a specific time period. In Spring Cloud Gateway, it helps protect microservices from overload and prevents abuse like too many API calls from a single user.
Distributed Tracing is a technique used to track a single request as it travels through multiple microservices. It helps developers identify where delays, failures, or performance issues happen in a microservices system.
Spring Cloud Sleuth is a tracing tool used in microservices to automatically add trace ID and span ID to every request. It helps track and debug requests as they move across multiple microservices.
Zipkin is a distributed tracing tool used in microservices to track a request as it travels across multiple services. It helps developers identify slow services, performance bottlenecks, and failures by showing the complete request flow in a visual way.