See All Posts

How I host my SaaS for FREE!!

Discover how leveraging AWS's Free Tier can significantly cut down your startup's operational costs, enabling a smooth sail through the early-phase financial crunch.

Photo by Ales Krivec on Unsplash

Every entrepreneur knows the challenges that come with launching a startup. One of the most significant hurdles can be managing operational costs, particularly when hosting your service. This challenge is even more visible at the initial stages, where you either work on building an MVP or still need to secure paying customers to cover the costs. Financial constraints during these early phases require innovative solutions to minimize expenses while maximizing value. As the founder of a startup myself, I was always on the lookout for cost-effective solutions to maximize efficiency without compromising on quality. That’s when I stumbled upon a gem - utilizing AWS’s “Free Tier” to host my startup’s platform for a year at ZERO cost!

Most of you are familiar with AWS, but here's a brief overview for those who aren't. Amazon Web Services (AWS) is well-known for being a dependable and powerful platform catering to various hosting needs. There are various platforms available for hosting a website, such as Heroku or Netlify. However, these platforms might not be the optimal choice, especially for those operating a software service. They lack the required flexibility to tailor the hosting environment to your specific needs and the architecture of your service. This limitation can be a significant drawback, especially for startups aiming to offer a seamless and customized user experience.

Also, I later discovered the AWS credits for startups, a resource that many, including perhaps yourself, might have at hand, thanks to a variety of channels. However, leveraging these AWS services conserves these valuable credits and effectively extends your startup’s financial runway! Let’s be honest, who doesn’t like free stuff?

The Magic Combination: AWS Lambda, S3, and RDS

AWS Lambda is a service that allows you to run your code without provisioning or managing servers. When coupled with S3 storage and RDS (Relational Database Service), it can create a powerful, scalable, and cost-effective solution for startups. This article will primarily concentrate on the AWS Lambda function, as it's commonly understood that the AWS Free Tier already offers substantial storage and database capacities at no cost.

Amazon's Simple Storage Service (S3) grants users 5GB of storage. Additionally, the Relational Database Service allocates 20GB of storage, accompanied by a diverse range of database options, including MySQL, MariaDB, PostgreSQL, and SQL Server. The setup and utilization of the mentioned resources are pretty straightforward. Hence, we’ll center this piece around Lambda!

AWS Lambda and the Cold Start Problem

For those familiar with AWS offerings, you’ll know that AWS Lambda is an event-driven, serverless service. It supports many programming languages like Python, PHP, GO, Ruby, NodeJS, and more. To use the service, you must create a function that fulfills a task. After uploading your function, Lambda will automatically generate an endpoint for you. Each time this endpoint is called, it triggers the execution of the mentioned function. It means the function is always on standby, ready to load a snapshot of the defined environment and execute the code when needed. It’s great because you will only pay for the time you use the CPU cycles! One of the advantages of using this structure is that you could take advantage of AWS’s “Free Tier” promotion, and if you find yourself constrained, transitioning to another service is a straightforward option. Since you don’t need to do additional coding to use Lambda functions. However, it’s not all sunshine and rainbows!

If you know the Lambda function, you might know. It does have a 'cold start' problem! Meaning that the instance can get terminated after a period of inactivity. Suppose the service receives no requests for some time. In that case, the new/next user will experience a delay of approximately 10 seconds (or even more) before the instance becomes available again and sends a response. This could spell disaster for a startup aiming to establish a solid online presence. No worries though, as there are ways around it! Check out Nixie Social.io, which is built using the same technology stack. You can register an account and dive into the dashboard to personally experience its level of responsiveness.

Now that I am done with introducing the required services, let’s talk about some specifics and how it’s possible to use them in practice. Navigating this can become a bit tricky, especially if your choice of programming language differs from mine — I primarily use Python/Django with the Zappa framework for most heavy lifting. However, numerous options are available for deploying other codebases, such as Bref for PHP-based applications. Additionally, I will share my experience using this approach for the past few months and the challenges I faced with possible workarounds that I came up with!

Introducing Zappa to the Mix

Zappa simplifies the deployment of serverless Python applications on AWS Lambda. In simple terms, consider it a cost-effective, maintenance-free hosting solution specifically designed for Python applications. Zappa ensures scalability at a fraction of conventional deployment costs. It sounds impressive, right? But, how does it work?

It is a framework that will transform a Django or Flask backend into a Lambda function. The entire process is automated! As a cherry on top, it also schedules wake-up requests to ensure the server remains active and effectively eliminates the cold start issue.

The free tier offering a generous 1M free requests per month provides a solid foundation for startups to build and scale their digital platforms without incurring additional costs.

Lessons Learned

By now, I hope you're motivated to experiment with Lambda functions! So, let's dive into some useful tips that I've tried. These might save you some time!

1. Trigger Wake Up Calls

While Zappa schedules regular wake-up calls, I occasionally face unexpected downtime. To tackle this issue, I created an endpoint that returns nothing; it is only responsible for waking up the server. This endpoint was hooked on the first input fields of the forms, such as the register and login pages. (the ones that require database access) By doing so, I ensured that the server was up and running by the time users finished filling out the rest of the form.

Fortunately, our frontend won't experience significant disruptions, as our landing page typically doesn't depend on backend data. This is also true for my blog page, which employs Nuxt-Content, known for its static nature.

2. Docker

While Lambda functions offer numerous advantages, there's a drawback worth noting: you won't have direct access to the environment for custom configuration. An excellent practice to navigate this limitation is to use Docker as your local development environment. Docker provides a perfect solution, especially when leveraging readily available docker images replicating the Lambda environment https://hub.docker.com/r/mlupin/docker-lambda. You ensure that the packages you intend to use can seamlessly integrate, allowing for a smoother and more efficient development process.

3. Cronjobs

One feature you'd undoubtedly miss when working with Lambda functions is the ability to create Cron Jobs for automating tasks. However, there's no need to worry because Amazon EventBridge offers a solution called "API Destinations." This feature makes it easy to invoke a Lambda endpoint. Just be aware of this service so you won't seek external tools or solutions to accomplish the same task as I did.

4. Django Tutorial

Lastly, if you plan to use this stack, do yourself a favour and follow this tutorial by Edgar Roman: https://romandc.com/zappa-django-guide/. It is designed for Django applications, but most content is easily transferable. I wish I found it earlier. It starts from the first step, setting up your environment, connecting your application to the database and S3 to more complex configurations like security measures.

Final Thoughts,

Navigating the financial constraints of launching a startup requires creativity, innovation, and patience in identifying cost-effective solutions. By leveraging AWS’s free tier and integrating the Zappa library, I managed to host a sophisticated, responsive, and reliable platform without spending a dime or using my AWS credits. The Amazon free tier is accessible to new accounts for 12 months. So, remember this for your next service launch!

by Ala, 22-Oct-2023