Leandro Glossman
Leandro Glossman

Reputation: 362

Redis Stale Data

I'm new at Redis. I'm designing a pub/sub mechanism, in which there's a specific channel for every client (business client) that has at least one user (browser) connected. Those users then receive information of the client to which they belong.

I need Redis because I have a distributed system, so there exists a backend which pushes data to the corresponding client channels and then exists a webapp which has it's own server (multiple instances) that holds the users connections (websockets).

Resuming:

So, in order to reduce work, from my Backend I don't want to push data to Clients that don't have Users connected. So it seems that I need way to share the list of connected Users from my Webapp to my Backend, so that the Backend can decide which Clients data push to Redis. The obvious solution to share that piece of data would be the same Redis instance.

My approach is to have a key in Redis with something like this:

[USERS: User1/ClientA/WebappServer1, User2/ClientB/WebappServer1, User3/ClientA/WebappServer2]

So here comes my question...

How can I overcome stale data if for example one of my Webapps nodes crashes and it doesn't have the chance to remove the list of connected Users to it from Redis?

Thanks a lot!

Upvotes: 0

Views: 1237

Answers (1)

Itamar Haber
Itamar Haber

Reputation: 50112

Firstly, good luck with the overall project - sounds challenging and fun :)

I'd use a slightly different design to keep track of my users - have each Client/Webapp maintain a set (possibly sorted with login time as score) of their users. Set a TTL for the set and have the client/webapp reset it periodically, or it will expire if the owning process crashes.

Upvotes: 1

Related Questions