How I became a Go developer

A presentation at Financial Times Sofia Meetup in September 2018 in Sofia, Bulgaria by Luca Panziera

Slide 1

Slide 1

How I became a Go developer Luca Panziera - The Financial Times

Slide 2

Slide 2

Who I am Started working for the FT 3 years ago I was hired as Java developer I spent 10 years implementing applications in Java Mainly in computer engineering research projects

Slide 3

Slide 3

Why Java? Java is a popular language: ● Many libraries ● Cross-platform ● Garbage collection ● Memory security

Slide 4

Slide 4

What people were doing at the FT when I joined Implementing the new Content platform Going towards microservices... Each microservice was a Java application running on a VM in two FT data centers and AWS. In parallel… … Implementing a hand-rolled “container orchestration framework”

Slide 5

Slide 5

One day our software architect said... WE MUST USE GO! Why? Go is efficient!... And we can implement everything in few milliseconds!

Slide 6

Slide 6

Let’s take a look at Go…

Slide 7

Slide 7

What is Go? A Programming Language: ● developed by Google ● announced in November 2009 ● Version 1.0 released in March 2012 So… it’s quite new!

Slide 8

Slide 8

What Go developers had in mind? ● Statically typed and scalable to large systems (like Java or C++) ● Simple and readable, without excessive boilerplate ● Not requiring IDEs, but supporting them well ● Supporting networking and multiprocessing

Slide 9

Slide 9

My first reaction to Go import “math” Struct instead of Class?! type Circle struct { x, y, r float64 Methods are functions?! } func (c *Circle) Area() float64 { return math.Pi * c.r * c.r } Is this C?

Slide 10

Slide 10

Why it looks like C? Pointers No overloading: func addInt(a,b int) int { return a + b } func addFloat64(a,b float64) float64 { return a + b } Very basic data structures: Array, Slice, Map... nothing more Go is a compiled language

Slide 11

Slide 11

The reaction of my team... We must use Go! It’s going to make our life! What the hell is this?

Slide 12

Slide 12

Actually Go is really cool! It is more concise… compared to Java… Java public class Circle { private double x, y, r; public double getX() { return x; } public void setX(double x) { this.x = x; } public double getY() { return y; } public void setY(double y) { this.y = y; } public double getR() { return r; } public void setR(double r) { this.r = r; } } public double area() { return Math.PI * r * r; } Go import “math” type Circle struct { X, Y, R float64 } func (c *Circle) Area() float64 { return math.Pi * c.R * c.R }

Slide 13

Slide 13

Go is easy to learn Go Tour + Effective Go After few days

  • Bit of practice Decent Go developer

Slide 14

Slide 14

CPU and memory efficiency ● Java microservice: JSON manipulation, 9K requests/day, 340MB memory ● Go microservice: Database query + data manipulation, 40K requests/day, 12MB memory Save cost of Cloud Services with smaller VM instances

Slide 15

Slide 15

What about memory allocation?! Memory safety and Garbage collection func brakeSlice() { a := []int{1, 2, 3} a[5] = 7 } panic: runtime error: index out of range

Slide 16

Slide 16

A simple way to handle concurrency func send(c chan string, msg string) { for { c <- msg } } func receive(c chan string) { for { msg := <-c fmt.Println(msg) } } main() go send(c,”gopher”) Goroutine-send go receive(c) c channel ”gopher” Goroutine-receive

Slide 17

Slide 17

No more Maven hell Go is a compiled language so... Fast in compiling and running test (few seconds) A easy import of libraries with “dep” dep init dep ensure -add github.com/sirupsen/logrus dep ensure -update go test ./... go build

Slide 18

Slide 18

Go sounds amazing… but...

Slide 19

Slide 19

When the team started using Go... People forgot about code practices!

Slide 20

Slide 20

Everything in a single file main.go Usage of func: line 34 Usage of func: line 232 Impl. of func: line 476 Usage of func: line 675 Source: wikipedia A good excercise for head bagging

Slide 21

Slide 21

Code in many files… but without any logic! pluto.go user.go Usage of func pippo.go cat.go db.go record.go dog..go pippo.go Where is the implementation of func? meaningless.go Impl. of func

Slide 22

Slide 22

Unit tests were not really mature... Coverage wasn’t great Difficulties in mocking Missing Integration tests Couple of times the worst happened in Production

Slide 23

Slide 23

OMG… What’s the situation now?

Slide 24

Slide 24

The FT Content platform After 3 years... The quality of code base improved a lot A Kubernetes-based platform made of ~150 microservices 85% of them are implemented in Go Reduced cost of 80% on AWS So, Go has been a success for us!

Slide 25

Slide 25

In the world of microservices… Fast implementation from scratch Efficiency with network overhead Go meets this requirements

Slide 26

Slide 26

What I learnt by using Go? Go combines: ● efficiency ● memory safety and garbage collection A concise programming language No language boundaries allow you to write excellent code… or total crap Good sense of the developer is the key (as usual).

Slide 27

Slide 27

Thank you! We are hiring! ft.com/dev/null @izzyblues83 Credit Ashley McNamara and https://github.com/ashleymcnamara/gophers for most images. Credit Renee French for the original gopher concept and design.