R
Railway•12mo 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•12mo ago
Project ID: N/A
Harris
HarrisOP•12mo ago
N/A
Fragly
Fragly•12mo 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 [email protected] from the email you use on railway ) if you want
Harris
HarrisOP•12mo ago
oh dope ty
Fragly
Fragly•12mo ago
no problem :)
Brody
Brody•12mo 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
HarrisOP•12mo 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•12mo ago
absolutely, there's no networking fees and less hops on the private network
Harris
HarrisOP•12mo ago
OH wait I'm currently using the TCP proxy right hmm
Brody
Brody•12mo ago
rlwy.net is the public one railway.internal is the private one
Harris
HarrisOP•12mo ago
gotcha so new goal acquired: convert redis to private network rather than tcp proxy
Brody
Brody•12mo ago
just connect to the private network using the correct variable instead use the private url reference variable
Harris
HarrisOP•12mo ago
i see
Harris
HarrisOP•12mo ago
No description
Harris
HarrisOP•12mo ago
so rather than REDISHOST i just do REDIS_PRIVATE_URL?
Brody
Brody•12mo 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
HarrisOP•12mo ago
No description
Harris
HarrisOP•12mo ago
ohhh interesting so you parse the URL I'm surpised there isn't a native URL option oh wait there totally is
Harris
HarrisOP•12mo ago
No description
Brody
Brody•12mo ago
doesn't seem to work
Harris
HarrisOP•12mo ago
oh it doesn't?
Brody
Brody•12mo ago
when I tried it will bullmq, it didnt
Harris
HarrisOP•12mo ago
is bullmq ontop of redis?
Brody
Brody•12mo ago
yes, uses the same types on top of ioredis*
Harris
HarrisOP•12mo 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•12mo ago
do you have that variable referenced on your service?
Harris
HarrisOP•12mo ago
I do
Brody
Brody•12mo ago
referenced and not just copy pasted lol
Harris
HarrisOP•12mo ago
yeah, I used the reference variable UI
Harris
HarrisOP•12mo ago
No description
Harris
HarrisOP•12mo ago
No description
Harris
HarrisOP•12mo ago
worry
Brody
Brody•12mo ago
show code please
Harris
HarrisOP•12mo ago
oh wait haha i changed the variable on prod but my code is on bezoslaugh
Brody
Brody•12mo 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
HarrisOP•12mo ago
family 0?
Brody
Brody•12mo 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
HarrisOP•12mo ago
No description
Harris
HarrisOP•12mo 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•12mo ago
do a sanity check variable print? though maybe buns url parser doesn't wanna parse a url with a redis scheme
Harris
HarrisOP•12mo ago
yeah the url logs but doesn't get parsed
Brody
Brody•12mo ago
uncommon bun L
Harris
HarrisOP•12mo 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•12mo 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
HarrisOP•12mo ago
are these settings able to be stored in railway.toml at all? would be nice to do this through code
Brody
Brody•12mo 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
HarrisOP•12mo ago
i think i had turned it off at some point didn't understand what it was
Brody
Brody•12mo 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
HarrisOP•12mo 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•12mo ago
and egress reduction
Harris
HarrisOP•12mo ago
true my main thing was scaling I would like minimal setup max autoscale
Harris
HarrisOP•12mo ago
No description
Harris
HarrisOP•12mo 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•12mo ago
youre on pro so you get a max of 32vcpu and 32gb of ram
Harris
HarrisOP•12mo ago
👀 does it dynamically scale up to that?
Brody
Brody•12mo 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
HarrisOP•12mo ago
gotcha what about connection pooling? if I have 100 serverless functions trying to access it at once that's needed right?
Brody
Brody•12mo ago
you can deploy PgBouncer
Harris
HarrisOP•12mo ago
oh nice is that just built into postgres?
Brody
Brody•12mo ago
no its a template on the marketplace
Harris
HarrisOP•12mo ago
No description
Harris
HarrisOP•12mo ago
nice need to read up on that some more
Brody
Brody•12mo 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
HarrisOP•12mo 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•12mo ago
thats true dont see why you cant use both
Harris
HarrisOP•12mo 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•12mo ago
saw that thread, i unfortunately cant answer it, never used it myself
Want results from more Discord servers?
Add your server