swr or tanstack query for a dashboard polling 8 endpoints every 5 seconds TanStack Query
Internal ops dashboard, 8 widgets, each one hitting its own endpoint. Product wants "live", which in practice means a 5 second refresh. Maybe 30 people have it open during a shift, one of them leaves it open on a wall display all day.
I have used SWR before and liked how small it is. Team lead wants TanStack Query for the devtools and mutation handling. There are no mutations on this screen at all.
Is there a real difference here or is this bikeshedding?
@mulch_marta · 5mo ago · 3 replies
For this screen alone it is close to bikeshedding - both give you an interval, both dedupe, both stop when the tab is hidden if you leave the defaults alone. Pick either and move on.
The number that should worry you is not the library. 8 endpoints every 5s is 1.6 req/s per open tab. Thirty tabs is 48 req/s of pure polling before anyone clicks anything, all day, including the wall display that nobody is looking at after 6pm. Two things I would do before choosing:
/dashboard/summarycall. It is one query, it caches as a unit, and your poll drops to 6 req/s across all thirty tabs.After that, the library choice is a coin flip and you should take the one your lead will maintain.
Reply
Report
@mulch_marta · 5mo ago
That is how every dashboard gets built. Worth keeping the individual endpoints around for anything that needs to be polled at a different cadence - the summary call is for the widgets that all want the same 5 seconds, not a rule for the whole screen.
Reply
Report
@clickertrainbee · 5mo ago
The summary endpoint is the obvious call in hindsight. The 8 widgets are 8 endpoints because 8 different people asked for them at different times, not because anything required it.
Reply
Report