Understand These 5 Microservices Questions for Interviews

Microservice architecture is a common choice for building scalable and resilient applications. It is also one of the most common topics for Java Interviews.

November 1, 2025
3 min read
Understand These 5 Microservices Questions for Interviews

We will discuss some critical interview questions related to Microservices.

1. How Do Microservices Communicate With Each Other?

Microservices can communicate with each other using either:

  • Synchronous protocols like HTTP/REST
  • Asynchronous protocols like RabbitMQ, Kafka
Communication TypeDescriptionExample ToolsProtocol
SynchronousReal-time, blockingREST, gRPC, FeignHTTP, gRPC
AsynchronousEvent-driven, non-blockingKafka, RabbitMQAMQP, Kafka

So what are the differences between them?

FeatureREST (Synchronous)Messaging (Asynchronous)
TimingReal-timeDelayed, eventually consistent
CouplingTightly coupledLoosely coupled
Failure handlingRetry logic or circuit breakerMessage retries, dead letter queues
ToolsFeign, RestTemplateKafka, RabbitMQ

Rest Template Examples

@Service
public class ProductClient {
    private final RestTemplate restTemplate = new RestTemplate();

    public String getProductById(Long productId) {
        String url = "http://localhost:8081/products/" + productId;
        return restTemplate.getForObject(url, String.class);
    }
}

Using Feign Client

@FeignClient(name = "product-service")
public interface ProductClient {

    @GetMapping("/products/{id}")
    String getProduct(@PathVariable("id") Long id);
}

2. How Can You Secure Microservices?

We can use OAuth2, JWT or API Keys to secure microservices.

JWT Example

@EnableWebSecurity
public class SecurityConfig {

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http
          .authorizeHttpRequests(auth -> auth
              .requestMatchers("/admin/**").hasRole("ADMIN")
              .anyRequest().authenticated())
          .oauth2ResourceServer(oauth2 -> oauth2.jwt());
        return http.build();
    }
}

3. What Are the Key Differences Between Monolithic and Microservices Architectures?

FeatureMonolithic ArchitectureMicroservices Architecture
CodebaseSingle unified codebaseMultiple small, independent codebases
DeploymentEntire application deployed at onceEach service can be deployed independently
ScalabilityHard to scale specific featuresEasy to scale individual services
Technology StackTypically a single tech stackCan use different stacks per service
Fault IsolationOne failure can crash the entire appFailures isolated to individual services

4. What Are the Common Microservices Patterns?

PatternPurposeExample Library
API GatewayEntry point for requestsSpring Cloud Gateway
Circuit BreakerFail fast on repeated failuresResilience4j
Service DiscoveryDynamic registration and discoveryEureka, Consul
Configuration ServerCentral config managementSpring Cloud Config
Saga PatternDistributed transaction managementKafka-based Orchestration

5. What Are the Different Ways to Handle Fault Tolerance?

StrategyDescriptionTools
RetryRe-attempt failed callsSpring Retry
Circuit BreakerPrevent repeated failuresResilience4j
BulkheadIsolate service failuresResilience4j
FallbackProvide default responseResilience4j, Hystrix

Circuit Breaker with Fallback Example:

@CircuitBreaker(name = "productService", fallbackMethod = "fallback")
public String callProductService() {
    return restTemplate.getForObject("http://localhost:8081/products", String.class);
}

public String fallback(Throwable t) {
    return "Default product response";
}

Thanks for Reading.