How to speed up API response?
jcode
PROOP

a year ago

My NodeJS API responds pretty slow to requests to the public network IP Railway provides.

Anyway to speed this up?

27 Replies

jcode
PROOP

a year ago

5a8681b5-f0ee-46a2-bed3-62fba619de18


a year ago

Did you deploy this API in a region near your end user/you?


a year ago

How are you measuring the latency of the requests?


jcode
PROOP

a year ago

Yeah Amsterdam and i'm in Belgium


jcode
PROOP

a year ago

Via the Network tab in DevTools, it's around 40ms to 69ms. Some are 100ms


jcode
PROOP

a year ago

I got very good ping and internet at my house, so that shouldn't be a big factor.


a year ago

Are you using the metal edge network? You can check that in your service -> public networking


jcode
PROOP

a year ago

Yeah

1366872241878335498


a year ago

Can you try disabling it and seeing if the latency lowers or is more consistent?


jcode
PROOP

a year ago

As in downgrading the network?


jcode
PROOP

a year ago

(clicking that refresh icon?)


jcode
PROOP

a year ago

If it's not better, can I still go back to Metal edge network?


a year ago

yes


a year ago

and yes


jcode
PROOP

a year ago

It's the same


jcode
PROOP

a year ago

Maybe i'm used to quicker cuz of local environment and now everything else feels slow


jcode
PROOP

a year ago

But there probably isn't much I can do right other than improve my NodeJS code for better performance?


mikexie360
PRO

a year ago

details on what the API is doing?

if the API has to handle a lot of work, then here are some solutions that I can think of.

  • Do API calls asynchronously.
  • Do API calls in big batches all at once
  • Do API calls in parallel instead of concurrent.

jcode
PROOP

a year ago

So basically improve my code


jcode
PROOP

a year ago

I already do most of those things


mikexie360
PRO

a year ago

ok, so the only thing now is to probably try other regions, or other cloud providers


mikexie360
PRO

a year ago

You could probably to also look into finding out if you could test the latency remotely on a different computer in a different geographical location compared to yours.

So use a service on a different cloud provider, call that api on railway, and log the latency to see if it is a regional thing.


a year ago

this is likely the case. api calls to a local server will have 0ms rtt, plus the actual processing that the api is doing


a year ago

more details on what processing is actually being done by your api would be helpful for suggesting optimizations


a year ago

40ms is not bad


jcode
PROOP

a year ago

Oh okay 🙂


jcode
PROOP

a year ago

Thanks guys


Welcome!

Sign in to your Railway account to join the conversation.

Loading...