[GoLang] Slow API Response

shankytiwariTRIAL

10 months ago

Hi Everyone,

I need help with my Slow API response, I have been using Railway for a few months now and observing this API response slowness issue.

I am using Railway to host my API codebase, which is written in Golang, with a PostgreSQL database hosted on AWS.

However, I am experiencing very slow API responses.

Here are some details:

  1. My API server is hosted on Railway in the US West (Oregon, USA) region.

  2. My PostgreSQL database is hosted on AWS in the Asia Pacific (Mumbai) region.

  3. Locally, my code runs very fast.

  4. I have implemented Golang best practices and my database queries are optimized with proper indexing.

  5. I am currently on the Hobby Plan.

Given this setup, I am looking for advice on how to increase the performance of my API. Specifically:

  • Should I consider changing the regions of my services to bring them closer together?

  • Is there anything I might be missing that could be causing the slow response times?

  • Are there any tips and tricks to improve the performance of my API given my current setup?

Thank you in advance for your help!

Solved

11 Replies

10 months ago

From past experience helping other users, the round trip time for distances like US West to Asia is detrimental to database connections, here's a few options from (IMO) best to worst -

  • Run your database on Railway with the Pro plan so that both your service and database are in the same Singapore region and so you can connect to the database over the private network.

  • Stay on Hobby but still run your database on Railway so you can connect to it via the private network.

  • Update to Pro so that you can move your service to the Singapore region.

  • Move your database on AWS to the US West region.


shankytiwariTRIAL

10 months ago

Understood.

Is having different resgions is only problem or have you seen any other issues as well ?


10 months ago

For threads similar to yours it's always been the service is far away from the database.


shankytiwariTRIAL

10 months ago

Got it, I'll try one of these options. Thank you 👍🏻


shankytiwariTRIAL

10 months ago

Off Topic: Do you guys have good document on How to deploy barebone Next App on Railway? I want only NextJS to serve my Client Code, no DB in it.


10 months ago

For the most part deploying a next app is fairly simple, you should be able to give Railway your GitHub repo and it will build and run it, where you have any difficulties?


shankytiwariTRIAL

10 months ago

Yeah, I tried it gave Internal server error for some reason. Do you have a Sample Repo with DockerFile or share an example of DockerFile, that would be huge help?


10 months ago

I like Dockerfiles more than the next guy but you shouldn't need one in this case, nor should you need a guide since it should just work, would you mind opening up a new help post so we can try to debug what's misconfigured with your next app?


shankytiwariTRIAL

10 months ago

Sure, let me give it a try one more time, if it does not work. I will create thread.


shankytiwariTRIAL

10 months ago

@brody: Quick Update, I have purchased Pro Plan (Cancelled) Hobby. Once I used Singapore Region for my API service, API started to respond quickly. Thank you for the help.

P.S. I will create another thread for DB, wanted to understand how secure it is and do we have other feature such DR n all


Status changed to Awaiting Railway Response railway[bot] 10 months ago


10 months ago

Sounds good!


Status changed to Solved brody 10 months ago


[GoLang] Slow API Response - Railway Help Station