🍃 Spring Boot Intermediate

What is Spring Boot microservices patterns?

Why Interviewers Ask This

Candidates at the intermediate level are expected to not only know this concept but explain the trade-offs involved. Interviewers use this question to see if you can reason about design decisions, not just recall facts.

Answer

Common microservices patterns with Spring Boot: 1. API Gateway: Spring Cloud Gateway as the entry point — routing, authentication, rate limiting, request transformation. 2. Service Registry/Discovery: Eureka Server: @EnableEurekaServer; clients register with @EnableDiscoveryClient. 3. Circuit Breaker with Resilience4j: @CircuitBreaker(name = "paymentService", fallbackMethod = "fallback") @Retry(name = "paymentService") @TimeLimiter(name = "paymentService") public CompletableFuture<Payment> processPayment(PaymentRequest req) { return CompletableFuture.supplyAsync(() -> paymentClient.process(req)); } private CompletableFuture<Payment> fallback(PaymentRequest req, Exception e) { return CompletableFuture.completedFuture(Payment.pending(req)); }. 4. Saga Pattern: orchestration-based sagas using Spring State Machine or Temporal; choreography via Kafka events. 5. CQRS: separate read models (optimized for queries) from write models (command handlers) — Axon Framework for event sourcing. 6. Distributed Tracing: Micrometer Tracing + Zipkin/Jaeger — spring.zipkin.base-url=http://zipkin:9411. Trace IDs propagated via HTTP headers. 7. Event-driven with Kafka: @KafkaListener(topics = "orders") public void handleOrder(OrderEvent event) { ... } kafkaTemplate.send("payments", PaymentEvent.from(order));. 8. Config Server: centralized configuration; spring.config.import=configserver:http://config-server:8888. 9. Health checks for K8s: liveness: /actuator/health/liveness; readiness: /actuator/health/readiness.

Pro Tip

Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex Spring Boot answers easy to follow.