R
Railway

✋|help

Ideal way to compose and manage a full stack app?

X.xevion9/4/2023
Railway doesn't really seem to be exposing an example of how one could/should compose a full stack application. It provides all the services, but it doesn't seem to detail on how you'd put them all together.

For example, Django is a great backend, but if you want a great frontend - you'll need something like React, built with Vite, perhaps.
But how is one supposed to build and serve your frontend files? Nginx comes to mind, serving static files for your frontend, and proxying all API requests to Django.

But how is this to be done? Most people use Docker Compose, which Railway doesn't support at all. Dockerfiles are cool, but I'm struggling to find any examples that include more than a single service. There's no Django + Postgres + React + Nginx example - there's just Django. Or Nginx. Or Django + Postgres at best; which isn't hard to figure out at all.
X.xevion9/4/2023
N/A
Any sort of blog posts, discussions, or docs, if I missed them, are what I'm looking for. Templates, dockerfiles also work - but I'm interested in a more generalized example - I really don't care if it's Django and React proxied by Nginx, or Axum and Svelte proxied via Traefik.
X.xevion9/4/2023
Does this require more than one repository? I don't like doing multiple, but I have very little experience with monorepos, which I've read that Railway provides some of?
Trying to understand what I'm looking at; literally never seen anything that you just linked 😓
Bbrody1929/4/2023
the public project does use 3 separate repos, only because it's comprised of 3 railway templates, but you absolutely could do this in a monorepo format
X.xevion9/4/2023
The style of repo I'm looking for is
/client
/server
README.md
Dockerfile

But I understand limitations may apply and some other format may be forced. It's just what I'm used to, personally ;p
Bbrody1929/4/2023
you wouldn't have a dockerfile in the root, you would have a dockerfile specific to each service type
otherwise that's totally doable on railway
X.xevion9/4/2023
Oh, okay. So, to confirm what I'm reading on the docs, you add two services, change this
X.xevion9/4/2023
And have dockerfiles in each?
Bbrody1929/4/2023
correct
X.xevion9/4/2023
Are three services required for proxying purposes? Or two? I'm wondering why there are three, when it seems only two things exist (a frontend, and a backend)
X.xevion9/4/2023
My thought process is, "client" repo receives all requests, and proxies everything in /api to the backend service (perhaps using the Railway private networking)
Bbrody1929/4/2023
that's exactly what that project you are looking at is doing
mysite receives all traffic, proxys requests to /api/* to the backend, and everything else to the frontend
all through the internal network, the frontend and backend are not exposing themselves to the public
X.xevion9/4/2023
So there's two Caddy services? Feels like more overhead when Caddy could be acting directly on the files in the frontend
Bbrody1929/4/2023
caddy is both a proxy and a file server
caddy is used in the frontend to serve the frontend site, and caddy is used on mysite to proxy incoming traffic to it's destination
X.xevion9/4/2023
Yes; can't it do both at the same time?
Bbrody1929/4/2023
totally could, wanna see an example of that too?
I do prefer keeping them separate when possible though, it's "cleaner" this way imo
X.xevion9/4/2023
I suppose it's a little cleaner in a diagram kinda way, but isn't the performance loss pretty bad?
Have to send an entirely new HTTP request just for proxying
Bbrody1929/4/2023
nope, rtt would be around 5ms on average between the proxy and the frontend or backend
X.xevion9/4/2023
Really? That's crazy.
Not that I don't believe you, but how do you know?
Bbrody1929/4/2023
it's an internal network after all
X.xevion9/4/2023
Does it consume more bandwidth or resources, besides memory; which should be pretty low given that it's just a webserver?
Bbrody1929/4/2023
example test results of a http get request to another internal service
X.xevion9/4/2023
I suppose I could spend several hours working up a benchmark with/without Caddy proxy :no_think_empty_brain:
Bbrody1929/4/2023
well given you arent charged for network usage on the private network, that wouldnt cost any extra, but yes you do pay for running two caddy services
you tell me what you want to know, theres a good change i already have testing in place for it
X.xevion9/4/2023
I mean, transferring a decent file (1MB+) with and without a middleman Caddy server, averaged over a decent number of requests (say 100, or 1000). Compare.
Bbrody1929/4/2023
you can check the mem usage in the services of that project, in fact they are all go services, so my estimated usage for that whole project is 50 cents
X.xevion9/4/2023
I have fair confidence though in what you say though; Railway in my opinion is not the platform to be building a service that cares about < 10ms delays. I use it for putting my silly little projects on it, and learning how to build cool shit.
If said silly little project blows up, it should not be hard to move it onto a AWS instance that will cost me several car payments per day to run.
Bbrody1929/4/2023
i could test that, i do have a service in place to generate files of any size, id just need to slap a caddy proxy in front of it
X.xevion9/4/2023
Caddy is very cool though. I have never heard of this alternative. I've been tearing my hair out over Nginx lately.
Bbrody1929/4/2023
well thats why i choose caddy to do this, i believe its more user friendly than nginx
heres the caddyfile for the proxy
https://github.com/brody192/reverse-proxy/blob/main/Caddyfile
X.xevion9/4/2023
One question though; if I wanted to host a frontend and a backend with Caddy, could I host one service in the root, and the second in, say, /server?
Bbrody1929/4/2023
yes but youd need to do some file whitelisting, though im not sure why youd want to structure your repo like that
X.xevion9/4/2023
e.g.
/client
  ...
/server
  Dockerfile
Caddyfile
Dockerfile <--- Builds frontend, serves with Caddy, proxies /api to backend
Bbrody1929/4/2023
why not just
/server
/frontend
/proxy
README.md
X.xevion9/4/2023
That's if I wanted to do a three service setup. I'm still curious about a two service setup.
Bbrody1929/4/2023
and i dont know if youve noticed, but the backend and frontend are not build with a dockerfile
X.xevion9/4/2023
wym?
Bbrody1929/4/2023
that was dumb
X.xevion9/4/2023
X.xevion9/4/2023
Says the builder was the Dockerfile here, too
Bbrody1929/4/2023
i know, my mistake
X.xevion9/4/2023
Oh, okay. :p
Bbrody1929/4/2023
i think
X.xevion9/4/2023
I'm okay building/not building with a dockerfile, but for more tuned setups like this, I might be okay with skipping Nixpacks for my own setup.
Bbrody1929/4/2023
though I absolutely could do the proxy with nixpacks
X.xevion9/4/2023
Yeah, I assume Caddyfiles are autodetect with nixpacks?
Bbrody1929/4/2023
no they arent, not at all
X.xevion9/4/2023
Oh; then how would nixpacks do the proxy?
Bbrody1929/4/2023
as ive come to learn, you can do a whole lot with nixpacks
so give me a sec
X.xevion9/4/2023
:Ok:
Bbrody1929/4/2023
providers = []

[phases.setup]
    nixPkgs = ['caddy']

[phases.fmt]
    dependsOn = ['setup']
    cmds = ['caddy fmt --overwrite Caddyfile']

[start]
    cmd = 'caddy run'

this doesnt use any providers, we manually install caddy and run it
X.xevion9/4/2023
Interesting.
Bbrody1929/4/2023
i just wrote that off the top of my head, though i dont see why it wouldnt do what i want
X.xevion9/4/2023
I don't know that I have anything more to add to the conversation, but this was really enlightening from start to end.
Thanks for the examples!
Bbrody1929/4/2023
no problem, i got all the examples
if you ever need any help structuring your app on railway or even setting up caddy just ask!
X.xevion9/4/2023
Will do!
I forgot if it said a way to mark this as solved, or where to press or w/e. If you can do it, please do. Or tell me. Whichever.
Bbrody1929/4/2023
you can use apps > mark solution in the context menu of a message, but in this case where we are mostly just chatting and I've answered all questions, I will just mark the entire thread as solved by editing the tags
and I have already done just that
X.xevion9/4/2023
Cool! The Discord apps thing is new to me lol.
Bbrody1929/4/2023
no worries!

Looking for more? Join the community!

Recommended Posts
Usage estimatesSo im trying to make a simple project using a MySQL database and im trying to figure out how much itMy website is not running due to SSL supportThe browser is showing following message: alfajr.edu.pk uses an unsupported protocol. ERR_SSL_VERSIPricing/resource questionHere's a silly question, how should I decide on what plan to use for hosting? I'm pretty dumb at thiAny solution for Typebot 2.17? Still showing server errorAPI response timeHello! I am looking for the best place to deploy my API and I currently have the "Pro Plan" package.Added a template as CRON service and it shows "Your project has no deploys"I added this template to take automatic DB backup - https://railway.app/template/UGKaB8 I added a Cservice in only one environment?Is it possible to have certain service(s) only in specific environment? I am making a new cron job tdeploy not building uptried it already three times now canceled teh ones before at around 5 mins the third is currently atError connecting to Redis database.As shown in the picture, I cannot connect to the database. I do not know the reason, but I think thaLove Railway but confused on pricingHello! I’m currently using the free trial of Railway for a service, and I’m loving it. As my free trWhat I thought was a simple python upgrade broke my deployed flask service. Need some help.Project ID: b06af9f3-d9c9-4d4c-a74f-c5521f149984/service/872870dd-f98a-486c-9f14-09fcd5bc43e5Question regarding pausing subscriptionHi there! I’m relatively new to railway, I’ve registered before the pricing change and got verifiedError with discord bot using go and pythonI am new to asking questions in a place like this, so please forgive me if there are any problems ISelenium driver unable to fetch page in Selenium deploymentI am facing an issue while deploying my app via railway.app. 

Here is the description of the app: I up loaded Tesseract-OCR Folder on gitup but on railway cant't findpytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your PATH.How to enable Email on CloudflareI have a React/NodeJS app running on Railway using a custom domain. Cloudflare DNS records have beeUnused DatabaseHey, I have a backend talking to my express server. Both are hosted on Railway. The thing is I am noRun a command in production (rake)Hi there, newcomer from Heroku here — I need to run a command in my production environment (in this don't remember how to log in into my accountI need to access to my account to suspend something, but I faced this notification (in the picture) Run a daily rails rake script on cronHi I have an app that does a daily update to the data in the db. Currently using railway I run this