4

I am currently creating a marketplace mobile application from scratch and I'm using React Native for the front-end part and Firebase for the backend (using Firebase and Firestore).

I am wondering wether :

  • I should create a RESTful API using cloud functions and express to create API endpoints (that would connect to firebase and firestore) that I'd call from my redux actions in my React Native app (using redux thunk).

  • or, I should call firebase and firestore directly from redux actions.

I see couple pros and cons for each method.

Restful API pros :

  • Safer as I can check and manipulate submitted data more easily

  • Custom API reply (I can manipulate the return data)

Restful API cons :

  • Probably slower as I would have to call an API endpoint that will then call firebase and/or firestore.

  • Won't be as easy to set listeners on firestore data

What do you think about it ?

Which option should I choose knowing that I predict that the app will get a few thousand users daily. I want it to be as fast and safe as possible and be able to set listeners for notifications purposes.

1
  • Without knowing very specifically what you're trying to do, this is entirely a matter of opinion. I've written extensively about this in a blog post. If you want to open up a general discussion for your specific use case, I suggest posting to a discussion forum that allows it, such as Reddit. Commented Nov 11, 2020 at 17:26

2 Answers 2

1

In my opinion you should mix them, if you have to manage users, products or etc. Firebase produces client and admin sdk that has different roles. If you haven't need manage any data of products or users or etc. you can simply use client sdk.

My advise is you can use admin sdk on API (server-side) and feel free to use client sdk on your clients.

Use as managements on API, listening data, realtime chat etc. via client sdk.

You can check admin and client sdk. Also npm packages for React Native here.

Sign up to request clarification or add additional context in comments.

1 Comment

Data which need to be updated on real-time for example Like, Dislike, Rating that should call directly to firebase from client. For other then that recommend to use admin sdk on server side. If you intends to do authorization then must use admin sdk.
0

Mixing will be of help, you can try:

  • Listen for small amounts of data using the client SDK
  • Write and sort data using the cloud functions

In my experience, writing to a firebase database that uses ordered ids (in my case) leads to some huge problems in the long run. I lost a good chunk of data when my app accidentally wrote to a root index instead of a child index when the app was resumed from inactivity because the android system cleared the RAM.

Also, for notification, use Firebase Cloud Messaging.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.