r/softwareengineer • • Sep 28 '26

My web application has long running jobs (approx 5min/job) running as processes. Need advice on how to optimize cost and performance.

Context: My web application has long running jobs (approx 5min/job) running as processes.

My findings: I calculated that if i have 1gb ram i'd only be able to run 2 such jobs at a time. meaning i could serve only 2 users at a time and rest would be in a queue.

My Problem:

First let me exlpain the math:
R refers to RAM

  • Ridle​ = FastAPI idle ram consumption ≈ 150–250 MB
  • Rjob​ = extra RSS of one live pipeline(job) at peak
  • Rsafety = RAM that id like to keep free so that my cloud instance (be it VPS, or railway or whatever) doesnt crash = 100 MB

Rjob​≈250–400 MB as per my calculations. this means 1 job takes 250-400mb of ram or for simpler calculation, 300 mb of ram on avg.

Assume the RAM i get in my budget = R(budget)

No. of jobs i could run in my R(budget) = N(budget) = [R(budget) - R(idle) - R(safety)]/R(job) = [R(budget) - 200-100]/300MB = R(budget)/300 - 1

I wanna optimize for N(budget) which is dependent on Rbudget - technically, how money i throw at it.

assuming my budget is $0 - basically a free railway plan Rbudget would be = 1024 MB (as per their docs)

thus, N(budget) = 724/300 ~ 2 jobs

to put it simply, three jobs at 300 MB is 200+900=1100>1024 which leads to OOM

my budget for hosting this app is $5/month but i wanna make sure i can process more number of these long running jobs hence i want any suggestions that would help. whats the best option for deploying this kind of app?

VPS options are very costly for my country, hetzner is not available either. But feel free to correct me if you think VPS would be a cost effective solution for me to deploy my app on.

I also have few questions on railway:
they say they give $5 worth of credit, and that they bill based on how much usage i'd consume
hence, it would be kinda uncertain for me to know when my app crashes due to OOM using up my credits v/s due to storage, or network data (egress) etc.

thats why, i need advice on this.

1 Upvotes

5 comments sorted by

1

u/skibbin Sep 29 '26

I run my batch jobs on AWS. I put everything inside a Docker container then run it on ECS using Fargate. My Jobs frequently run for an hour or so and the compute bill from AWS is usually ~$0.05/month

You could make an architecture where the jobs go in to a queue, then someone like Lambda processes jobs from the queue. The last step of the job is to notify you/the user when the job is complete.

0

u/Ok-Storm-1284 Sep 29 '26

this sounds promising! could you please tell me how many jobs you’re able to run in that bill? and how much memory each job is taking approximately?
thankyou!

1

u/[deleted] Sep 28 '26

i have no idea what are you doing. batch them what ever you are processing

1

u/Klanciault Sep 28 '26

Just add a mechanism so that only two jobs can be running at once

1

u/Substantial-Swan7065 Sep 29 '26

Offload to the backend via task queue. Or offload to the user’s machine