🎉
CockroachDB 1.0 is now available! Get more details in this blog post.

Hackathon Wins: My Experience With CockroachDB at NWHacks 2017

After winning the Best Node.js App using CockroachDB prize at NWHacks 2017, University of British Columbia student Trevin Wong writes about his experience with the database at the March event.

As I awoke to the noise of the SkyTrain, and the rays of sunlight streaming down on my face, I opened my eyes groggily to a beautiful mid-March day. Today was the start of nwHacks2017, touted as the biggest hackathon to hit the Northwest. I hopped on the bus and arrived at the UBC Life Sciences Atrium, which was to host crowds of students and numerous software companies such as Google, Telus and Hootsuite.

It was here that my group would then win the Best Node.js App using CockroachDB prize. Of course, I didn’t know it at the time, but let me take you through my experience of using it and the lessons that I learned.

Choosing CockroachDB

Originally, my friend Ryan and I had planned to use MySQL for the database of our geo-cached post feed app, known as GeoPost. However, after walking out of a strangely invigorating opening ceremony which encouraged us to take risks, we decided on using CockroachDB. Plus, there was the bonus of possibly winning the prize, as well as the allure of the nicely printed hoodies that all the members at the booth wore.

However, the rest of our group wasn’t as enthusiastic as we were upon using it, and so the task of setting up the database was thrust upon me. Unfortunately, I hadn’t the slightest idea of how a database worked, or even how a server communicated with one. Regardless, I dove into the documentation of CockroachDB, and was immediately assaulted by terms such as “nodes” and “clusters”. Nevertheless, I set to work upon configuring the database on my computer. I created a node, then a cluster. Finally, I built a table. It worked, but then, for some strange reason, I thought that it wouldn’t be accessible to other people. So, I set about trying to configure it with Amazon Web Services.

Ensue chaos and much confusion.

Hosting Woes

AWS has something called EC2, which essentially allows you to work on a virtual machine hosted by Amazon. So, I created an account, which needed my credit card information, something I found odd. After that, I was completely lost, and had to run over multiple times to the other hall to receive help from the kind CockroachDB people, who thankfully saw over my confused dealings with AWS, showing me how to connect to the VM using a key, and how to install CockroachDB. We ran into some problems with port forwarding, but as a temporary solution, we decided to simply re-direct all ports to the IP address, which is not recommended if you’re intending to deploy it to the public, since that has some major security issues.

…what I would recommend for anyone who would want to use CockroachDB in the future at a hackathon is to simply host it on your own local machine.

But, for the sake of the hackathon, we decided that it was fine, and so we continued onwards. Then, I connected to my VM using the key that I created, and made a table on it. Hurray. However, what I would recommend for anyone who would want to use CockroachDB in the future at a hackathon, is to simply host it on your own local machine and forward your own ports, and deal with AWS later if you’re planning to release it. AWS wasn’t too difficult, but it was a hassle and it would have saved me a couple of hours if I simply hosted the database from my own machine.

Trevin, The Database Guy

Despite the hassle, however, once it was set up, I was pleasantly surprised how easy it was to manage. The SQL syntax was easy to use and understand, and within minutes, I could get tables up and running with data about our posts and comments sent in from our backend. Unfortunately, thanks to my lack of skill at Javascript and anything web-related, I became the database guy, sometimes editing columns and removing rows whenever needed. While not too exciting, it did make me thankful for CockroachDB’s ease of use.

As the rest of our group trudged on, with two of my group-mates working on the Node.js backend, and the ever so talented Ryan continuing to polish the front-end with shiny buttons and logos, I sat around, drank coffee, and complained about how hard Javascript was to use. An excellent use of my time. Later, I did end up deploying the app using Heroku.

Finally, one sleepless night later, we had finished the app. It was dreadfully tiring, and I swear I could see visions of localhost appearing now and then. Nevertheless, it was done, and we enjoyed some curry for breakfast, and went on to present our app. Thankfully, the CockroachDB guys seemed to really like it, and thankfully so, since I definitely spilt a lot of tears setting it up.

When it came to the ending ceremony, the CockroachDB people called our name, bestowing upon us the title of the Best Node.js App using CockroachDB! It was a surreal experience. I was definitely stunned hearing our names.

Why CockroachDB?

Now, as I reflect on my experience at nwHacks2017, I’d like to share a little more about why I think CockroachDB would be a good choice to use at your next hackathon.

Firstly, how easy it is to use. As a complete newbie to servers and databases, I found CockroachDB very easy to configure. Most of the difficulty I encountered was due in part to Amazon Web Services, who almost charged me $1200 for forgetting to turn off their instance. When setting up CockroachDB, I was calling “cockroach start” and making tables within the first hour. The SQL syntax is very easy to use.

Secondly, the potential of scaling up into a legitimate app. If we wanted to, I’m sure we could have made GeoPost into something big. And to handle something big, we would have needed a database capable of handling thousands of posts and comments. By using CockroachDB, it would have been easy to do so by simply just adding more nodes and clusters. So, it’s a good idea to use CockroachDB just in case you land upon a good idea that you’d like to take further. While I can’t speak too much about the actual scalability and survivability since we didn’t take that extra step, I can see how useful it would be.

Finally, just some recommendations I have if you decide to use CockroachDB. Install the database on your local machine, and simply forward the relevant ports. This is faster and easier than trying to deal with setting it up on AWS. You can always migrate to AWS later, as well. Concern yourself with only creating and manage 1 node. The documentation suggest that you create a cluster, but since this is a small-scale prototype, you only need one. Familiarize yourself with the drivers needed to communicate from your back-end to CockroachDB, and how to do so.

That’s about all I have to say for CockroachDB, and if you ever get see CockroachDB at your local hackathon, I would encourage you to say hi to them and try using their technology. They were among the friendliest and most helpful people I’ve ever met, and I really enjoyed working with them and am definitely going to use CockroachDB again.

How does CockroachDB guarantee strong consistency at scale?

Read the ACID docs