Hi, Wishing you a happy new year!
I’ve been interested in developing a messaging mobile app (one-to-one chatting) and was initially considering Node/Redis/Mongodb as the backend tech stack. Since there can be multiple instances of WebSocket servers and different users can connect to different server instances, my idea was to use Redis to do the server-to-server communication that will route messages from one server to another, where it is necessary.
And this is when I discovered Cloudflare Workers! And it seems very interesting. However, I’m still trying to figure out how to implement a WebSocket based one-to-one messaging system using Workers and DOs.
So far, here is my current thought on this. I may be able to use a Durable Object that is unique for each user. The Durable Object will be managing the user’s WebSocket connection. So, if the user-A sends a message to user-B, the user-A’s Durable Object will lookup the DO belonging to the user-B and use it to push the message to the user-B’s device. But, when does DO instances get destroyed? Or do they live forever, resulting in massive number of unused DO instances?
Although, being a complete noob on Cloudflare technologies, I have a strong feeling that there might be much better ways to do this.
Any tips would be highly appreciated.