Home > Software engineering >  How can i make my REST API Faster with nodejs and express?
How can i make my REST API Faster with nodejs and express?

Time:02-16

  1. Summarize the problem

My problem: I have built a slow API. I want to make my api faster.

I am using Node.js and express to make REST APIs. And I have one api that takes average response time of 3.5s.

Below is what it does.

  1. It gets all userIds.
  2. Based on the userIds, it requests parallel REST APIs to get other user Data such as projectIds and groupIds. (Since the databases are in different DB, it is inevitable to make different Rest APIs)
  3. Based on the userData(userId, projectId, groupId etc..), it filters. ex) projectId = 1.
  4. It requests 4 different REST APIs in parallel such as schedule and timezone and so on.

I believe I am making two many requests because if there is 10 accounts. I am making 54 requests in total to response.

I want to get whole DB table with each request and combine them with code. Help me there is better way to do it.

Thx in advance.

CodePudding user response:

You can try the following ways to decrease the response time.

  1. Use logging to find which query takes most of the time and optimize it.
  2. Using Redis. Use caching to handle frequent common requests. Caching will remove the need to make any additional queries.
  3. Make sure all the requests and queries inside are actually async and try to make a common Database or Table to Get this data instead of various databases.
  • Related