How to reduce response time in API ? Please suggest.
I have been given a feature to build and I have completed all the backend work, including creating all the APIs and their impl.
However, I’m facing a performance issue. The main API internally calls three other APIs. Individually, each API takes around 500ms, but due to several conditions and processing logic, the overall response time of my API becomes 2-4 seconds.
There are no direct DB calls in my API, but the downstream APIs I’m calling perform DB operations internally. I have already implemented session caching, which helps for repeated requests, but during refreshes, first-time hits, or when new keys are generated, the response time still becomes quite high.
I was considering using multithreading/parallel API calls to improve performance. However, the first and second API calls are dependent on each other, while only the third one is independent. I’m also a bit reluctant to introduce multithreading because of some bad past experiences with concurrency issues.
Does anyone have suggestions on how I can further optimize or improve the response time in this kind of scenario?