Kafka or RabbitMQ? A System Design Interview Classic!⚙️
Designing an Order Processing System: Kafka vs. Rabbit MQ
Overview of the User Journey
- The discussion begins with a scenario where a customer places an order, which triggers the checkout service to call four other services: payment, inventory, email, and analytics.
Challenges with Direct Service Calls
- If the checkout service calls all four services directly, it may lead to delays for the customer if any service is slow; thus, some services should run in the background.
Role of the Broker
- After confirming payment, the checkout service passes the order to a broker (either Kafka or Rabbit MQ), which manages communication with remaining services without making customers wait.
Differences Between Rabbit MQ and Kafka
- Rabbit MQ uses multiple queues (one for each service), allowing workers to pick tasks from these queues. Once completed, tasks are deleted unless they fail after several attempts.
- In contrast, Kafka retains tasks even after processing for at least seven days. Each service reads from a shared topic while maintaining its own position (offset).
Handling Failures and Retries
- If an email service encounters issues (e.g., sending incorrect emails), Rabbit MQ deletes those tasks upon completion. However, Kafka allows reprocessing since it keeps historical data available.
Choosing Between Rabbit MQ and Kafka
- For ephemeral tasks like sending OTP emails that expire quickly, Rabbit MQ is suitable as old tasks do not need retention. Conversely, if event history is essential for future reference or corrections, Kafka is preferred.
Conclusion on Order Processing System Design
- For this specific order processing system scenario discussed in the video, choosing Kafka would be advantageous due to its ability to retain task history and facilitate error recovery.
Turn any video into a summary like this
YouTube links, meetings, lectures. With transcripts, search, and chat.