I've been prototyping something server-side in the style of the SQL Kappa architecture: facts on immutable logs, possibly keyed (and compactable by key), and SQL materialized views streaming the updates with Flink. And I'm in search of a React state manager in that philosophy.
Rows are sent to each client requesting a feed of them:
INSERT INTO user_orders_total_feed(user_id, data)
SELECT
uo.user_id,
SUM(o.price) total
FROM user_order uo
JOIN order o ON uo.user_id = o.user_id
JOIN user_live_subscription uls ON uo.user_id = uls.user_id
GROUP BY uo.user_id
WHERE uls.subscription_topic = 'orders_total'
But: maybe you want all the orders in the UI and do the aggregation client-side, to have all orders alongside the total. You could move the aggregation to the client side. And it would be great to have the same data language than on the server (so that business rule expression is the same).In that case, a React Hook library like SimpleR State could aggregate in SQL the sum and update the view reactively. It would look like:
const TotalView = () => {
const view = state.view('SELECT SUM(price) total FROM order_feed');
return (
<>
<div>{view.total}</div>
</>
)
}
I don't think that would be easy to do; but I think there is a market for it: The business folks doing no-code+SQL client-side, and they would sometimes ask through proper channels for a query to be computed globally server-side or be brought client-side.