30
53 Comments

Why I run 5 different applications on the same server

I have a 1 vCPU, 3.75 GB memory server on GCP for ~$25/month. I run 2 Node.js backend projects and 3 Next.js applications. I use this server for everything database, Redis etc.,

Why I do this?

There are 2 reasons.

  1. I like to keep the server cost in check and have complete control over the applications I'm running.
  2. When I experiment with different projects, I don't have to spin-up and set up a new server.

As everything is a JS-based application, the memory consumption is not much, and I believe I can run more JS applications on this server without impacting the performance of the existing apps.

I use several open-source tools for CI-CD, SSL and Webserver. So, everything is automated, including daily database backups after the one-time setup for each application.

This setup may not be ideal for your requirements, but it works out well for my applications.

Shortly, I will do a detailed write-up of my whole setup.

I am eager to know about your server setup, the tools you are using and the incurred costs. Feel free to share those in the comments.

posted to Icon for group Developers
Developers
on March 22, 2021
  1. 4

    Sounds awesome, ping me when you have the writeup, interested to learn about your setup.

    Here’s an article I wrote about my setup:

    Robust NodeJS Deployment Architecture

    1. 1

      Sure thing. The article is excellent. My setup has almost all of the technologies you have mentioned in your article.

  2. 3

    Same here! And good thing, after 7 years building apps that haven't made money, it'd be crazy to pay for a separate instance for each.

    I also really like LXC. I know enough about Docker now that I could probably switch to it, but LXC allows me to work on each app like it's on a separate server, while still giving the root access to do backups and stuff.

    1. 2

      Cool. Containerization is something I'd love to explore in the near future.

      1. 2

        It's getting so easy, too!

        My one vps is like a virtual cluster haha. ssh "jump" machine, web server, pgsql server, and a few apps.

        I even use a LetsEncrypt wildcard cert so I have my own ngrok on it :-P

  3. 3

    I run ~5 PHP apps on a $5 Linode, but there's barely any usage. It can certainly be done.

    I strongly believe in keeping my side projects costs to a bare minimum. My only other expense is a handful of domains.

  4. 2

    That's cool! I was wondering if 2-4 Gb would be enough to run a Tomcat server, NodeJS, and a database. Do you have a caching tier, e.g. Clouflare? Where do you store your files?

    1. 1

      It depends on what your applications are going to do. NodeJS usually consumes less memory unless you plan to do some memory-intensive tasks like loading puppeteer upon HTTP requests, for example.

      I don't have a CDN as of now. I am considering it as I have plans to load a lot of static content on my applications soon.

  5. 2

    Nice post. I do something like that with http://dokku.io/ , to me is the easy way to use Docker. And I use swap to increase de memory. The best 5 dollars of my life. :D

    1. 1

      Dockerization is something I like to learn soon.

  6. 2

    I always say people overdo their deployments. But I still rather separate projects by VMs personally, it's kind of clean. The big saving is to run your database on the same box, which is even faster (no network trips).

    The important thing is to separate the application properly from the rest of the system. I am just writing a book that goes into these bits in detail (rootless services, rootless containers, SELinux). If you have good boundaries, you can easily run everything on the same VM and save $$$.

    1. 1

      Yeah, having the database on the same instance helps. All the best for your book launch :)

  7. 2

    I ran an Alexa top 50k site off of a single t2.small instance on AWS and never saw the CPU go as high as 10%. People vastly over-estimate how much resources their projects will need.

  8. 2

    Did you consider using serverless infrastructure like S3, Lambda, and DynamoDB instead of self hosting everything? I like the pay-per-request pricing of serverless architectures and I wonder if the overhead and cost benefits would outweigh a setup like this.

    1. 2

      I love the idea of doing this. Here are my thoughts:

      • I'll bet for low volume apps, the cost is lower for serverless.
      • Like vicke4 said, I'm also a relational DB guy. I'd drop the DynamoDB part.
      • There's a kind of simplicity in running your own vps. There's also no worry about vendor lock-in.
      • The free tiers (and "founder" credits) can help a ton :)

      While I have a setup similar to vicke4, I'm building vidds.co, and doing renders serverless was definitely the way to go. I start jobs with Fargate right now. The only downside is a 45 second startup time. I plan to switch it to Lambda over time, but the temp storage limits require some serious workarounds.

      It's good to have a hybrid setup - you get to pick and choose while learning and testing!

      1. 2

        Oh yeah, there are also some crazy hybrid options for those who want to dip their toes into serverless or vps:

        OpenFaaS and FN project: Run your own lambda-like functions.
        Dokku: Run your own Heroku-like PaaS on a machine.

        I really want to rework my system to incorporate these tools, but gotta stay focused on what's important - time spent marketing or improving the app that's running fine for now :-P

    2. 2

      I'm more of a relational DB guy. And, I have read somewhere with NoSQL, we can't do join queries and stuff. Hence, I have never tried it.

      1. 1

        This comment was deleted 2 years ago.

        1. 1

          It can get real messy real quick. Structuring can't bail you out in some cases. Let's say there's a common entity to two different entities. I won't want to save details about the common entity in the two different entities resulting in duplicate data.

          I would rather save the common entity in its own table and connect it to the two entities using foreign keys. So, there's one source of truth, and I have the flexibility to use join queries when needed.

          1. 1

            This comment was deleted 2 years ago.

  9. 2

    I'm also using GCP for Newsletterss, but I have Cloud Run instead of a VM, use Pub/Sub for queues, Datastore for the data layer and Go as the main programming language. Firebase Hosting is my CDN and some assets are pulled directly from Cloud Storage (pending to be migrated to a different CDN soon)

    It is an unusual setup, but it was optimized for cost reduction from the beginning. I pay less than $1 a month (yup, one dollar) but it's only about 10k requests per day and most of the cost reduction is due to the services being covered by GCP's free tier

    1. 1

      Interesting, I'm not aware of the capabilities of Cloud Run & Firebase hosting. Will explore.

  10. 2

    I like to roll with either Firebase or serverless usually works well in regards of saving money, as it's pay per use and as long as I don't have much traffic it will be pretty much free.

    Everything is automated here as well plus I get the scalability out of the box.

    If you can live with the vendor lock-in I think this is even better than rolling your own servers but that's just my 2c.

    1. 1

      The scalability part is interesting. This post has several comments mentioning serverless. I'd explore.

  11. 2

    I'm pretty much the same. I have two separate servers at digital ocean for resilience through a load balancer to make updates and patching easier without taking anything offline, but its just 2 servers that run everything, from websites, databases etc.

    If I get enough traffic where it becomes a concern then potentially I'd move a project onto separate servers but not anywhere near that yet.

    1. 1

      Do you mean one of the servers handles all the write requests and the other read requests?

      1. 1

        No, they both run identically so both do read/write, the database does bi-directional replication to keep both servers up to date.

        1. 2

          Could you spare a minute or two to explain how you got the replication working? I tried on MySQL, but it was a bugger to get working smoothly again in the event of an outage. Do you use a third-party app to manage it? (I guess that'll depend on which DB you're using).

          1. 1

            There’s a few different steps involved. I only know the exact steps for Linux but should be the same for windows just config files in a different place. There’s a my.cnf file which on Linux is usually in /etc.

            Most of it is the same apart from two vital parts that need to be amended, the server id needs to be unique for each server and you need to set an offset for auto increment fields. Both servers need to increment by 2 but one server should be offset by 1 and the other offset by 2 otherwise you’ll get duplicate key errors for primary keys that auto increment.

            Once the config is done restart MySQL and then login to the MySQL client and run a change master command on both servers setting the master host to be the address of the other box.

            Maybe https://www.google.com/amp/s/www.digitalocean.com/community/tutorials/how-to-set-up-master-slave-replication-in-mysql.amp can be of help.

            My Twitter dms are open if you need a hand

            1. 2

              Thanks for the info. I'll check into that. Appreciate your time.
              Andy

  12. 2

    I do similar for my project. I have a Linode VPS with 2 gb mem ($10/mo) where I have deployed all of my projects. Currently it have 3 web apps and a bunch of client projects mostly cron jobs.

    None of my projects get a lot of traffic so its working fine till now.

    1. 2

      Great! Also, it depends on what you run, right? Node consumes less memory comparatively.

  13. 2

    Well done, balancing costs with productivity and product goals is an important activity for an entrepreneur.

    How are you managing your ports? Are you redirecting to different ports depending upon the application or do you have a single service to route to different applications depending upon the paths of a single domain?

    1. 2

      Yes, I run different applications on different ports. I just proxy pass based on the server name. I will explain the whole setup in detail in a blog post soon.

  14. 2

    What drives costs up, even on a small scale, is data processing with a lot of disk writes and network traffic to fetch data. Responding to user actions on a web app is very cheap when you don't have many users.

    1. 1

      I believe I have to experiment more to comment on this.

  15. 2

    I completely agree that minimizing server costs should be one of the higher priorities in the beginning. It really sucks your energy if you're paying a $100 cloud build the first 12 months when you're barely generating any traffic or visitors.

    With that said, minimizing server costs does not always equal the most simple server setup. For example, imagine you're building a project that consists of a website and a web crawler.

    The optimal solution might be a small instance for the website, but an horizontally scalable solution for the crawler. Suddently we might be looking at a solution that include private networking, kubernetes, containers, auto scaling, multiple instances etc, and this might be the "most cost efficient" solution since it would allow us to increase our costs as the crawler runs, and reduce it when it doesn't, while still keeping the website the same.

    1. 1

      Exactly, the provisioning of servers must be based on the requirement. There's no one size fits all.

  16. 2

    Awesome, love this minimalism. If you want push-to-deploy but self-hosted on your own server check out Piku. I am running more than 20 sites on a $10/month Digital Ocean box with this.

    1. 4

      Can voucher for CapRover! Switched over from Heroku to my own self-hosted PaaS and have been using it for the past 3 months.

      1. 1

        At first glance, CapRover seems great! Thanks for the suggestion. Will explore more about it.

    2. 1

      woaa looks super nice. Thanks for that.

    3. 1

      How does it differ from a classical remote git deployment?

      1. 2

        I'm not sure what you mean by a traditional remote git deployment, but the way Piku works is:

        • you add a git remote called 'piku' pointing at your piku server
        • you create a Procfile with the command for running your server, and static paths
        • you create an ENV file your domain name and any other vars

        after that whenever you git push piku your new code is deployed, any setup (installing deps etc) happens, an SSL cert is provisioned, and your changes are live on the internet.

    4. 1

      Piku looks solid. I will give it a try in future.

  17. 2

    What's the reason for hosting nextjs on it over say Vercel?

    1. 1

      3 reasons,

      1. Some of my API routes fetch data from Redis. If the Redis runs on the same server, it makes things a little easy.
      2. Vercel comes with certain limitations https://vercel.com/docs/platform/limits.
      3. As I have a server already, I can save $20/month.

      At one point, I considered moving my Next.js projects over to Vercel for their "Push to deploy" feature. But, I was able to implement it myself using GitHub actions.

      1. 1

        I am like you, I like to run things, but sometimes saving $20 means spending 3 hours a week in tweaking things that can be bought rather cheaply. Depending how you value your time, it might not be worth it. On the other hand.. it's fun to roll your own.. at least for me.. ;)

        1. 1

          You won't have to tweak every other week, right? You set it up once, and it is on auto-pilot.

      2. 1

        Very cool, did you see any performance tests for self hosted vs Vercel?

        1. 1

          I haven't so far. I believe Vercel will perform better because of Edge network.

Trending on Indie Hackers
I spent $0 on marketing and got 1,200 website visitors - Here's my exact playbook User Avatar 41 comments Why Early-Stage Founders Should Consider Skipping Prior Art Searches for Their Patent Applications User Avatar 22 comments I built eSIMKitStore — helping travelers stay online with instant QR-based eSIMs 🌍 User Avatar 20 comments Codenhack Beta — Full Access + Referral User Avatar 20 comments Veo 3.1 vs Sora 2: AI Video Generation in 2025 🎬🤖 User Avatar 18 comments Day 6 - Slow days as a solo founder User Avatar 13 comments