1

I'm planning to host a web application that consists of a Front-end, Back-end (Written in NestJS + TypeORM). This Web application requires a database like many others.
Something I'm struggling with right now is figuring out what's a good way to host my database. My web application has relatively low usage (think 1-3 users during office hours) so there's no real need for some crazy load balancing between N number of EC2 instances.
What I'm thinking of is hosting a singular EC2 instance (probably t4g.nano 2vCPU and 0.5gb ram @ 27.16USD/month) as the backend, but what I'm stumped with is what to use to host my database.
The options I came up with are:

  • Configure TypeORM to sqlite, then store the sqlite file on an EBS volume which is backed up by EBS snapshots for redundancy. This is roughly 2.88USD/month with 30gb storage.
    OR
  • Use a MySQL RDS instance (t4g.micro, 2vCPU and 1GB memory) reserved for a year for a whopping $162USD upfront and $30.42USD/month.

Now RDS seems like it's way to expensive and overkill, but I'm just worried that EBS + SQLite might not work. But (in my very limited experience) it should especially when there's only atmost 1 process reading/writing to it?
So my question is:

  • Would the EBS + SQLite solution work? In the event EC2 goes down would re-attaching the newly-spun up EC2 instance to the SQLite database found on the EBS volume be problematic or could it be solved with a bash script?

1 Answer 1

2

While I have no experience with Amazon AWS, I can tell you this:

  • Sqlite in WAL mode can have 1 writer and an unlimited number of readers accessing the database simultaneously.
  • If you have multiple writers, they just have to wait for each other, but this can be easily handled automatically by having them wait some milliseconds. A web application with a sqlite database can easily support hundreds of connected clients.
  • A sqlite database is just a single file and to "attach" to it you just need to open it when you need. If the drive where it's stored is available when you application starts, it doesn't need anything else to be operative.
  • Of course this means the EBS volume must be connected to the EC2 instance when it starts, but I suppose this is trivial.
2
  • I'm also considering running my own MySQL/Postgres instance instead of SQLite on the EBS instance instead... But I'm not too sure what are the tradeoffs(?) SQLite seems more lightweight and probably supports EBS snapshots in a more straightforward manner(?) (since it's just one file vs having to generate dump files for MySQL)
    – CXY
    Commented Apr 22, 2023 at 1:55
  • Thanks for answering btw!
    – CXY
    Commented Apr 22, 2023 at 1:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.