Firestore + RedisGraph Cloud - The Best of Both Worlds?

jdgamble555

Jonathan Gamble

Posted on September 12, 2021

Firestore + RedisGraph Cloud - The Best of Both Worlds?

Right now if you want to do things like search your firestore database or have any kind of realistic relational data, tough cookies.

For reference, I have created work-arounds using Firestore alone:

Full-Text Searching

There are two officially supported ways to search your data:

  • Algolia
  • Elastic Search

I am purposely not linking to the docs on this, because paying for an outside service is not a real option. It is ridiculous that the Firebase team owned by the biggest search engine on earth, officially recommends paying for an outside service. I also think Firebase stepped down from Elastic Search since the Amazon forked it, and really just recommends Algolia.

My search version is way cheaper, and almost works just as well IMHO (minus speed).

However, if you don't mind spinning up your own docker instance, there are two other free-ish options (minus paying for the cloud run instance) that can be way faster and cheaper.

Users of Typesense claim it is way better than MeiliSearch, but I personally don't see a big difference. You can see Fireship.io for quick instructions on implementing this.

Relational Data

The problem with this is that you still can't search "relational" data. Algolia has ways to index relational data, but it is similar to how MongoDb indexes relational data. It is still a noSQL database under the hood that requires extraneous indexes. It is not efficient nor practical.

Enter Redis Cloud with RedisGraph

  1. Create a Redis Enterprise Cloud Account.
  2. Select RedisGraph as your module
  3. Login, get all your server information
  4. Download RedisInsight and connect your account
  5. Read the basics about RedisGraph
  6. Learn Cypher
  7. Create a Firebase Function OnWrite Trigger that basically adds and deletes everything you want to search and / or be relational
  8. Create a Firebase Callable Function that queries the db

Advanced users can increase the speed with:

Why not just use Redis?

Redis is quick and runs on the heap! It is in the cloud and has automatic scaling! However, there are no frontend apis that I could find. I found one small simple example for RedisGraph GraphQL, but no Rest API, nada. Even then I would need to write my own and deploy it to docker. Hopefully something like Prisma.io will write a GraphQL adapter, and Redis will support it out of the box. For the moment, it is a cloud database, but not a cloud platform.

So let's fix two broken databases by putting them together shall we!

Counters and Realtime and Notes

  • You can use redisGraph for Counters and aggregations through a cloud function
  • You could still have realtime data by returning the relevant document ids in the cloud function, then grabbing the document(s) from firebase
  • You could theoretically do a websocket in cloud run, but you don't necessarily need to
  • There are also Redis Enterprise versions on AWS and Heroku where you can add RedisGraph

In Sum

I have downloaded RedisGraph and created a cloud account. It was super easy, free, and most importantly I don't have to mess with docker or understand complex server technology. RedisInsight is just a tool I can install, not a necessity.

I did mess with Cypher using RedisInsight. There are no complex schemas and it is a super easy language. Use redisgraph.js in your Firebase Function to connect to it.

I have not done the last part, as I have other projects, but I think this should be a must for anyone who wants to use Firebase in the long haul. If you have a universal trigger function, which keep in mind can be costly and will run on every write to your db, you could keep your redis db up-to-date at all times. If you grow past Firestore, your data is there, and saved in RDFs which is even better.

Hope someone tries this. Let me know your thoughts.

J

💖 💪 🙅 🚩
jdgamble555
Jonathan Gamble

Posted on September 12, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related