Building a Web Backend from Scratch

I built the backend for my last project on Heroku using Sinatra. It was great; I got to learn about Ruby and a new web framework and it was a very stable and fast API.

I’ve been thinking about what to use for my next project when I saw Marco’s Web Hosting for App Developers and the ensuing discussions among developers on Twitter. After giving it some thought I came to the conclusion that I could probably learn alot by self-hosting the backend myself. Maybe I can even build something as stable and reliable as what I built on Heroku?

Rebuild, Rebuild, Rebuild

I made the decision up-front to script the entire process of building the server. This way, in the event of a network outage at Linode or in the unlikely event that my app comes under heavy load, I can add new servers in a matter of minutes.

My current scripts do the following:

  • Setup SSH keys and disable SSH password authentication
  • Setup firewall, leaving only ports for my application open.
  • Install git, postgres, golang, and other software used by my application.
  • Configure postgres and golang
  • Checkout the application code from my repository
  • Configure it so that it automatically starts when the system reboots.

Did I miss anything?

Another thing that I do to make sure that my scripts are always in working order is to rebuild the server every time I make a substantial change to the script. Also, I completely rebuild the server every evening I sit down to work on it. This leaves me feeling pretty confident that I can quickly recover from a serious outage.

Now, you might have noticed that I mentioned golang above. I’d originally planned to use Flask, but as I already have some experience with Python, I chose Golang so that I can learn something new. The dowside of this will be that Go isn’t as widely used, and I will be navigating uncharted water without the usual wealth of online sample code and SO Q&A. Still, my early impressions of Martini + Golang are very positive. I’m hopeful that I can get everything working withough too much headache.

Next:

I need to setup automatic database backups. I’ll probably use a cron job that automatically sends raw backups to Amazon S3. Also, I’d like to support HTTPS for all API calls. Since I’m just building a web API for my own app, I can just be my own Certificate Authority and issue my own SSL certificates and keys. Any problem with that?

Have any comments or suggestions? Let me know.