Complex queries and need for ElasticSearch

Congrats on you app! While I wont directly answer your questions, I will share my experiences that I gained last 2 years.

I’m developing a social media app. You can see it on Google Play Store. While I developed this app I also worked on complex queries.

I should say, Parse doesn’t use best way on queries. For example parse has matchesQuery option.

Lets say you have users and users can create Trips. You will have two tables. _User and Trip. And Trip table will also have field called user. So you can know which user created the trip.
And let say users can set their profile to private. So only their friends will know the upcoming trips.
Imagine you want to search trips. And you can only show trips from public profiles. How do you do it?

In parse way, you create 2 query.

//First create User Query
const userQuery = new Parse.Query("_User");
userQuery.equalTo("is_public",true); //You only get public profiles

//Then Create Trip Query
const tripQuery = new Parse.Query("Trip");
tripQuery. matchesQuery("user", userQuery);

This will work at the beggining. But everytime you run this query, all users with public profile will be fetched. İf you have couple of hundred users this will work but what if you have 100k users? Query will timeout. You will tire server for nothing. So for large database this is not ideal solution.

My solution to this is making my database similar to Graph databases. Which means every objects has relevant information from relative objects.
Which means Trip objects know if User profile is public or not.

You can do this on beforeSave trigger.

Parse.Cloud.beforeSave("Trip", async (request) => {
  if(!request.original){
    const user = request.user;
    const trip = request.object;
    trip.set("is_public",user.get("is_public"));
    return trip;
  }
});

This way you can re-design your query. And final query will look like this:

const tripQuery = new Parse.Query("Trip");
tripQuery.equalTo("is_public",true);

This query doesnt fetch every users. And only returns relevant objects and its fast.

My second advice is move your app logic to cloud code. For an app like yours, I think moving app logic to cloud code is a must. I moved my logic to cloud code. And if something doesnt work or I want to change app behaviour, I just update cloud code and users dont have to update app.