Aleksandar Diklić wrote this on August 28, 2013
Building our first app in Go
Or how and why we started using Go in production.
There is a lot of hype about new and innovative programming languages this days. Go is one of those of course. Big names that are behind this project, like Ken Thompson, Rob Pike and Google itself, can mean that this language should be taken seriously.
Beside being quite C-like with low-level facilities such as pointers, Go offers many features of high or even very high-level languages, like powerful data structures, duck typing and easy high-level concurrency. With that in mind Go becomes a very interesting solution for many classes of problems, from system tools to web applications and distributed systems.
Why we need it and where does Go fit in our stack?
The first question that logically arises is why we need something besides Ruby in the application stack?
As our CI service Semaphore grows we’re discovering new and stack specific problems. Scaling it makes us constantly improve our knowledge and skills in about every segment of web application. One of the big problems that we experienced was large number of requests on a single Ruby on Rails application.
Our front-end application was handling all web traffic, website interface and API. Naturally the biggest portion of that traffic comes from the API which can eventually make the whole web application suffer. A solution for that is to divide the application into a few smaller ones which will let us balance the amount of requests and performance of vital parts of application.
The nature of this problem gave us the space to explore and try something new, because API alone doesn’t have any complex logic. Since there have been many success stories with Go posted on Twitter and Hacker news, after a short survey we decided to give it a chance.
Where to start learning Go?
Like any new language, Go has a relatively small community, not much documentation and no battle-tested guidelines (the opposite of our beloved Ruby world). Of course things aren’t that bad, Go’s main website and rich standard library are a great resource for start. Now and then you’ll find lack of examples in docs but that could be supplemented by the always great community on Stack Overflow and of course the main mailing list golang-nuts. I think that these shortcomings will be overcome over time as community matures. Don’t let those problems beat you on the way to learn and use a new tools - use it as inspiration - and at the end of the day you will not regret the invested effort.
I highly recommend checking out the book by Mark Summerfield Programming in Go. We received it a few days ago and we’ll post review of it in close future. Another great resource would be source code of other people’s libraries. Most Go open source libraries are not that big and the code is easy to follow.
Tip: never forget that the best way to learn a new language is by using it, even if you suck at beginning.
The journey is the reward
With that in mid, we started with just one single API action. That was the CruiseControl notification endpoint, which brings us heavy traffic. For accomplishing that first step in our Go API project, we needed an XML response with a few attributes wrapped by some simple logic. Since we have never done anything in Go, that simple process went on for a few days but it was worth the time. Interesting fact is that we spent most time on figuring out how to write tests (we failed with first attempt of Go TDD).
When we got the minimal valuable product, in this case a basic application, we went back to the beginning and start learning “the Go way” again to figure out how to adjust our way of seeing and understanding the problem to the new tool and discover new, better solutions.
We will continue to use Go
A combination of low-level and high-level features makes Go a great tool for a vast variety of problems, and brings a new dimension to the world of programing languages. Since Go programs perform very well and it is easy to understand its basic principles, it will increasingly be part of our stack in the future. It’s not a silver bullet but it seems to be a powerful solution for isolated services that need very high performance.
If you want to try Go, here are some basic questions to consider:
- Are you ready to learn something new?
- Are you having real problems to solve?
- Are you ready to invest some time for the sake of performance?
If “yes” is the answer to these questions, try Go and share your experience.
In upcoming posts I’ll try to focus more on specific stuff, like real benefits, disadvantages, problmems, solutions and of course examples.
Till next time, stay cool and learn Go. :)