I’m not an expert but here’s what I know:
-
It’s the number of tables that hits performance. As far as I’ve read it’s not recommended to have more than 3 tables (classes) connected to the live query server. In general scaling live queries requires using redis cache. Parse server has a module for caching live queries with redis cache.
The number of clients connected also matters. I remember reading on this forum that a single live query server can handle about 30k simultaneous clients.
-
As far as I know Parse live query server uses Websockets under the hood. And websockets use HTTP connections under the hood. So in my opinion if you can use HTTP connections directly it’s better. For react there is a package called useSWR that can automatically send HTTP connections to fetch the recent data (every second for example). Which means that with it your clients are not bound to the server instance and can be served by different instances as required by your load balancer.
This is not techical advice though.
This is how to use useSWR module to emulate live queries without having to use the live query server.
// client side
import useSWR from "swr";
// inside react component
const [numberOfPeople, setNumberOfPeople] = useState(0);
// this is a fetcher function to connect to the actual function in the backend
function fetchNumberOfPeople({numberOfPeople}) {
const Parse = (await import("parse")).default;
Parse.initialize(process.env.NEXT_PUBLIC_APP_ID);
Parse.serverURL = `${process.env.NEXT_PUBLIC_SERVER_URL}/parse`;
const response = await Parse.Cloud.run("getNumberOfPeople", { groupId});
if (response && response.sts) {
setNumOfPeople(response.msg);
}
}
// this is the function that emulates the live queries
useSWR({ groupId, setNumberOfPeople}, fetchNumberOfPeople, { refreshInterval: 1000 }); // refresh every second;
// server side
// this is the actual function on the backend
Parse.Cloud.define("getNumberOfPeople", async (req) => {
const { groupId} = req.params;
try {
const qNumOfPeople= new Parse.Query("People");
qNumOfPeople.equalTo("groupId", groupId);
const rNumOfPeople = await qNumOfPeople.count({ useMasterKey: true });
if (rNumOfPeople ) {
return { sts: true, msg: rNumOfPeople };
} else {
return { sts: false };
}
} catch (err) {
console.log("Error in getNumberOfPeople", err.message);
return err;
});