SQS-style distributed delay queue, but outside of AWS?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
When developers need to manage asynchronous messages in distributed systems effectively, they often turn to message queuing services like Amazon SQS (Simple Queue Service). However, what if you need similar functionality outside of AWS, especially focused on delayed message delivery? This is where the concept of a SQS-style distributed delay queue comes into play, but implemented in an environment not dependent on AWS. This article explores the technicalities of creating and managing a distributed delay queue like SQS in a non-AWS context.
Understanding Delay Queues
A delay queue allows you to postpone the delivery of new messages to consumers for a certain period of time. Each message in the queue can have its own delay setting, controlling the visibility of the message to consumers. Delay queues are useful for tasks that do not need to be processed immediately but should be deferred until later. For instance, sending a notification email 24 hours after a user action.
Implementing a Distributed Delay Queue
To implement a SQS-style distributed delay queue outside of AWS, you need a few components:
- Message Queue System: RabbitMQ, Kafka, or any other broker that supports delayed messaging can be utilized.
- Storage Backend: A persistent storage to keep track of message states and ensuring reliability.
- Delay Mechanism: Handling the delay before messages are visible to consumers.
- Distributed System Support: Ensures that the solution scales and manages across different nodes in a network.
Choice of Technology
For this example, let’s choose RabbitMQ with its delayed message plugin for the queue system and PostgreSQL for backend storage.
Message Structure
Each message must include:
- ID: Unique identifier
- Payload: The actual data of the message
- Timestamp: When the message was queued
- Delay: Time in seconds to delay the message
RabbitMQ Configuration
To implement delayed messaging in RabbitMQ, first enable the RabbitMQ Delayed Message Plugin. Once enabled, you can declare a queue where messages can be published with a delay:
Processing and Visibility
Stored messages in PostgreSQL are processed based on their delay. A scheduled task checks periodically if messages are due to be processed based on current time and the initially set delay.
Scalability and Fault Tolerance
Since the operation depends heavily on the system clock and the scheduled tasks, ensure clocks are synchronized across your distributed system nodes. Use clustering for RabbitMQ and replication for PostgreSQL to ensure high availability and fault tolerance.
Key Considerations
| Feature | Description | Considerations |
| Delay Handling | Managed at the message broker level with plugins or at application level for simpler brokers. | Requires precise time management and can introduce latency if not managed properly. |
| Scalability | Should scale horizontally to handle high loads. | Dependencies on external systems like databases or other services need to be scaled accordingly. |
| Fault Tolerance | System should continue operating despite individual component failures. | Use of clusters and replication for all components; ensure backups. |
| Cost | Avoid vendor lock-in and potentially reduce costs with open source tools. | Initial setup and maintenance might be more complex and resource-intensive compared to managed solutions. |
Conclusion
Building a SQS-style distributed delay queue outside of AWS involves selecting the right technologies and correctly configuring them to handle message delays. By using tools like RabbitMQ with appropriate plugins and a robust backend like PostgreSQL, developers can create a powerful delay queue system that scales and provides the necessary delay functionality for asynchronous messaging tasks.
Related reading

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack 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.