Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis PubSub message order in cluster is not guaranteed?

Tags:

redis

Is the message order of pubsub messages in a redis cluster in any way guaranteed?

We are using a Redis cluster (v3.2.8) with 5 master nodes, each with one slave connected & we noticed that we sometimes get pubsub messages in wrong order when publishing to one specific master for one specific channel and being subscribed to slave nodes for that channel.

I could not find any statements related to pubsub message order in cluster on redis.io nor on the redis-github repo.

like image 343
sebuseba Avatar asked Oct 18 '25 15:10

sebuseba


1 Answers

First of all, if you are using PUBLISH, then it is blocking and returns only after messages have been delivered, so yes the order is guaranteed.

There are 2 problematic cases that I see: Pipelining and Client disconnection.

Pipelining

From the documentation

While the client sends commands using pipelining, the server will be forced to queue the replies, using memory.

So, if a queue is used, the order should be guaranteed.

Client disconnection

I can't find it in the documentation, but if the client is not connected or subscribed when the message is published, then it wont receive anything. So in this case, there is no guarantee.

If you need to persist messages, you should use an a list instead.

like image 87
noscreenname Avatar answered Oct 21 '25 14:10

noscreenname