RabbitMQ
Shovels
Federation Plugin
Message Queues
Technology Solutions

When to use RabbitMQ shovels and when Federation plugin?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

RabbitMQ is an open-source message broker that efficiently supports complex routing scenarios and message queuing. A common challenge in distributed systems involves deciding the optimal method to share or synchronize messages across different brokers or networks. RabbitMQ provides two primary mechanisms for this purpose: Shovel and Federation. Understanding when to use each can optimize messaging architectures and ensure system scalability and reliability.

Understanding RabbitMQ Shovels

Shovels in RabbitMQ are components that actively move messages from a source queue to a destination queue, potentially across different brokers. Shovels work by connecting to the source and destination brokers simultaneously. They then transfer messages using standard AMQP protocols or custom configurations.

Use Cases for Shovels

  1. High Volume, Low Latency: Shovels are ideal for scenarios requiring high-throughput and low-latency direct message delivery to another broker. They can efficiently handle large volumes of messages without significant delays.
  2. Cross Data-Center Replication: In architectures demanding real-time data replication across different data centers, shovels can ensure data synchronization without administrative overhead at the network level.
  3. Conditional Replication: Shovels can be configured with advanced filtering properties to selectively replicate messages based on specific criteria or headers. This is beneficial in environments where not all messages in a queue need to be duplicated elsewhere.
  4. Temporary Data Migration: During system upgrades or migrations, shovels can temporarily move data to a new broker or cluster without impacting the existing messaging flow.

Understanding RabbitMQ Federation

Federation in RabbitMQ extends the idea of shovels with more emphasis on eventual consistency and linking queues over unreliable networks. It does not actively move messages but instead, it waits for messages to be consumed (pulled) by the destination.

Use Cases for Federation

  1. Loose Coupling: When different systems or services must be kept loosely coupled yet need access to the same set of messages, federation can synchronize queues over long distances without tight dependency on the broker's state.
  2. Incremental Scaling: Federation is ideal when the messaging system needs to scale incrementally. It allows separate brokers or clusters to join the network and start receiving messages with minimal configuration.
  3. Intermittent Connections: Federated queues are perfect for scenarios where network connections are unreliable or intermittent. The federation links are resilient to network failures and can buffer messages until the connection is restored.
  4. Geographically Distributed Systems: When systems are spread across multiple geographic locations, federation helps by connecting brokers in a way that each maintains its autonomy while ensuring messages are shared across locations.

Example Implementations

Shovel Configuration

To configure a Shovel in RabbitMQ:

  1. Enable the Shovel plugin:
bash
   rabbitmq-plugins enable rabbitmq_shovel rabbitmq_shovel_management
  1. Define the Shovel via the management UI or a configuration file:
json
1   {
2     "src-uri": "amqp://source_broker",
3     "src-queue": "sourceQueue",
4     "dest-uri": "amqp://destination_broker",
5     "dest-queue": "destinationQueue"
6   }

Federation Configuration

Setting up Federation involves:

  1. Enable the Federation plugin:
bash
   rabbitmq-plugins enable rabbitmq_federation rabbitmq_federation_management
  1. Configure the upstream source:
json
1   {
2     "upstream-name": "upstreamA",
3     "uri": "amqp://remote_broker"
4   }
  1. Define a federated queue:
json
1   {
2     "federation-upstream": "upstreamA",
3     "queue": "myFederatedQueue"
4   }

Comparison Table

FeatureShovelFederation
Connection TypeActive connection (Push mechanism)Passive connection (Pull mechanism)
Use CaseHigh-throughput, low-latency tasksScalable, loosely-coupled systems
Network ReliabilityRequires stable networksSuitable for intermittent connections
Administrative OverheadRequires continuous monitoringLow maintenance once configured
Message DeliveryImmediate replication of messagesAsynchronous, eventual consistency
Configuration ComplexityRequires precise configurationEasier to set up and manage

Conclusion

The choice between Shovel and Federation in RabbitMQ should be guided by the specific requirements of your application. For critical, time-sensitive tasks where large volumes of data are involved, Shovels are generally more appropriate. Meanwhile, Federation suits scenarios where network stability is an issue or when incremental scalability and loose coupling are primary concerns. Both techniques offer robust solutions but excel under different conditions.


Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.