Reputation: 755
I'm a newbie to nodejs. What that out of the way, here is what I'm trying to do. I'm working on a project requires to "push" images into the DOM of the browser as soon as they are appear in db.
Think about out it as Pinterest, but when new image is uploaded to Pinterest, it's automatically delivered to a browser, so user can seat there and watch new pictures pop-up on a screen.
I would appreciate any beginners guidance on the challenge.
Upvotes: 1
Views: 588
Reputation: 163488
There are two parts to this problem. The first is letting all of your servers know that you have a new image. The second is getting that information and image to the clients.
To tackle communication between your servers, I suggest looking into a pub/sub system. Redis can be used for this. Basically, the server that inserts a new image into the database will "publish" a message, which is then broadcast to all the servers that have "subscribed" to that type of message. Your message could contain the ID of the record you just inserted.
Once you have that in place, I recommend using Socket.IO to maintain a persistent web socket or web-socket-like connection between clients, and your servers. Your servers get the message that there is a new image, and then query the database for the details if needed. Once they have those details, they can send a message to the client(s) with the URL where the image can be accessed.
Upvotes: 3