The Road to Go
Golang, also known as Go, is an open-source programming language. It was created by Google to provide faster apps, increased productivity, and high code efficiency. It is viewed as easy to learn and get started with.
Golang user cases:
- Cloud and Network services – It’s now easier than ever to build services with Go
- Command-line Interfaces – Use Go to create fast CLIs
- Web Development – Go powers fast and scalable web applications
- DevOps and Site reliability – Go is built to support both DevOps and SRE
Challenges other programming languages face
In other programming languages, when you need to build an application with a server, you need additional servers and know the spec. to write sufficient code. However, Go doesn’t require any additional servers. You simply run it on one line, making it straight forward. You just need the code and configure the quickness of the server request etc.
I had experience in ActionScript where it took 3 months to learn all the Java spec required to build web app: JSE, JEE, JVM, TomCat spec etc. When I started to learn Go, it only took one week to start building web applications.
Benefits of Go
Go’s standout characteristics are speed, communication and memory capacity, around the same level as C++ or faster. From my involvement of working with C, you can build a faster application in Go. In general, C apps, which are used to monitor car systems should be quick, but the difficulty is when something goes wrong. The syntax of Go is succinct as in Python, so it attracts programmers who want more performance.
Go has benefits at the beginning of app development as you don’t need to worry about dependencies or build configuration. When you are using any third-party libraries, they will be added to your project automatically when you build your app. All you need to do is run `go mod init` to initialise the new root module.
Go also has a Garbage Collector so you do not have to worry too much about memory management. However, this has drawbacks too. One of the significant Go features is goroutines. This is a lightweight approach to run a function or method independently and simultaneously in connection with any other Goroutines present in your program. Garbage Collector in Go is forced when heap is increased twice and at least once every two minutes.
Let’s now imagine that we need to build a High Load application with hundreds or thousands of simultaneous tasks per second which should deliver notifications to users. If GC is forced every two minutes that means all the goroutines which are running at the time must be paused until GC has finish its work. It is then, the goroutines continues their work. This is really bottleneck when businesses require notifications to delivery immediately. Obviously, we can disable GC and trigger that from Go code, but this requires an experienced team and huge expenses for testing.
What can Go be used for and how does it differ from other languages?
When you design a microservice architecture for your app, you don’t need really care about what language you should take. You can build some services with Java, another with PHP and so on. And they can communicate with each other by REST, SOAP, RPC etc. But if the time for communication between services is important for your app and you really want to minimise that, you can: decrease request\response serialization\deserialization time (the best one is gRPC protocol) and remove VM\interpreter on service side, by choosing compiled language without VM (C, C++, Go etc.). You can also use lightweight asynchronous functions\methods to run as many requests as possible on the single service replica.
From my point of view the best solution is Go + gRPC, just because:
- Go supports all features of gRPC and it’s very easy to implement
- Go has GC and you don’t need to care about memory like in C
- Go has easy syntax so, new team members don’t need to spend a lot of time to understand service code
You can use Go in micro services, mobile app or desktop. I wouldn’t recommend building mobile apps within Go right now as it’s just beginning the mobile SDK support. Kotlin\Dart are much better at the moment in this area.
Java and Go both have a garbage collector. From a developer’s point of view, Java is complicated as each separate application should be tested against GCs with different parameters, which is time consuming. With Go, there is only one option, you simply accept or decline it.
Looking at where this simple but complex language will go, I predict Go V2 will bring generics like Java, but bring benefits to cost and in the future, build generic solutions. I also hope Mobile SDK will be improved.
Go is a very young language, and we don’t have a lot of public frameworks as we still haven’t uncovered all the areas to write the complete required library. In my opinion, if you read something in Go, write it in Go. Language is easy – write it yourself!