Lessons from Building an App with Rails 5, PostgreSQL, and Dokku

DineSafe by Jon Lim

For the past two weeks, I've spent much of my nights (and early mornings) to chipping away at a fun little project for myself.

Here it is, check it out: DineSafe by JonLim.ca

For the curious, here's the stack for this:

  • Rails 5
  • PostgreSQL
  • Bootstrap 3
  • Dokku
  • DigitalOcean (Referral link!)

While it's still a work in progress, I wanted to share both the app and a few little lessons I learned from building this project.

Local Performance != Remote Performance

Performance on DigitalOcean

One of the bigger parts of my DineSafe app is that it takes a big (60mb+) XML file, parses through the nodes and performs an action for each new data found. Locally, it took about 20~ minutes for each file, but my database would be chock full of delicious data afterward.

Things were good. And the things were on fire.

When I pushed my project for the first time, the way that I would kick-off the parsing of the XML file was to (foolishly) use a file select and upload it. The app would write the file locally, parse its way through it with Oga, and create the records for the database.

Basically, what was a 20~ minute task on my local machine, which is a relatively beefy Mac Mini with plenty of RAM and CPU to spare, would cause this Heroku instance to come to a crawl.

There is much more to this, which is enough for another post, but remember: what works well and works quickly for your local development machine does not always translate into the same performance on your server.

Dokku is Amazing

Digital Ocean Dokku One Click Install

Initially, I was fiddling around with a Droplet, creating the necessary infrastructure for deploying a Rails app with Capistrano.

Headaches. Maybe because I was impatient, but after a friend suggested using Dokku on the Droplets, I never wanted to turn back.

DigitalOcean has the great option of one-click apps for creating Droplets, and is what I chose to use, which installed a configured Dokku 0.6.5 on Ubuntu 14.04.

Once you've got a better understanding of how to set up apps on Dokku, deployments become very Heroku-like: git push dokku master and we're off to the races.

Use New Relic to Monitor Performance

New Relic Overview

I'm still learning what all of the numbers mean, but it felt prudent and proactive to start taking a look at how my app is performing, and the easiest way was to set up New Relic to watch the different environments.

With New Relic, you can quickly take a look at the average response time for different transactions, time consumed by various database calls, time consumed by external data calls, among other things. I also installed their Server Monitor directly on my Droplet in order to understand the load that the server itself sees over time.

Going forward, as more features are added DineSafe, and more apps are deployed to this Dokku Droplet, all of these numbers will be great for understand where optimizations can be made.

Secure Your Server, Keep It Updated

Being new to hosting my own apps (as I had always used Heroku), I was a bit clueless about what to do secure and maintain something like an Ubuntu server.

In my case, my Droplets were running Ubuntu 14.04, which has a huge treasure trove of tutorials, like this fantastic tutorial series on setting up your server, securing it, and additional recommended actions.

If you're like me and have never maintained a server, definitely go through this guide. And continue going through it until it feels like second nature.

And for goodness sake, sudo apt-get update && sudo apt-get upgrade, often.


While this is a relatively general post about things I learned while building my personal DineSafe app, this definitely is not the last post involving coding, data, or side projects!

Stay tuned, thanks for reading.