Bird
Raised Fist0
RabbitMQdevops~20 mins

Message queue use cases in RabbitMQ - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Message Queue Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Primary use case of message queues in distributed systems
Which of the following best describes the main purpose of using a message queue like RabbitMQ in a distributed system?
ATo store large files and media content for web applications
BTo enable asynchronous communication between services, decoupling producers and consumers
CTo perform real-time data analytics on streaming data
DTo replace databases for persistent data storage
Attempts:
2 left
💡 Hint
Think about how services communicate without waiting for each other.
❓ scaling
intermediate
2:00remaining
Scaling consumers with RabbitMQ
If a system uses RabbitMQ to process tasks and the number of tasks suddenly increases, what is the best way to handle the increased load?
AIncrease the size of the RabbitMQ server's disk space
BSwitch to a synchronous request-response model
CAdd more consumer instances to process messages in parallel
DReduce the message TTL (time to live) to discard old messages faster
Attempts:
2 left
💡 Hint
Think about how to process more messages at the same time.
❓ tradeoff
advanced
2:00remaining
Tradeoff between message durability and performance
What is a common tradeoff when configuring RabbitMQ for message durability?
AEnabling message durability increases latency but prevents message loss on broker failure
BDisabling message durability improves security but reduces throughput
CDisabling message durability guarantees message delivery order
DEnabling message durability decreases latency and increases throughput
Attempts:
2 left
💡 Hint
Consider what happens when the broker crashes and how durability affects speed.
❓ Architecture
advanced
2:00remaining
Designing a fault-tolerant task processing system with RabbitMQ
Which architectural pattern best ensures that tasks are not lost and are processed at least once using RabbitMQ?
AUse durable queues, persistent messages, and manual message acknowledgments
BUse transient queues with automatic message deletion after consumption
CUse non-persistent messages with auto-acknowledgment enabled
DUse a single consumer with no message acknowledgments
Attempts:
2 left
💡 Hint
Think about how to avoid losing messages even if the system crashes.
❓ estimation
expert
3:00remaining
Estimating RabbitMQ capacity for peak load
A system expects to receive 10,000 messages per second at peak. Each message is 1 KB in size. The RabbitMQ server has a network bandwidth of 1 Gbps and disk write speed of 100 MB/s. What is the main bottleneck when enabling message durability?
ADisk write speed is the bottleneck because 10,000 KB/s (approx 10 MB/s) is less than disk speed, so no bottleneck
BNetwork bandwidth is the bottleneck because 10,000 KB/s equals 80 Mbps, which is less than 1 Gbps
CDisk write speed is the bottleneck because 10,000 KB/s (approx 10 MB/s) is close to disk speed limit
DNeither network nor disk is a bottleneck because both exceed the required throughput
Attempts:
2 left
💡 Hint
Calculate the data rate and compare with bandwidth and disk speed.

Practice

(1/5)
1. What is a primary use case of a message queue like RabbitMQ in system design?
easy
A. To enable asynchronous communication between different parts of a system
B. To store large amounts of data permanently
C. To directly serve web pages to users
D. To replace a database for all data storage needs

Solution

  1. Step 1: Understand message queue purpose

    Message queues allow parts of a system to send messages without waiting for immediate response, enabling asynchronous communication.
  2. Step 2: Compare options with message queue role

    Storing large data, serving web pages, or replacing databases are not typical message queue roles.
  3. Final Answer:

    To enable asynchronous communication between different parts of a system -> Option A
  4. Quick Check:

    Message queue = asynchronous communication [OK]
Hint: Message queues help parts talk without waiting [OK]
Common Mistakes:
  • Thinking message queues store data permanently
  • Confusing message queues with web servers
  • Assuming message queues replace databases
2. Which of the following is the correct way to declare a queue in RabbitMQ using its syntax?
easy
A. queue.declare('task_queue', durable=False)
B. channel.create_queue('task_queue', persistent=True)
C. channel.queue_declare(queue='task_queue', durable=True)
D. channel.queue('task_queue', durable=True)

Solution

  1. Step 1: Recall RabbitMQ queue declaration syntax

    The correct method is channel.queue_declare with parameters like queue and durable.
  2. Step 2: Check each option's method and parameters

    Only channel.queue_declare(queue='task_queue', durable=True) uses the correct method name and parameters. Others use incorrect method names or parameters.
  3. Final Answer:

    channel.queue_declare(queue='task_queue', durable=True) -> Option C
  4. Quick Check:

    Correct method is queue_declare with queue and durable [OK]
Hint: Use channel.queue_declare with queue name and durable flag [OK]
Common Mistakes:
  • Using wrong method names like create_queue
  • Confusing parameter names like persistent instead of durable
  • Omitting the channel object
3. Given the following RabbitMQ setup, what will happen if the consumer is slower than the producer?
channel.queue_declare(queue='jobs')
for i in range(10):
    channel.basic_publish(exchange='', routing_key='jobs', body=f'job-{i}')
# Consumer processes messages one by one slowly
medium
A. Messages will be lost if consumer is slow
B. Producer will block and wait for consumer to finish each message
C. Consumer will skip messages if it is slow
D. Messages will queue up in RabbitMQ until the consumer processes them

Solution

  1. Step 1: Understand RabbitMQ message flow

    RabbitMQ stores messages in the queue until consumers process them, allowing producers to send messages quickly.
  2. Step 2: Analyze slow consumer effect

    If consumer is slow, messages accumulate in the queue, waiting to be processed, not lost or skipped.
  3. Final Answer:

    Messages will queue up in RabbitMQ until the consumer processes them -> Option D
  4. Quick Check:

    Slow consumer = messages queue up [OK]
Hint: Slow consumer causes message backlog in queue [OK]
Common Mistakes:
  • Assuming producer blocks on slow consumer
  • Thinking messages get lost automatically
  • Believing consumer skips messages if slow
4. A developer wrote this RabbitMQ consumer code but it never receives messages:
channel.queue_declare(queue='tasks')
channel.basic_consume(queue='task', on_message_callback=callback, auto_ack=True)
channel.start_consuming()

What is the likely problem?
medium
A. Queue name mismatch between declare and consume calls
B. Missing call to channel.queue_declare
C. auto_ack should be False to receive messages
D. Callback function is not defined

Solution

  1. Step 1: Compare queue names in declare and consume

    The queue is declared as 'tasks' but consumed from 'task' - names differ.
  2. Step 2: Understand effect of queue name mismatch

    Consumer listens on a different queue than the one declared, so it receives no messages.
  3. Final Answer:

    Queue name mismatch between declare and consume calls -> Option A
  4. Quick Check:

    Queue names must match to receive messages [OK]
Hint: Check queue names match exactly in declare and consume [OK]
Common Mistakes:
  • Ignoring queue name spelling differences
  • Thinking auto_ack affects receiving messages
  • Assuming callback must be defined to start consuming
5. You want to design a system using RabbitMQ to handle image processing tasks that may take time. Which approach best uses message queues to improve system scalability and reliability?
hard
A. Use RabbitMQ only for logging, not for task processing
B. Send image processing requests to a durable queue and have multiple worker consumers process them asynchronously
C. Store images in the queue and process them only when the queue is empty
D. Process images immediately in the web server without queues to reduce latency

Solution

  1. Step 1: Identify system needs for scalability and reliability

    Image processing tasks are time-consuming and benefit from asynchronous handling and multiple workers.
  2. Step 2: Match RabbitMQ use case to system design

    Using a durable queue with multiple consumers allows tasks to be processed reliably and in parallel, improving scalability.
  3. Final Answer:

    Send image processing requests to a durable queue and have multiple worker consumers process them asynchronously -> Option B
  4. Quick Check:

    Durable queue + multiple workers = scalable, reliable processing [OK]
Hint: Use durable queues and multiple workers for heavy tasks [OK]
Common Mistakes:
  • Processing tasks synchronously in web server
  • Storing large data directly in queues
  • Using message queues only for logging
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard