# Golang for Data: A talk @ Web Summit Meetup in Lisbon

Golang for data: Using Golang to easily extract and process data faster.

This was the title of the lightning talk I gave at the recent Web Summit Meetup in Lisbon. This blog post is a written, slightly changed, version of that presentation. So, without further ado let's Go.

Why Golang for data

Extracting, processing and analysing data are very important tasks in today's information age. While interpreted languages, such as Python, are commonly used, they have their problems, namely speed, when dealing with large amounts of data.

Golang being a compiled, modern, and easily concurrent language becomes an attractive possibility to deal with data.

Libraries

Part of the appeal in using any language for any task are the libraries it offers. So what about Go?

Mike Hall did a good round up of libraries by the end of 2015, which can be found here.

We can already see a good number of libraries which are very useful. While some libraries might still be missing, I do believe the existing ones already give developers a very good foundation to work with data. However, if you do feel like something is missing you can always contribute back to the community and create a library, that way we can increase that list.

Example

So let's jump to an example and see how easy it is to use Golang for a simple web scraper. Consider we want to fetch the links for the results of a duckduckgo search query.

For this example, I will use the goquery library, which is built on top of the Go's project library net/html.

And there we go. We may now scrape 3 different queries at the same time.

It would also be interesting to have the scraper itself being concurrent (for example, by analysing multiple nodes at the same time). However, with this library, it isn't that easy, if even possible. Instead, if we had used the net/html library we would have more control over the scraper and it would be easier to do this. We would, of course, lose the simplicity of goquery, but it's a trade-off worth considering.

Deployment

One other factor which I believe is very interesting in Go is the ease of deployment. Let's say we want to send the scraper to a server. We would create a binary for the server's architecture and run it there without other dependencies.

To do this we have the GOOS and GOARCH environment variables. If our server was running on a Linux 64 bits system we could simply do

export GOARCH=amd64
export GOOS=linux
go build

And we have a binary capable of running on the server. We just upload it to the server and we can have our scraper running without the need for any more dependencies.

Performance

Performance was one of the main reasons I looked at Go for data, so let's compare our scraper against a similar Python version that uses the pyquery library

We can see Go is able to get both a better time and a better memory usage, which, although isn't very significant for this small scenario, makes it very interesting for even larger scenarios. Imagine this on a larger scale, instead of taking 17 days, you would only take 2 days with the Go version.

Conclusion

Golang has been growing a lot in the last couple of years, and some interesting libraries for data already exist. This together with its performance, easy concurrency and good error handling make it a valuable tool to have in one's arsenal when dealing with data.

With this said, I invite you to give Go a try. However, make sure to always evaluate what is the better tool for each job and to not blindly use any of them. While Go is interesting for some use cases like our example, there are certainly other cases where R, Julia, Python, or any other language could be a better fit.