Ask
198
@clickertrainbee ·

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?

9 answers Share
Report

Answering anonymously — a moderator will review it first.

  • @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:

    • collapse the 8 endpoints into one /dashboard/summary call. It is one query, it caches as a unit, and your poll drops to 6 req/s across all thirty tabs.
    • if any widget genuinely needs sub-5s freshness, that widget wants a server-sent events stream and the rest can poll at 30s.

    After that, the library choice is a coin flip and you should take the one your lead will maintain.

    174
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    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.

      69
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      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.

      54
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @sdcard_sid · 5mo ago · 2 replies

    One real difference: check the background behaviour explicitly rather than assuming. Both libraries default to not refreshing while the tab is hidden, and both let you turn that back on. On a wall display that is exactly backwards from what you want - the display is never focused, so with defaults it will quietly stop updating and show a number from three hours ago to a room full of people. Set the always-refresh option for that one deployment and leave the defaults alone everywhere else.

    118
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @flashcard_fen · 5mo ago

      Also give the wall display its own route with that option baked in rather than a query parameter somebody can forget. Ours ran for two months on stale data because a browser restart lost the ?live=1.

      41
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @film_fridge · 5mo ago

    Whichever you choose, make sure a slow endpoint cannot stack requests. With a 5s interval and a widget that occasionally takes 9s you want the next tick skipped, not queued behind it - both libraries handle the in-flight case, but if you have wrapped anything in your own effect you will have reinvented a request pileup. Ask me how I know.

    63
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @torque_spec · 5mo ago

    There are no mutations today. Within a year somebody will want to acknowledge an alert from the dashboard, and then you will want the mutation cache, the invalidation and the devtools. That is not a knockout argument but "we do not need feature X" on an internal tool has a short shelf life. The bundle difference between the two is not the thing that will decide whether this app is fast.

    79
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @flashcard_fen · 5mo ago

    Small thing that made our ops dashboard actually usable: show the age of the data next to each widget rather than a spinner on every refresh. "14s ago" tells the operator more than a flicker does, and it makes a stalled poll immediately visible instead of looking like a quiet period.

    44
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @sam_the_temp · 5mo ago

    Do check with whoever owns those 8 endpoints. Ours were cheap right up until the dashboard existed, and then one of them turned out to be doing a count over a 40 million row table every five seconds. The dashboard did not need to change - the query behind it did.

    27
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report