DEV Community

Discussion on: How would you tackle this? Multiple screens showing the same user generated content in real time.

Collapse
 
kallmanation profile image
Nathan Kallman

Sorry to necro; but I couldn't resist throwing my 2 cents at it!

I would add a table to track the "big screen" 's current image (a row for each "big screen", with a foreign key to the images table you have above):

ID CurrentImageID Name
1 3 Singapore
2 2 London

Then there's just a few operations to implement:

  1. User uploads new photo: just insert another record in the Images table
  2. "Big Screen" needs a new photo to display: check if that big screen's CurrentImageID is less than the largest ID in the Images table
    • if it is: display the image CurrentImageID points to, and increment CurrentImageID to the next one
    • if it is not (aka users have stopped uploading pictures for awhile): return a random image and do not increment CurrentImageID
  3. Adding a new "Big Screen"? Insert another row to this table and set CurrentImageID to the most recent image.
Collapse
 
nataliedeweerd profile image
𝐍𝐚𝐭𝐚𝐥𝐢𝐞 𝐝𝐞 𝐖𝐞𝐞𝐫𝐝

Great solution ! Thanks for taking the time to share it :D Don't worry about necroing the thread, it's great to get several different perspectives, as I know a similar job will come around again when we can travel more freely!

How would you trigger the "Big Screen" image check? CRON? OR just "listen" for an image upload?

Collapse
 
kallmanation profile image
Nathan Kallman

If I'm limited to just HTTP (so no websockets, server push schemes, or custom protocols) then I would just have the "Big Screen" regularly poll (aka cron) for a new image (maybe 10 seconds?).

If we can use websockets or similar, then that opens the door for fun things of the server notifying screens that new images are available (but then the screen would still make the "request" to get that new image so that it always goes through the same consistent process)