Synchronous communication in Microservices means:
One microservice sends a request to another microservice and waits for an immediate response before continuing execution.
In simple words:
The caller service blocks and waits until the called service responds.
Simple Real-Time Understanding
Imagine calling customer support on phone.
- You ask a question
- You wait for answer
- Only after response you continue conversation
This is synchronous communication.
Microservices Real-Time Example
Suppose an E-Commerce application contains:
- Order Service
- Payment Service
When user places an order:
- Order Service calls Payment Service
- Waits for payment result
- Then completes order
Synchronous Communication Flow
Order Service
|
HTTP Request
|
v
Payment Service
|
HTTP Response
|
v
Order Service Continues
Important Characteristic
During communication:
Order Service cannot continue execution until Payment Service responds.
Why Synchronous Communication is Used
Synchronous communication is used when:
- Immediate response is required
- Business operation depends on response
- Real-time processing is necessary
Examples
- Payment verification
- User authentication
- Balance validation
- Inventory availability check
Real-Time Banking Example
Suppose user transfers money.
Banking system must:
- Immediately verify account balance
- Immediately process transaction
Banking Flow
Transfer Service
|
v
Account Service
|
Check Balance
|
v
Response Returned
Transfer continues only after response.
How Synchronous Communication Works
- Client sends request
- Service A receives request
- Service A calls Service B
- Service A waits
- Service B processes request
- Service B returns response
- Service A continues execution
Step-by-Step Example
Step 1: Customer Places Order Step 2: Order Service Calls Payment Service Step 3: Order Service Waits Step 4: Payment Service Processes Payment Step 5: Payment Success Response Returned Step 6: Order Service Confirms Order
Technologies Used for Synchronous Communication
- REST API
- Feign Client
- WebClient
- gRPC
1. REST API Communication
REST APIs are the most commonly used synchronous communication mechanism.
REST Communication Flow
Service A
|
HTTP Request
|
v
Service B
|
HTTP Response
|
v
Service A
Spring Boot REST Example
Payment Service
@RestController
public class PaymentController {
@GetMapping("/pay")
public String pay() {
return "Payment Success";
}
}
Order Service Calling Payment Service
RestTemplate restTemplate =
new RestTemplate();
String response =
restTemplate.getForObject(
"http://payment-service/pay",
String.class
);
What Happens Internally
Order Service:
- Sends HTTP request
- Waits for response
- Continues after response arrives
2. Feign Client Communication
Feign Client simplifies synchronous REST communication in Spring Boot.
Why Feign Client?
- Less boilerplate code
- Cleaner communication
- Easy integration
Feign Client Example
@FeignClient(name = "payment-service")
public interface PaymentClient {
@GetMapping("/pay")
String pay();
}
Usage
@Autowired
private PaymentClient paymentClient;
String response =
paymentClient.pay();
Communication Flow
Order Service
|
Feign Client
|
v
Payment Service
3. WebClient Communication
WebClient supports reactive synchronous communication.
Example
WebClient.create()
.get()
.uri("http://payment-service/pay")
.retrieve()
.bodyToMono(String.class);
4. gRPC Communication
gRPC is a high-performance synchronous communication framework.
Why gRPC?
- Fast communication
- Binary protocol
- Low latency
REST vs gRPC
| Feature | REST | gRPC |
|---|---|---|
| Data Format | JSON | Protobuf |
| Performance | Moderate | High |
| Protocol | HTTP | HTTP/2 |
Advantages of Synchronous Communication
1. Immediate Response
Caller gets response instantly.
2. Simpler Business Logic
Easy to implement sequential workflows.
3. Easy Debugging
Request-response flow is easier to trace.
4. Real-Time Processing
Suitable for immediate operations.
Disadvantages of Synchronous Communication
1. Tight Coupling
Caller depends heavily on another service.
2. Increased Latency
Response time increases because caller waits.
3. Cascading Failures
Failure in one service may affect others.
4. Reduced Scalability
Blocking communication reduces throughput.
Real-Time Problem Example
Order Service
|
v
Payment Service (Slow)
Order Service also becomes slow because:
- It waits for response
Cascading Failure Example
Client | v Order Service | v Payment Service (Down)
Result:
- Order Service fails too
How to Handle Synchronous Communication Failures
- Circuit Breaker
- Retry Mechanism
- Fallback Responses
- Timeout Configuration
Circuit Breaker Example
@CircuitBreaker(
name = "paymentService",
fallbackMethod = "fallback"
)
Timeout Example
If Payment Service does not respond within:
3 seconds
Request automatically fails.
Fallback Example
Instead of crashing:
- Default response is returned
Load Balancing in Synchronous Communication
Load balancers distribute traffic across service instances.
Architecture
Load Balancer
|
------------------------------------------------
| | | |
v v v v
Payment 1 Payment 2 Payment 3 Payment 4
Service Discovery
In cloud environments:
- Service locations change dynamically
Service discovery helps services locate each other.
Example
Order Service
|
Service Registry
|
v
Payment Service Instance
Popular Tools
- Eureka Server
- Consul
- Kubernetes DNS
Synchronous vs Asynchronous Communication
| Feature | Synchronous | Asynchronous |
|---|---|---|
| Response | Immediate | Not immediate |
| Coupling | Tight | Loose |
| Latency | Higher | Lower |
| Scalability | Moderate | High |
| Examples | REST, Feign | Kafka, RabbitMQ |
Real-Time Example from My Project
In my project:
- API Gateway communicated synchronously with microservices
- Feign Client was used for service-to-service communication
- JWT validation happened synchronously
- Payment verification used synchronous REST communication
Project Communication Architecture
Client | v API Gateway | --------------------------------------------------- | | | | v v v v Interview Payment Internship Notification Service Service Service Service
Best Practices for Synchronous Communication
- Use timeouts
- Implement Circuit Breakers
- Use retries carefully
- Monitor latency
- Use load balancing
Professional Interview Answer
Synchronous communication in Microservices means one service sends a request to another service and waits for an immediate response before continuing execution. This communication is commonly implemented using REST APIs, Feign Client, WebClient, or gRPC. Synchronous communication is suitable for real-time operations such as payment verification, authentication, and inventory checks where immediate response is required. However, it can introduce tight coupling, latency, and cascading failures, so mechanisms like Circuit Breakers, Retry Policies, Timeout Configuration, and Load Balancing are used to improve reliability and fault tolerance.
Why Interviewers Like This Answer
- Explains communication clearly
- Includes real-time examples
- Covers Spring Boot technologies
- Explains challenges and solutions
- Shows distributed systems understanding
- Includes production-level concepts
Frequently Asked Questions
What is synchronous communication?
One service sends request and waits for immediate response.
Why synchronous communication is used?
For real-time operations requiring immediate response.
What are examples of synchronous communication?
REST APIs, Feign Client, WebClient, and gRPC.
What are the disadvantages?
Latency, tight coupling, and cascading failures.
How failures are handled?
Using Circuit Breakers, retries, fallbacks, and timeout mechanisms.