R
Railway•7mo ago
Harris

How close is my Redis & Application when deployed on Railway?

Would it be two pods on the same machine? Two pods in a magic EKS cluster in the same region? I'm trying to gain a better mental model of it all. One thing I know is accessing Redis (in my same project) should be faster than access a Neon DB in the same geographic region but not guranteed to be on the same datacenter.
67 Replies
Percy
Percy•7mo ago
Project ID: N/A
Harris
Harris•7mo ago
N/A
Fragly
Fragly•7mo ago
I did some digging in the docs and couldn't really find any information about that, it's possible I missed it though since you're on pro plan you can directly email railway and ask for that information ( via support@railway.app from the email you use on railway ) if you want
Harris
Harris•7mo ago
oh dope ty
Fragly
Fragly•7mo ago
no problem :)
Brody
Brody•7mo ago
two services given that they are both set to the same region will absolutely be in the same data center, but are not guaranteed to be on the same host due to how railway packs compute, but either way, all services within the same project and environment will be part of a wireguard tunnel making service to service communication faster then connecting to an external database elsewhere, provided you connect over the private network
Harris
Harris•7mo ago
ahh! so I should prefer to use private networking over everything else for inter-service communication when I set up my redis instance, and had it connect to my app with shared variables is that url (proxy.rlwy.net) a private network one? on the docs it shows "railway.internal" being the private net
Brody
Brody•7mo ago
absolutely, there's no networking fees and less hops on the private network
Harris
Harris•7mo ago
OH wait I'm currently using the TCP proxy right hmm
Brody
Brody•7mo ago
rlwy.net is the public one railway.internal is the private one
Harris
Harris•7mo ago
gotcha so new goal acquired: convert redis to private network rather than tcp proxy
Brody
Brody•7mo ago
just connect to the private network using the correct variable instead use the private url reference variable
Harris
Harris•7mo ago
i see
Harris
Harris•7mo ago
No description
Harris
Harris•7mo ago
so rather than REDISHOST i just do REDIS_PRIVATE_URL?
Brody
Brody•7mo ago
nope, a url isn't the same as a host, this is what I'd do, it's for bullmq but bullmq uses the exact same connection object type https://discord.com/channels/713503345364697088/1176342343826280540/1176379472228909087
Harris
Harris•7mo ago
No description
Harris
Harris•7mo ago
ohhh interesting so you parse the URL I'm surpised there isn't a native URL option oh wait there totally is
Harris
Harris•7mo ago
No description
Brody
Brody•7mo ago
doesn't seem to work
Harris
Harris•7mo ago
oh it doesn't?
Brody
Brody•7mo ago
when I tried it will bullmq, it didnt
Harris
Harris•7mo ago
is bullmq ontop of redis?
Brody
Brody•7mo ago
yes, uses the same types on top of ioredis*
Harris
Harris•7mo ago
just pushed, will try the single url and then the url extraction TIL I was leaving the datacenter and then coming back via TCP proxy
Brody
Brody•7mo ago
do you have that variable referenced on your service?
Harris
Harris•7mo ago
I do
Brody
Brody•7mo ago
referenced and not just copy pasted lol
Harris
Harris•7mo ago
yeah, I used the reference variable UI
Harris
Harris•7mo ago
No description
Harris
Harris•7mo ago
No description
Harris
Harris•7mo ago
worry
Brody
Brody•7mo ago
show code please
Harris
Harris•7mo ago
oh wait haha i changed the variable on prod but my code is on bezoslaugh
Brody
Brody•7mo ago
you'll have that oh, it won't work anyway, you need family 0 since ioredis assumes ipv4 by default and the private network is ipv6 only
Harris
Harris•7mo ago
family 0?
Brody
Brody•7mo ago
have a look at the example code here, same connection object bullmq just passes it to ioredis, so you can use it all the same
Harris
Harris•7mo ago
No description
Harris
Harris•7mo ago
// Documentation: https://www.npmjs.com/package/ioredis
import Redis from 'ioredis';

if (!process.env.REDIS_PRIVATE_URL) {
throw new Error('REDIS_PRIVATE_URL not found');
}

const redisURL = new URL(process.env.REDIS_PRIVATE_URL);

export const redis = new Redis({
family: 0,
host: redisURL.hostname,
port: parseInt(redisURL.port),
username: redisURL.username,
password: redisURL.password,
});
// Documentation: https://www.npmjs.com/package/ioredis
import Redis from 'ioredis';

if (!process.env.REDIS_PRIVATE_URL) {
throw new Error('REDIS_PRIVATE_URL not found');
}

const redisURL = new URL(process.env.REDIS_PRIVATE_URL);

export const redis = new Redis({
family: 0,
host: redisURL.hostname,
port: parseInt(redisURL.port),
username: redisURL.username,
password: redisURL.password,
});
Brody
Brody•7mo ago
do a sanity check variable print? though maybe buns url parser doesn't wanna parse a url with a redis scheme
Harris
Harris•7mo ago
yeah the url logs but doesn't get parsed
Brody
Brody•7mo ago
uncommon bun L
Harris
Harris•7mo ago
hmmm i think i know why i didn't have private networking enabled <:stare_hmm:869304431093620776> i think it works now? i'm a little confused about the logs though oh nevermind i think it works hype turns out you need to enable it or else the URL is thumbsup services need private networking enabled right?
Brody
Brody•7mo ago
ah yeah that makes a lot of sense even though the private networking enable and disable is in a services settings, it's a global option for the project
Harris
Harris•7mo ago
are these settings able to be stored in railway.toml at all? would be nice to do this through code
Brody
Brody•7mo ago
nope this setting isn't available in a config file but it's enabled by default, so not sure why it was even off
Harris
Harris•7mo ago
i think i had turned it off at some point didn't understand what it was
Brody
Brody•7mo ago
fair enough lol are you using the private network to connect to postgres? (i think you mentioned at some point you use postgres too)
Harris
Harris•7mo ago
my postgres currently lives in NeonDB (same region & datacenter I believe) but I'm heavily considering moving it to railway for latency gains
Brody
Brody•7mo ago
and egress reduction
Harris
Harris•7mo ago
true my main thing was scaling I would like minimal setup max autoscale
Harris
Harris•7mo ago
No description
Harris
Harris•7mo ago
neon kind of just lets me do that on the right with the slider there also handles connection pooling from my serverless functions on vercel
Brody
Brody•7mo ago
youre on pro so you get a max of 32vcpu and 32gb of ram
Harris
Harris•7mo ago
👀 does it dynamically scale up to that?
Brody
Brody•7mo ago
it just what you could use at any time, if postgres only needs 1gb, then its only gonna use 1gb, if postgres needs 28gb, then it will be able to use 28gb aka vertical scaling
Harris
Harris•7mo ago
gotcha what about connection pooling? if I have 100 serverless functions trying to access it at once that's needed right?
Brody
Brody•7mo ago
you can deploy PgBouncer
Harris
Harris•7mo ago
oh nice is that just built into postgres?
Brody
Brody•7mo ago
no its a template on the marketplace
Harris
Harris•7mo ago
No description
Harris
Harris•7mo ago
nice need to read up on that some more
Brody
Brody•7mo ago
https://railway.app/template/L09YMd dont know how well it will work with the private networking though, but im always here to help
Harris
Harris•7mo ago
well so I'd need to be able to access it via private networking and public since my Bun application can use private, but Vercel functions need public
Brody
Brody•7mo ago
thats true dont see why you cant use both
Harris
Harris•7mo ago
alrighty time to read up and implement 😤 goal for tonight: - implement pgbouncer & move postgres to railway - setup Infisical for secret management (i dunno how nicely it'll play for variable references worry )
Brody
Brody•7mo ago
saw that thread, i unfortunately cant answer it, never used it myself