Computer Science Grade 12 20 min

Message Queues: Asynchronous Communication (RabbitMQ, Kafka)

Explore message queues like RabbitMQ and Kafka, which enable asynchronous communication between different components of a distributed system.

Tutorial Preview

1

Introduction & Learning Objectives

Learning Objectives Differentiate between synchronous and asynchronous communication models in distributed systems. Define the core components of a message queue system: producer, consumer, broker, and queue. Explain the role of message queues in decoupling services and improving system fault tolerance. Compare and contrast the architectural models of RabbitMQ (smart broker) and Kafka (durable log). Design a basic microservices architecture that uses a message queue for inter-service communication. Analyze use cases to determine an appropriate message queuing technology. Ever wonder how a food delivery app can process your payment, alert the restaurant, and find a driver all at once without making you wait? 🍔➡️🛵 That's the magic of asynchronous communication! This le...
2

Key Concepts & Vocabulary

TermDefinitionExample Message QueueA component in software engineering that allows independent applications or services to communicate by sending messages to each other. It acts as a temporary buffer, holding messages until a recipient is ready to process them.An email service. When you send an email, it doesn't go directly to the recipient's inbox. It goes to a mail server (a message queue) which holds it until the recipient's email client is ready to download it. Producer (or Publisher)The application or service that creates and sends a message to the message queue.In an online store, when you click 'Place Order', the 'Checkout Service' is a producer that sends an 'OrderPlaced' message to a queue. Consumer (or Subscriber)The application or se...
3

Core Syntax & Patterns

Publish/Subscribe (Pub/Sub) Pattern Producer -> Topic/Exchange -> [Queue A -> Consumer A], [Queue B -> Consumer B] Used when a single message needs to be delivered to multiple, different consumers. The producer sends a message to a central 'topic' (in Kafka) or 'exchange' (in RabbitMQ), and the broker broadcasts it to all subscribed queues. This is ideal for event notifications where different services need to react to the same event (e.g., a 'UserSignedUp' event triggers a welcome email, a profile creation, and an analytics update). Competing Consumers Pattern (Work Queue) Producer -> Queue -> [Consumer A, Consumer B, Consumer C] Used to distribute a high volume of tasks across multiple identical consumers to scale processing....

4 more steps in this tutorial

Sign up free to access the complete tutorial with worked examples and practice.

Sign Up Free to Continue

Sample Practice Questions

Challenging
You are designing a financial system where every transaction must be processed exactly once, in the order it was received, and the entire history of transactions must be auditable for 7 years. Which technology is better suited and why?
A.RabbitMQ, because its per-message acknowledgement provides stronger guarantees than Kafka.
B.RabbitMQ, because its complex routing is necessary for financial systems.
C.Kafka, because its 'durable log' is an immutable, ordered record of events that can be retained for long periods and replayed for audits.
D.Neither, a traditional relational database with ACID transactions is the only option.
Challenging
A system uses the Competing Consumers pattern with three consumers (A, B, C). Consumer B encounters a bug causing it to process messages very slowly, but it does not crash and still sends an 'ack' upon completion. What is the most likely impact on the system?
A.The broker will detect the slow consumer and stop sending it messages.
B.Messages will be processed out of order, but overall throughput will remain the same as consumers A and C pick up the slack.
C.Overall system throughput will decrease because messages sent to consumer B will be 'stuck' in processing for a long time, and the broker will continue to send it a share of the messages.
D.The system will halt because the queue requires all consumers to operate at the same speed.
Challenging
To avoid the 'chatty' request/reply pitfall, design a fully asynchronous workflow for a video processing service. A Web API needs to know when a submitted video is transcoded. Which description best represents a robust, event-driven design?
A.The API uploads the video, sends a message to the 'video_processing' queue, and then polls a database status field every second until it changes to 'COMPLETED'.
B.The API sends a message to the 'video_processing' queue. The processing service, upon completion, writes the result directly back to the API's internal memory.
C.The API publishes a 'VideoSubmitted' event to a topic. A processing service consumes this. When finished, the processing service publishes a 'VideoProcessed' event (containing the result URL) to a different topic, which the API (or a notification service) is subscribed to.
D.The API opens a persistent TCP connection to the processing service, sends the video data, and waits for the result on the same connection.

Want to practice and check your answers?

Sign up to access all questions with instant feedback, explanations, and progress tracking.

Start Practicing Free

More from Distributed Systems: Architectures, Concurrency, and Fault Tolerance

Ready to find your learning gaps?

Take a free diagnostic test and get a personalized learning plan in minutes.