DEV Community

Lakshay
Lakshay

Posted on

From Ghostbusting Tiny Monsters to Resurrecting the Giant

Well, I am not really busting ghosts here although it would be fun to be a part of the original Ghostbuster series.

This one, 2 years later, is about the same side project. It is the story of haunting microservices, deployments, and my heartfelt sad decision to move back to the monolith.

Recap - A series of unfortunate events

The backend of my ECom side project was 6 node apps running Apollo GraphQL servers and another node app running Apollo gateway, to stitch all the federated schemas - or as I would quote "One ring to rule them all"!

Once upon a time I used to deploy these easily when Heroku was free. Its seamless CI/CD pipelines were smooth AF and the cold starts weren't bad either.

So what happened?!

Sauron decided to turn things upside down and Heroku went from free to paid, forcing me to move towards gathering the alliances or thinking about monoliths.

Challenges you ask?!

Managing 7 node servers - even for development locally, was tiring.
Like imagine hitting pnpm start for each server one by one, I found that tiring. Of course, I could have written a shell script but... never mind.

This was just a small thing. The bigger one was deploying this. This being just a side project, a playground for me to tinker with my ideas, I did not want to shed some bucks around.

So I started exploring the possible free solutions.

Possible solution I explored?

I did find multiple free services that were allowing me to do something similar, but there were hurdles, hurdles that got me thinking - "I shall not pass!"

All the free services are limited to a very low grade CPU which was not able to run all the 7 servers. Deploying them individually was another idea but the cold starts were bad, like reeeaaaallly bad, that many times API calls used to fail because response time was too much for our dear gateway to wait for.

Sweating on this for days, I got an idea - what if I could bind them all under one shell! Yes, the glorious concept of monorepos often allows us to ship and manage projects seamlessly.

But as Uncle Ben said - "with great powers, comes great responsibility", and with monorepos comes heavy machinery.

I used Vercel's Turborepo for this task since that is what we use at work. It did make my job easy for local development, I was even able to set up a workspace-global prisma instance which was much much easier than maintaining the schema for each service using Mongoose.

But as I mentioned above, free services don't give a strong CPU, running 1 server wasn't easy, imagine running 7 under a shell. Kaboom!

...and that's what happened. Some would start and some would not since RAM was not sufficient either.

So how will Frodo reach the fires of Mount Doom?

Since I did not want to pay, and being the only dev in a side project, all of it was just killing the fun, and the only way forward I could see was doing things the old way.

So one Saturday night at 00:00 I took out my favorite Starbucks' mug and poured me a noice freshly brewed cup of french press, and forked a new branch from main and named it project-knightfall!

First of all, if you know what is Project Knightfall, we should be friends!

I took the plunge, re-wrote a lot of it, deleted a few things, and was able to get the backend up and running in a few hours.

I deployed it on - shoutout to - render.com and even though the cold start is really annoying, but things were finally working. No calls were failing, schema operations were working fine, and post cold start, response time was also good.

Conclusion

Coding is fun, building is fun but sometimes making such small decisions can ruin multiple nights and lives.

For let's say a hobbyist it is annoying to encounter such challenges. But you definitely learn a lot, after all your mistakes are your best teachers.

It is good that we have new SSR frameworks like Remix and Next which do eliminate such issues to some extent(?) but - and I am frontend guy - building a federated GraphQL backend was super cool and I wanted to do a lot more with it.

Do you think, I should pay and get back on it? Do you have such stories to share?

Drop in the comments and say hi!

Top comments (0)