Tutorials Microservices & Event-Driven Architecture (EDA) Mastery
Asynchronous Communication: Message Brokers (RabbitMQ/Kafka)
On this page
Async Communication: Decoupling
The secret to high availability is Asynchronous Communication. If Service B is down, Service A shouldn't care—it just drops a message in a queue and moves on.
1. RabbitMQ vs Kafka
- RabbitMQ (Smart Broker): Best for complex routing. It handles the logic of ensuring messages get to the right place. Once read, a message is usually deleted. High reliability for task distribution.
- Kafka (Smart Client): Best for high-throughput 'Stream Processing'. It's essentially a distributed log. Messages stay in Kafka for days, allowing multiple services to 'Replay' the data. Perfect for analytics and audit trails.
2. MassTransit (The .NET Secret)
Don't call RabbitMQ or Azure Service Bus APIs directly. Use **MassTransit**. It's an abstraction layer that handles retries, poison pill queues (Dead Letter Queues), and the Saga pattern for you. It allows you to switch your broker from RabbitMQ to Kafka with just a config change.
4. Interview Mastery
Q: "What is 'Backpressure' in a messaging system?"
Architect Answer: "Backpressure is when the consumer is slower than the producer. If you send 1,000 messages a second but your DB can only handle 100, the queue will grow until the server crashes. We handle this through **Rate Limiting** on the consumer, or by automatically scaling out more consumer instances (KEDA) to handle the load."