Questions regading pricing, how to reduce costs
hello I have a app that runs with postgres, redis, and a single instance running, the last month bill was $ 42 and it's already estimated to $ 76 is that correct ? what Im missing ?
154 Replies
Project ID:
N/A
are you connecting to postgres and redis via the private network? if not, you are subjecting yourself to unnecessary egress fees
hello
not sure
hello!
probabbly via network
let me check it
what variables are you using when connecting to your two databases?
yeah
Im using the external url :HAHAHA:
how to switch ?
both postgres and redis have private url variants, using those to connect to the database will eliminate all database <--> service egress fees
got it
how to change
?
I think I must set like this, right ?
that is using the public network to connect to the databases
sh**t
that's the reason
additional $18
what two environment variables does your code use to connect to the two databases?
Database_url and redis_url
and would you happen to be using ioredis?
I don't know what is ioredis
then it seems you aren't using it 😆
what is the difference ?
I'm connecting like this
it's a client library for redis, just needed to know for the next steps, one minute I'll get you the new references you want to use
ok, but what it changes ?
exactly
it crashed my app
:blob_help:
Solution
update those two url variables with the values shown below
what did you change??
the database_url
and redis_url
only
slow down please, use the variable I have provided
ok
once done changing the variables, please resend an updated version of this screenshot
ok
There was one thing I also added in the previous postgres url
that is the max connections
as I'm using prisma, and some times I got the max connections reached
well that's easy enough to add later on
ok, I'm waiting the build
^
looks good to me
is this bun?
remix
not bun
remix with node?
node
yes
do any of those error logs have attributes, hover over the log line and look for a plus icon on the far left of the log line
well those aren't very helpful errors to say the least
at what point in your applications lifecycle do you open thr connection to the two databases? right on startup?
so in the file I use prisma just import it
right but that doesn't quite answer my question
I can't say this exactly Brody
please try to answer my question
inside my root file, I import this
db.server
that inside of it has the
getClient()
that handles the client.$connect();
I'm sorry but that doesn't quite answer my question
What kind of answer do you need ?
in the startup I open my connections
are you sure about that?
yes
what's your current start script
I got the error
that doesn't quite answer the question
this
Uses the default database
but mine has a different name
^
"start": "cross-env NODE_ENV=production node ./build/server.js",
what is the name of your postgres database?
pedegas
then update that name in the variable
postgresql://${{PGUSER}}:${{POSTGRES_PASSWORD}}@${{RAILWAY_PRIVATE_DOMAIN}}:5432/pedegas
I should set something like this, right ?hold on, send a screenshot of your railway project first please
b19b2751-44b4-49a2-b64d-0be0ed08b0b8
but you aren't using the default database name of
railway
(where your tables are located)
correct?please do your best to answer my questions, I seem to be asking my questions a few times each time I ask a question
I'm using the default database name
is that what your code has always used? the default database name?
no.
that's different
what database name where you using before
railway
may I ask why you said no? it becomes increasingly harder for me to help with incorrect information
sorry for that
set your start script to this please
ok
Hello @Brody
I did that
I solved the issue of the database connection
why delete?
just redacting
Now I think I will not have more billings for egress
as both redis and postgres are using the private network
did you modify the database url on the postgres service?
yes
why?
as it is my default database
what did you change the private url to?
My application Database url
you should be using these
yes
That's the same
DATABASE_URL=postgresql://${{Postgres.PGUSER}}:${{Postgres.POSTGRES_PASSWORD}}@${{Postgres.RAILWAY_PRIVATE_DOMAIN}}:5432/${{Postgres.PGDATABASE}}?connection_limit=10&pgBouncer=true
And now it works
why did you write out the entire url instead of using
${{Postgres.DATABASE_PRIVATE_URL}}
?bcs I need the other params
after the ?
${{Postgres.DATABASE_PRIVATE_URL}}?params=here
I tried this
not worked
I can try it again
it would work
why set pgbouncer to true? you arent using pgbouncer
I don't know
I just set this a lot of time ago
to don't reach the max connections
And I did not get it anymore
so I just kept
fair enough
HEY
I still have a question
@Brody regarding the ioredis
will it make any difference for me ?
you can still ask questions, im just marking the solution to the initial question
no, its just another redis client
ah ok
It worked !
awsome
ty
have a nice day
no problem! you too!
@Brody and if
I have another project that uses the same database
I checked that another one also was using an external database_url
Is that possible to still share the private database url ?
you have a service in another project that is connecting to the database in this project?
yes
then no, the private network is scoped to the project and environment that they are located in, you would want to bring that service into the project that has the database
(please dont close threads)
I see
@Brody I moved the project for the same that the db is located
but now it can't connect to the db
screenshot of project please
have you added the 3 second sleep to the start command?
no
let met add
Still error
please use these
fixed.
thanks again
no problem!
@Brody I really don't know what is happending
when I updated the estimated bill decreased to $ 22.33
now it is $ 47.08
its down from 80 so thats good
no lol
I was paying under 30
open the project cost and view billing by service
well you did add another service to the project
yes
did you remove the service from the old project?
yes
go and look into each services metrics
this last one is a cron, just runs once in the day
you would be charged egress for the backup data you send away to wherever you store
would that cost that much ?
just 29 mb zip file
no, just letting you know
ok
the thing is, last year I was paying a lot less
that was just update the db and this happened
last year railway didnt charge as much for egress
I see
look
from 19 to 42 😓
under 25 would be great for me
yeah looks normal, they used to waive 100% of egress, then 50% and now 0%
hmm, let's see so, next month
is the backup service using the private url too?
actually I notticed that it's oscilating
now, yes.