From synchronous RPC calls to event-driven communication using Java 21, Micronaut 4, gRPC, and Apache Kafka.
When building microservices, one of the first architectural decisions is how services should communicate.
Should one service call another and wait for a response?
Or should it publish an event and let other services process it independently?
In real-world systems, the answer is often both.
In this article, we'll explore how gRPC and Apache Kafka fit into a Java microservices architecture, why they solve different communication problems, and what developers should consider when combining them.
We'll also look at a practical Java 21 and Micronaut 4 starter project that you can explore and adapt.
TWO COMMUNICATION PATTERNS, TWO DIFFERENT RESPONSIBILITIES
Let's start with a simple example.
Imagine an e-commerce application with three services:
• Order Service
• Payment Service
• Notification Service
When a customer places an order, several things happen.
The Order Service needs to process…