Reducing COGS of our service
We finally got an MVP of our app up on railway with
one test user
using it, and everything works great. Issue is the cost seems excessively high. We would like to know what this cost is for and what typically makes this cost high, and what we can do to fix it.
Some details:
We use timescaledb: https://www.timescale.com/ for time series data. And our timeseries data is about 1k-5k rows per day for 3 years per user. Of course when i say rows keep it mind timescaledb creates columnar data chunks as i understand it to make it faster to query.
This screenshot was taken today, it is Nov 15th (halfway through the billing/usage cycle).PostgreSQL ++ for time series and events
Engineered to handle demanding workloads, like time series, vector, events, and analytics data. Built on PostgreSQL, with expert support at no extra charge.
14 Replies
Project ID:
aa5f6f94-b4b8-4582-bfda-61de1da9b940
aa5f6f94-b4b8-4582-bfda-61de1da9b940
Another screenshot of usage. You can see when the user downloaded their data.
what backend tech stack are you using? looking at the memory usage, for just 1 user, looks like the code is either not optimized enough/heavy task (that could be handle with queue/workers, whatnot) and/or memory leak are happening
Teck stack is react on the front end (webapp), gateway is our graphql server, and a postgress db. The graphql server has a rest data source class that downloads data from facebook (all text). Stores it in the db. We then query it. But this is without hardly 100 requests to the backend from the react app during that time period.
The postgress db that was costing us a lot was the legacy, I just this morning deleted the legacy postgres plugin as we migrated to the V2. This v1 was what was costing us a lot.
We have data in the new db. and the second image is from our new db (v2). both dbs had the same ammount of data
V2 db was brought online just a few days ago, and so it could also be charging us alot, i dont know. Issue is the memory in the postgres instance. Why is our postgres instance consuming so much RAM when there is only .02gb of egress and 0gb on disk. I am just trying to wrap my head around this (legacy db)
what is your idle memory usage for your react app?
are you connecting to the postgres database exclusively over the private network?
the legacy postgres database was pg14 and the new v2 database is pg15, so I wouldn't say the new databases use less memory
@Brody Here are the detailed stats for all services. I deleted the legacy db yesterday which its stats are pictured in the original post. We have done a lot of deploys in the last few days. But whats hard is to determine what is costing us on
RAM
and Egress
.
WebApp is a react app using vite, antd, xstate, and some images (10-20).
Gateway is our Apollo Graphql api that WebApp interacts with.
Postgres is our PG db with timescale db and we might have 1,000-5,000 rows per day (for historical 3 years) per user, we do employ a number of indexes.
With one active user atm (pre-alpha launch).
I would like to understand in detail what could contribute to RAM
and Egress
usage for each of these services. Those are our largest costs by far.
are you connecting to the postgres database exclusively over the private network?No, not yet
For instance we are using the same RAM and 10x Egress as the "Growing SaaS" example. We have one user.
Have you looked into tuning Postgres? https://www.postgresql.org/docs/current/runtime-config-resource.html
PostgreSQL Documentation
20.4. Resource Consumption
20.4. Resource Consumption # 20.4.1. Memory 20.4.2. Disk 20.4.3. Kernel Resource Usage 20.4.4. Cost-based Vacuum Delay 20.4.5. Background Writer 20.4.6. Asynchronous …
I had not no, so if this was a baseline and would not change significantly with 5,000 DAU then I would say this is not an issue. The issue is I don't know if its a baseline or if the RAM and Egress will exponentially grow with more users. Do you have any insights into this?
Have you considered simulating more users on the app?
that would answer your question. The best answer you’ll get is to try it out for yourself
Great idea, thanks 🙂 yeah i will do this of course, in the mean time I was wondering what could cause the app to use so much RAM and Egress with practically no load. Thanks adam!
The egress could be your database, are you communicating with it over public or private networking? If public, that’s the issue.
As for RAM, databases use a constant, generally large amount of RAM
I'm gonna attack the low hanging fruit, how are you currently serving the vite app? looks like it's currently sitting around 80mb? if it's just a client side rendered static single page app, that memory usage can be improved