What is Inter-service Communication?

How one microservice talks to another to:
-
Fetch data
-
Trigger actions
-
Share events
There are two main approaches:
-
Synchronous (REST/HTTP)
-
Asynchronous (Messaging – Kafka/RabbitMQ)
🔹 1️⃣ REST (Synchronous Communication)
How it works
-
Service A calls Service B using HTTP
-
Service A waits for response
📌 Example:
Characteristics
-
Request/response model
-
Blocking call
-
Tight runtime dependency
Pros
✅ Simple to implement
✅ Easy to debug
✅ Immediate response
✅ Good for CRUD operations
Cons
❌ Service A fails if Service B is down
❌ Higher latency under load
❌ Causes cascading failures
When to use REST?
✔ Real-time queries
✔ Simple data fetch
✔ Low-latency operations
🔹 2️⃣ Messaging (Asynchronous Communication)
How it works
-
Service publishes a message/event
-
Consumer processes it later
-
No direct dependency
📌 Example:
Characteristics
-
Event-driven
-
Non-blocking
-
Loosely coupled
Pros
✅ High scalability
✅ Fault tolerance
✅ Better performance under load
✅ No cascading failures
Cons
❌ Eventual consistency
❌ Harder debugging
❌ Message ordering complexity
When to use Messaging?
✔ Notifications
✔ Payments
✔ Auditing
✔ Event-driven workflows
🔹 REST vs Messaging (Quick Comparison)
| Aspect | REST | Messaging |
|---|---|---|
| Type | Synchronous | Asynchronous |
| Coupling | Tight | Loose |
| Latency | Immediate | Delayed |
| Failure handling | Poor | Better |
| Scalability | Limited | High |
| Complexity | Low | Medium–High |
🔹 Real-World Example (Best Practice)
🛒 E-commerce App
-
REST → Get order details
-
Kafka → Order placed → Payment → Email → Inventory update