The Stack - Reliably Deploying Rails Applications: Hassle free provisioning, reliable deployment (2014)

Reliably Deploying Rails Applications: Hassle free provisioning, reliable deployment (2014)

2.0 - The Stack

Overview

The stack used for examples in this book is just one of many possible configurations. I’ve picked a combination of components I’ve found to be most common across clients but it’s intended to be an example only.

If part of your intended stack is not included here don’t despair, all of the general principles will apply.

If you know, or can find instructions, how to install the component in question, the techniques covered for automating with Chef can be adapted.

Ubuntu 12.04 LTS

Ubuntu has become an increasingly common distribution in a server environment over the last four or five years. The primary reason I recommend it is the level of community support available.

The sheer number of people of all abilities using it means that you are almost never the first person to have a particular problem so in 99% of cases, a quick Stack Overflow search will point you in the right direction.

For the renaming 1% the community is extremely friendly and helpful.

Nginx

Nginx is a web server and reverse proxy known for its high performance and small memory footprint.

A key benefit of nginx is that due to its event driven architecture, it’s memory usage is extremely predictable, even under heavy loads. This makes it ideal for projects that may begin on a small VPS for testing and grow to much larger machines as they scale.

Unicorn

Unicorn is a web (HTTP) server for rack applications (of which Rails is one).

If you’d like to understand the internals of Unicorn better, I strongly recommend reading the Github article

https://github.com/blog/517-unicorn

on why they moved from Mongrel to Unicorn.

Architecturally, when requests come into the server, they are handled by Nginx which then passes them back to Unicorn which runs the rails application and returns the response.

For more about the benefits of Unicorn vs Passenger and why the approaches are different, see this Engineyard post; https://blog.engineyard.com/2012/passenger-vs-unicorn

Postgresql / MongoDB / MySQL

Postgresql and MySQL are traditional relational databases. MySQL is probably the best known and due to its track record, is a common choice in larger organisations.

Postgresql has increasingly become the default for new rails applications using relational databases, in part because it is the default database supported by Heroku. It’s my preferred database primarily because with the addition of native JSON support it is increasingly able to combine the benefits of a traditional RDMS with those of a NoSQL solution such as Mongo.

MongoDB is a non-relational database, extremely popular when storing large amounts of unstructured data.

Having managed the provisioning of applications using all of the above, the example code includes all three. My personal preference for most applications and the one I have most experience with is Postgresql so this will be used in a majority of the examples.

Ruby (rbenv)

This book covers and has been tested with Ruby 1.9.x and Ruby 2.0.x. Whilst a lot of the techniques may work with more exotic flavors such as JRuby, I have minimal experience with these and so will not cover them directly.

My preference for managing and installing ruby versions on production servers is rbenv. This is primarily because I find rbenvs operation simple to understand (and therefore troubleshoot) as opposed to rvm which I find more complex.

Anecdotally having tried to do a fair few installs of both on new server builds, I’ve had far fewer issues with rbenv than rvm. This absolutely shouldn’t be taken as a criticism of rvm which I use exclusively on my local development machines.

Redis

Redis is an extremely fast key value store. It’s great and very fast for things like caching and api rate limiting.

It has a few gotchas such as its behavior when its max memory limit is reached which are covered in the section on configuring redis.

Memcached

Similar to Redis but entirely in memory (reboot the machine and you lose everything that was in Memcached). Great for caching, and like Redis, incredibly simple to install and maintain.

Why This Stack

These components cover a majority of the applications I’ve encountered over the last few years. I’m generally fairly neutral in the “which is the best stack argument.” There’s lots of other great combinations out there and the concepts in this book will apply to most of them.

This, with an appropriately selected database, is my go to setup for a new project so hopefully it will serve as a good starting point for your projects as well.

Adapting to your stack

If your stack is not covered above, don’t worry. The aim of this book is to show you how easy it is to use Chef to automate the provisioning of any Rails stack, the components here are just examples. By the end of the book you’ll be able to write your own Chef recipes to setup almost anything.