When I started my blog a couple of months ago, I was in a hurry to get it started so I could start writing. I went with one of the easiest and cleanest blogging platforms I could find, Ghost. I like how simple it is; you just focus on writing, you don't waste time with lots of tinkering, which I have done in the past with Wordpress. But now that the blog is going well, and I have consistently pushed out content for a couple months, I think it is time to build the blog from scratch.
There are many great tools I can use, and many many different routes I can take. But I have decided on a serverless architecture. I have three main reasons for serverless over a traditional web app with an API and front-end server.
The first is price, with a serverless architecture you are only charged for the time your functions are running. That means if you just get 5 views in a day your cost will be virtually nothing. And with AWS Lambda, the serverless infrastructure I will be using, the first million requests per month are free!
The second main benefit I see from going to a serverless architecture is the lack of maintenance. Because I am only building functions and not worrying about the operating system or web server, I am free to push up a function and basically forget about it. There are no monthly server updates I need to make or worry about my SSL library being out of date. Amazon will handle all that for me, leaving me more time to do fun things like write code or blog!
The final main reason I switched to serverless is scalability. Yes, if you do it right you can scale a website without serverless architecture. Products like AWS Elastic Beanstalk can handle that quite efficiently. But with Lambda, absolutely everything is dealt with for you. It can scale from 2 requests to 1,000,000 without any issues because of AWS's massive infrastructure.
How I Am Doing It
I have been wanting to do this for a while, but never got around to it because my primary language for personal development, Golang, was not supported. But recently Amazon added support for Golang. After doing some research, serverless.com is the easiest way to build out a whole API in one repository using the serverless architecture. An example of how this will work is here.
I will create the blog API similar to a normal API, but each function needs to be compiled into its own binary which can be easily done using a Makefile. If you're unfamiliar with Makefiles, I'd recommend this article.
I have been leaving the frontend out of this post so far, but I will also be running the frontend without a server. I am building the frontend with React and will use webpack to compile my code into a
dist/ folder. From there I will use Scotty.js to push the folder to AWS S3 where it can be exposed to the public, and AWS CloudFront as a CDN. Doing this will make deploying the frontend a breeze and allow for incredibly fast load times.
Moving from a service like Ghost to a made from scratch front and backend will be interesting. The most time-consuming part of it for me is building out the frontend, but I think within the month I will have it good enough for my needs. Although all of this is overkill for my little blog, I am excited about the learning experience as this will be my first fully serverless web app. This being said I can think of many many uses for a monolith and/or microservice architecture but I believe adding some serverless architecture to projects can make lots of sense, and ultimately save time and money.