Re:Ask HN: How Can I Make My Front End React to Database Cha...
by bruchim on Thursday April 18, 2024 @07:21AM
(#40074993)
Expiration-based cache (e.g., 3 seconds) is not acceptable in this case, and more than that will reduce the load on the server + db dramatically.
Imaging subscribing to SQL query not just for a table; isn't it very complicated?
Something like the "stale while revalidate" strategy (eg as used by react-query) is wayyyy simpler however, and gets you most of the way there. You can set a timeout for when to invalidate the frontend cache to something short if you wanted (eg 3 seconds), and if the content is still being viewed by a component after that time it just fetches itself again while keeping the stale data in place. And for the few pieces that truly are realtime, like a stock ticker or something, just use a direct websocket.