Beware of using Serverless & Firestore

makeDEVeasy
2 min readApr 22, 2024
Photo by Growtika

In this article, I will explain the dos & don’ts of Serverless and Firestore. where it is good to implement and where it is really bad to implement.

Initially most of my side projects use DB - Firestore, Hosting APIs - Serverless

Because Firestore is cheap and serverless is pay-for-use, It also gives additional benefits, Firestore will give real-time, and with serverless - we can host our APIs independently, If some of the APIs are consumed by more no. of users, then those APIs will only charged and other APIs will be not be charged, This is very good to run any project in very low cost.

One day, a lot of users are started complaining about slowness in the app… I checked my codebase everything was good , but when I checked the response time of the APIs it nearly 2.5 sec — 3 sec its lot of time for doing any basic CRUD operations in backend.

Later spending so much time researching, I understood the point where in my backend code there is no issue, actually issue is in serverless and also in Firestore DB.

The problem with the serverless is the cold start issue. It means when you trigger an API.

Step 1 — It won’t start processing your request instantly.

Step2 — First it will find an instance to run your code, basically if you use EC2 or GCP compute engine those will run 24/7 and you will charged for the same, so any of your API trigged it will start processing your request instantly, but in serverless model it’s not the case.

Step 3 —In serverless model, Once it finds the free shared instance, then it will start installing your code packages and start running the code.

Step 4 —Then it can start taking up your request and start processing and give the response.

All these operations sound like little long but it will do in 1 to 1.5 seconds.

The worst part is most of the time it might give in 1 to 1.5 sec, sometimes it may go long from 1 to 10 seconds, which is bad.

If your project is frontend heavy and less backend-dependent APIs then serverless is good to use. but if your project is backend-heavy and needs an instant quick response time of less than 100ms then it’s not to prefer serverless rather AWS EC2 or GCP compute engine can do a better job.

Coming to Firestore — For any query operation to store data into DB, It will take an average of 1.5–2sec, It’s a lot of time. Better to avoid it instead Mongodb is the best option it will take an average 50ms.

I hope you learned something valuable…

--

--

makeDEVeasy

Initiative to make the every developer easy, when they look into complex problems and make them to learn more simpler as easy……