Microservices Patterns with Spring Boot and Spring Cloud
Java microservice interviews cover the building blocks: API gateway, service discovery, central configuration, inter-service calls, distributed tracing and data per service. Spring Cloud provides most of them, and Kubernetes provides some natively.
What you will learn
- Name the core microservice patterns and their Spring tools
- Call other services with RestClient or OpenFeign
- Trace requests across services with Micrometer Tracing
- Know what Kubernetes replaces
Key concepts
API gateway
Spring Cloud Gateway routes external requests to services and handles auth, rate limiting, CORS and path rewriting in one place.
Service discovery
Eureka or Consul keep a registry of service instances; clients look up healthy instances by name. On Kubernetes, Services and DNS do this.
Config server
Spring Cloud Config serves configuration from Git to every service. On Kubernetes, ConfigMaps and Secrets are common instead.
Distributed tracing
Micrometer Tracing (replacing Spring Cloud Sleuth) propagates trace ids through HTTP and messaging, exported to Zipkin, Jaeger or an OpenTelemetry backend.
Step by step
Declarative HTTP clients
// OpenFeign
@FeignClient(name = "inventory-service")
interface InventoryClient {
@GetMapping("/api/stock/{sku}")
StockResponse stock(@PathVariable String sku);
}
// Spring 6 HTTP interface (no extra dependency)
interface PricingClient {
@GetExchange("/prices/{sku}")
Price price(@PathVariable String sku);
}Examples
Gateway route
spring:
cloud:
gateway:
routes:
- id: orders
uri: lb://order-service
predicates: [ Path=/api/orders/** ]
filters: [ name: RequestRateLimiter ]Practise it
Try these without looking back. If you can explain each one out loud, you are ready for this question.
- Split a monolith into order, inventory and payment services, each with its own database.
- Follow one request across three services in Zipkin using its trace id.
Interview questions
What interviewers ask next on this topic. Answer out loud first, then open the model answer.
How do microservices share data?
Not through a shared database. A service exposes its data through an API, or publishes events that others consume to build their own read copies. Cross-service consistency is handled with sagas and eventual consistency.
Synchronous REST or asynchronous messaging between services?
REST or gRPC when the caller needs an answer now (check stock before checkout). Messaging when the work can happen later or many services react (order placed → email, analytics, loyalty points). Async messaging reduces temporal coupling.
Summary
Gateway, discovery, config, declarative clients and tracing are the core patterns; Spring Cloud supplies them and Kubernetes covers discovery and config natively. Keep data per service and prefer events for cross-service reactions.
Stuck on this one? Talk to Sumit.
Keys: F focus mode · ← → previous / next topic · Esc leave focus