Backend Development 8 min read

Implementing Delayed Queues with Redis and Other Technologies

This article explains how Redis can be used to implement delayed queues, compares its advantages with other solutions such as RabbitMQ, RocketMQ, Kafka, Netty and Java DelayQueue, and provides practical guidance on using sorted sets and timestamps for time‑based task scheduling.

Top Architect
Top Architect
Top Architect
Implementing Delayed Queues with Redis and Other Technologies

Redis, a single‑threaded in‑memory database, can also be used to implement delayed queues by leveraging its sorted set (ZSET) data structure, where timestamps are stored as scores.

Typical business scenarios such as order cancellation, ride‑hailing timeouts, and delivery auto‑cancellation illustrate the need for delayed processing.

Implementation steps with Redis:

Use zadd to add tasks with a future timestamp as the score.

Periodically query with zrangebyscore (or zrangebyscore key min max withscores limit 0 1 ) to fetch due tasks.

Execute and remove processed tasks.

Advantages of Redis for delayed queues include high‑performance score sorting, fast in‑memory operations, clustering for scalability, and persistence via AOF/RDB.

Alternative solutions:

RabbitMQ – set queue expiration ( x‑expires ) or message TTL ( x‑message‑ttl ), or use the rabbitmq‑delayed‑message‑exchange plugin.

RocketMQ – send delayed messages to specific delay‑level queues and poll them with a timer.

Kafka – uses a timing wheel (TimingWheel) to schedule delayed tasks.

Netty – implements delayed queues with HashedWheelTimer based on a delayed queue.

Java DelayQueue – a priority queue that releases elements after their delay, suitable for single‑node scenarios.

Choosing the appropriate technology depends on factors such as required precision, scalability, persistence, and distributed support.

BackendRedisKafkaMessage QueueRabbitMQZsetDelayed Queue
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.