Microservices communicate with each other through well-defined interfaces, either synchronous HTTP-based APIs or asynchronous messaging, without needing to know each other's internal implementation.
A Shopping Cart service might call a Pricing service synchronously over REST to get the current price of an item, while separately publishing a CartUpdated event to a Kafka topic that an Analytics service consumes later without the Cart service waiting on it.
// Synchronous: Feign client calls the Pricing service over REST
@FeignClient(name = "pricing-service")
public interface PricingClient {
@GetMapping("/prices/{sku}")
PriceResponse getPrice(@PathVariable("sku") String sku);
}
@Service
public class CartService {
private final PricingClient pricing;
private final KafkaTemplate<String, CartUpdated> kafka;
public CartService(PricingClient pricing, KafkaTemplate<String, CartUpdated> kafka) {
this.pricing = pricing;
this.kafka = kafka;
}
public void addItem(String cartId, String sku) {
PriceResponse price = pricing.getPrice(sku); // wait for answer
// ... update the cart ...
kafka.send("cart-events", cartId, new CartUpdated(cartId, sku, price.amount())); // fire event
}
}
// Enable Feign with @EnableFeignClients on the application classA concise interview answer is
Microservices talk to each other through APIs, either synchronous REST calls when an immediate response is needed, or asynchronous messaging through something like Kafka or RabbitMQ when the caller doesn't need to wait. Either way, they interact only through a well-defined contract, not by sharing internal implementation details.
Last updated: 1 November 2026
Previous question: Can you explain how an API Gateway can handle load balancing?
Next question: What is the difference between synchronous and asynchronous communication in microservices?