codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Subjects
🏗️

System Design

24 chapters

1System Design Basics2Vertical vs Horizontal Scaling3CAP Theorem4Load Balancers & Algorithms5Proxy Servers (Forward & Reverse)6Caching Strategies & Eviction7Content Delivery Networks (CDNs)8Database Replication9Database Sharding & Partitioning10Database Scaling & Sharding11Consistent Hashing12Choosing Databases (SQL vs NoSQL)13Message Queues (Kafka, RabbitMQ)14Microservices Architecture15API Gateways16Rate Limiting Algorithms17Long Polling vs WebSockets vs SSE18Heartbeat & Health Checks19Bloom Filters & Probabilistic Data Structures20Leader Election in Distributed Systems21Event-Driven Architecture22Distributed Locking23Circuit Breaker Pattern24Case Study: Design URL Shortener
SubjectsSystem Design

Message Queues (Kafka, RabbitMQ)

Updated 2026-05-04
3 min read

Message Queues (Kafka, RabbitMQ)

In a tightly coupled system, Service A directly calls Service B. If Service B is slow or crashes, Service A is blocked and also fails (a cascading failure). Message Queues solve this by introducing an intermediary buffer between services, enabling asynchronous communication.

1. The Concept

A Message Queue is a form of asynchronous service-to-service communication. Messages are stored in the queue until the consuming service retrieves and processes them.

The Model:

  1. Producer: The service that creates and sends a message to the queue (e.g., the Order Service places a "New Order" message).
  2. Queue (Broker): The intermediary that stores the message reliably until a consumer is ready.
  3. Consumer: The service that retrieves and processes the message from the queue (e.g., the Email Service reads the message and sends a confirmation email).

Key Benefit:

The Producer doesn't need to wait for the Consumer to finish. It drops the message into the queue and immediately continues processing other requests. This is asynchronous processing.

2. Use Cases

  • Order Processing: When a user places an order, the Order Service writes the order to the database and drops a message into the queue. Separate consumers asynchronously handle: sending the confirmation email, notifying the warehouse, and updating inventory. The user gets an instant "Order Placed!" response.
  • Image/Video Processing: When a user uploads a video to YouTube, the raw file is saved and a message is queued. Background workers asynchronously transcode the video into multiple resolutions (360p, 720p, 1080p, 4K).
  • Log Aggregation: Application servers produce millions of log entries per second. Instead of writing logs to a database synchronously (which would slow down every API response), they push log messages to a queue, and a dedicated log processing service consumes them.

3. RabbitMQ (Traditional Message Broker)

RabbitMQ is a traditional message broker that follows the AMQP (Advanced Message Queuing Protocol). It is designed for complex routing of messages.

  • Message Delivery: Once a consumer acknowledges a message, it is permanently removed from the queue.
  • Routing: Supports complex routing patterns (direct, topic, fanout exchanges) to send messages to specific queues based on routing keys.
  • Best For: Task queues, microservice communication where messages should be processed exactly once.

4. Apache Kafka (Distributed Event Streaming)

Kafka is fundamentally different from RabbitMQ. It is a distributed event streaming platform designed for massive scale.

  • Message Retention: Messages are NOT deleted after consumption. They are retained for a configurable period (e.g., 7 days). Multiple consumers can read the same messages independently.
  • Partitioning: Topics are split into partitions, distributed across multiple brokers. This enables massive parallelism.
  • Ordering: Kafka guarantees message ordering within a single partition.
  • Best For: Real-time event streaming, log aggregation, data pipelines processing millions of events per second (LinkedIn, Netflix, Uber).


PreviousChoosing Databases (SQL vs NoSQL)NextMicroservices Architecture

Recommended Gear

Choosing Databases (SQL vs NoSQL)Microservices Architecture