0

The problem I'm dealing with is performance issues when needing to perform multiple Firestore queries in order to reach a result similar to to joins in SQL.

In my Flutter app, which uses Firebase and Firestore, I use Cloud Functions for serving my REST API. My API is the only thing that actually interacts with the Firestore database, not the Flutter app itself. I was always taught to design apps like this (not allowing the client to interact directly with the database) and so continued with that approach.

A potential solution I've seen are the official Firestore plugins for Flutter and have seen people designing their clients to interact directly with Firebase, however I haven't found any official documentation explicitly saying this design is preferred or even ok, and since it goes against when have been taught I haven't tried it yet. Can anyone confirm this or point me to documentation confirming this?

Edit Perhaps it's worth noting that the reasons I've been told not to have the client connect directly to the database are 1. Security and 2. It would require business logic for managing data to be in the client and that should be handled server-side.

Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
Garrett
  • 1,576
  • 4
  • 27
  • 51
  • 1
    There's lots of "should" in your question, which basically is just somebody's opinion. Your approach is valid using Firestore, but so is implementing business logic client-side *as long as you also implement server-side security rules* that enforce that logic on the database. For more on this, see https://stackoverflow.com/questions/37482366/is-it-safe-to-expose-firebase-apikey-to-the-public/37484053#37484053 – Frank van Puffelen Jan 10 '23 at 14:28
  • 2
    Note that needing to perform JOINs in a NoSQL database is typically a sign that your data model is still too relational. Consider if you can improve performance by duplicating the data, which is something that you've also been taught that you *should* not do in relational databases, but which is actually quite common in Firestore and other NoSQL databases. For more on this, I recommend checking out [NoSQL data modeling](https://highlyscalable.wordpress.com/2012/03/01/nosql-data-modeling-techniques/) and [Get to know Cloud Firestore](https://firestore.video). – Frank van Puffelen Jan 10 '23 at 14:31
  • Maybe show us a view of your database structure and what you are trying to achieve. – GrahamD Jan 10 '23 at 15:27

0 Answers0