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

120 messages · Page 1 of 1 (latest)

fallow trail
#

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.

rancid kayakBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

solemn heronBOT
#

Project ID: N/A

fallow trail
#

N/A

pastel onyx
#

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

fallow trail
#

oh dope

#

ty

pastel onyx
#

no problem :)

soft vapor
#

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

fallow trail
#

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

soft vapor
fallow trail
#

OH wait I'm currently using the TCP proxy right now

soft vapor
fallow trail
#

gotcha

#

so new goal acquired: convert redis to private network rather than tcp proxy

soft vapor
#

just connect to the private network using the correct variable instead

#

use the private url reference variable

fallow trail
#

i see

#

so rather than REDISHOST

#

i just do REDIS_PRIVATE_URL?

soft vapor
#

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
#1176342343826280540 message

fallow trail
#

ohhh interesting

#

so you parse the URL

#

I'm surpised there isn't a native URL option

#

oh wait

#

there totally is

soft vapor
#

doesn't seem to work

fallow trail
#

oh it doesn't?

soft vapor
#

when I tried it will bullmq, it didnt

fallow trail
#

is bullmq ontop of redis?

soft vapor
#

yes, uses the same types

#

on top of ioredis*

fallow trail
#

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

soft vapor
#

do you have that variable referenced on your service?

fallow trail
#

I do

soft vapor
#

referenced and not just copy pasted lol

fallow trail
#

yeah, I used the reference variable UI

soft vapor
#

show code please

fallow trail
#

oh

#

wait

#

haha

#

i changed the variable on prod

#

but my code is on dev

soft vapor
#

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

fallow trail
#

family 0?

soft vapor
#

bullmq just passes it to ioredis, so you can use it all the same

fallow trail
#
// 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,
});
soft vapor
#

do a sanity check variable print?

#

though maybe buns url parser doesn't wanna parse a url with a redis scheme

fallow trail
#

yeah the url logs

#

but doesn't get parsed

soft vapor
#

uncommon bun L

fallow trail
#

hmmm

#

i think i know why

#

i didn't have private networking enabled

#

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 malformed

#

both services need private networking enabled right?

soft vapor
#

even though the private networking enable and disable is in a services settings, it's a global option for the project

fallow trail
#

are these settings able to be stored in railway.toml at all?

#

would be nice to do this through code

soft vapor
#

nope this setting isn't available in a config file

#

but it's enabled by default, so not sure why it was even off

fallow trail
#

i think i had turned it off at some point

#

didn't understand what it was

soft vapor
#

fair enough lol

#

are you using the private network to connect to postgres? (i think you mentioned at some point you use postgres too)

fallow trail
soft vapor
#

and egress reduction

fallow trail
#

true

#

my main thing was scaling

#

I would like minimal setup max autoscale

#

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

soft vapor
#

youre on pro so you get a max of 32vcpu and 32gb of ram

fallow trail
#

👀

#

does it dynamically scale up to that?

soft vapor
#

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

fallow trail
#

gotcha

#

what about connection pooling?

#

if I have 100 serverless functions trying to access it at once that's needed right?

soft vapor
#

you can deploy PgBouncer

fallow trail
#

oh nice is that just built into postgres?

soft vapor
#

no its a template on the marketplace

fallow trail
#

nice

#

need to read up on that some more

soft vapor
#

dont know how well it will work with the private networking though, but im always here to help

fallow trail
#

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

soft vapor
#

thats true

#

dont see why you cant use both

fallow trail
#

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 )