
Blog Content
Communication between microservices occurs in two categories:
-
Synchronous communication (Direct/waiting)
-
Asynchronous communication(Indirect/ without waiting)
1. Synchronous communication(One-by-one)
In this model, when Service A calls Service B, Service A blocks its thread and waits until Service B finishes its work and sends back the response .
Its types and protocols:
-
HTTP/REST (most common) : This uses data transfer,such as your frontend or one service sending a GET or POST request to another service.
-
How to implement in springboot(Tools)
-
RestTemplate/Webclient: Older/standard ways where you write boilerplate code to hit urls.
-
Feign Client (Declarative HTTP Client): A modern tool where you just create a java interface and annotations(like @Feign client).Spring automatically handles the underlying REST API call, making the code much cleaner and eliminating boilerplate code
-
gRPC (Google Remote Procedure Call): This runs over HTTP/2 and is very fast because it sends data in binary format (Protocol Buffers). gRPC is used when very fast internal communication is required
When to do it?
-
When you need an immediate response, such as checking a password during login (you can't send the user in without validation).
-
Example: Authentication/Login validation, payment processing authorization(where the next step strictly depends on the success of the current step
Challenges/Drawbacks:
-
Tight coupling: If service B is down, service A will also fail
-
Cascading failure: If one service behind slows down , all the services ahead in line will slow down.
2. Asynchronous Communication
In this model, Service A (Producer) sends a message to a Message Broker (like RabbitMQ or Kafka) and immediately continues its execution without waiting for a response from Service B (Consumer)
Its Types and Protocols:
-
Message Broker / Queue-Based (e.g., RabbitMQ): Works on AMQP protocol. Uses Exchanges and Queues to route targeted messages using routing keys. Best for point-to-point tasks or heavy background processing.
-
Event-Driven / Log-Based (e.g., Apache Kafka): Works on an append-only distributed log. Services publish "Events" to Topics, and multiple consumers can read them independently. High throughput, supports replayability
When to use it?
-
When the operation can be completed in the background (Fire-and-Forget).
-
Example: Sending an OTP/SMS, generating a PDF invoice after an order, syncing data with data analytics systems.
Advantages:
-
Loose Coupling: Service A doesn't care if Service B is alive or dead at that moment.
-
Traffic Spike Smoothing (Throttling): If 10,000 users place an order at once, the queue absorbs the load. Consumers process messages at their own safe pace without crashing
Transform Your Digital Presence
With Expert Engineering
We build high-performance web applications, mobile apps, and AI-driven systems. Let's discuss how we can help you achieve measurable growth.


