Microservices
Article 05: Inter-Service Communication Using REST
By Utility Zone · 2026-01-28T11:04:09.17842
1. Objective
Understand how microservices communicate synchronously using REST APIs and the challenges involved.
2. Key Concepts
- Synchronous communication
- REST APIs
- WebClient vs RestTemplate
- Tight vs loose coupling
3. Why Communication Is Needed
In microservices, each service owns its data. To complete a business flow, services must talk to each other.
Example:
- Order Service needs user details from User Service
4. Communication Flow
[Order Service] ---> HTTP ---> [User Service]
5. Hands-On: Calling User Service from Order Service
Using WebClient
@Service
public class UserClient {
private final WebClient webClient;
public UserClient(WebClient.Builder builder) {
this.webClient = builder.baseUrl("http://localhost:8081").build();
}
public String getUser(Long id) {
return webClient.get()
.uri("/users/" + id)
.retrieve()
.bodyToMono(String.class)
.block();
}
}
6. Controller Usage
@GetMapping("/orders/{id}")
public String getOrder(@PathVariable Long id) {
return "Order for user: " + userClient.getUser(1L);
}
7. Problems with Hardcoded URLs
- Not scalable
- Breaks when service location changes
- Difficult in cloud environments
8. Common Mistakes
- Chatty communication
- Circular dependencies
- Blocking calls everywhere
9. Interview Notes
- REST is simple but introduces runtime dependencies
- Synchronous calls increase latency
10. Summary
REST-based communication is easy to start with but has limitations.
11. What’s Next
Introduce Service Discovery to remove hardcoded URLs.