Hi, I hope you all are doing well. Recently I was exploring RabbitMQ, and I found it fascinating. Previously I've used Kafka. RabbitMQ is very different from Kafka. This article is mostly useful for beginners or people who haven't used RabbitMQ. If you are an experienced developer, you might not find anything new in this post.
What is RabbitMQ?
RabbitMQ (Rabbit Message Queueing) is an Open Source message broker. It is used by applications to interact asynchronously. Simplest use case of RabbitMQ can be establishing a communication between multiple micro-services.
Those who are new to message brokers or message queue read this to understand them. Experienced persons can skip.
What is a message queue?
Let's say you need an e-commerce solution. When any user places an order, 3 things happen: checkout handling, email sending and inventory update. You have a monolithic system where all 3 things happen sequentially, and on average it takes 5 seconds. Your user needs to hang on for 5 seconds. Later you decide to address this problem and break your system into 3 microservices.
- Checkout Service
- Email Service
- Inventory Service
Now each service will handle a particular thing. But the user still needs 5+ seconds because things will still happen sequentially. This is where the message broker/message queue comes into play. You will modify your application in this way:
- When the checkout service confirms payment, just return success to the user.
- Publish a message with order details in a message queue.
- Email & Inventory service will continuously wait for messages in the queue.
- Both microservices will do their task in the background without forcing the user to wait.
Message Queues provide a reliable way for micro-services to communicate with each other.
Read complete post on my blog.
Top comments (0)