Loading
All articles
Python 13 min read

What Is the Go Programming Language? A Simple Guide to the Language of the Cloud

A friendly, jargon-free guide to Go, the simple and fast programming language Google created for the cloud. Learn what goroutines are, why Go programs are a single file, and how Go came to power Docker, Kubernetes and much of the internet.

nbkhope
On this page

When you stream a video, order a ride or open a website, there's a good chance some of the software answering you behind the scenes is written in Go. You've probably never seen it, but it quietly runs a big part of the modern internet: the tools that package apps, manage cloud servers and handle millions of requests per second.

Go was created at Google to be simple like Python but fast like C, and to be very good at doing many things at the same time. This article explains, in plain language, what Go is, why it was made, what makes it special, and where it's used.

Why Google made a new language

By 2007, Google had enormous programs written mostly in C++, Java and Python, running on thousands of computers. Each language had a problem:

What Google wanted in 2007: the best of both worlds. C++: fast programs, but slow to build and complicated. Python: easy to read and quick to write, but slow programs. Go: fast programs, builds in seconds, small and simple. Go's designers wanted the speed of a compiled language like C++ with the simplicity of a language like Python, plus easy ways to do many things at once
  • C++ produced fast programs, but it was complicated, and building a big C++ program could take many minutes. One of Go's creators, Rob Pike, has said the idea for Go took shape while waiting for a huge C++ program to compile.
  • Python was pleasant to write, but too slow for some of Google's busiest systems.
  • And computers were gaining more and more processor cores, but none of these languages made it easy to use them all at once.

So three Google engineers, Robert Griesemer, Rob Pike and Ken Thompson, set out to design something better. Ken Thompson was already a legend: he co-created the Unix operating system and the B language, the direct ancestor of C (see What Is the C Programming Language?).

Go was announced to the world as free, open-source software in 2009, and Go 1.0 arrived in 2012.

Small on purpose

Most languages grow by adding features. Go's designers did the opposite: they kept the language small, so it's quick to learn and every Go program looks familiar. Go has only 25 keywords (special reserved words like if, for and func), fewer than most popular languages.

Here's the classic first program:

1package main
2
3import "fmt"
4
5func main() {
6	fmt.Println("Hello, world!")
7}

package main says this is a program you can run, import "fmt" brings in the formatting toolbox, and func main() is where the program starts. It prints Hello, world!.

Go doesn't have classes like Java or C#. Instead, you describe data with a struct (a bundle of named values) and attach actions to it:

1type Car struct {
2	Color string
3	Speed int
4}
5
6func (car *Car) Accelerate() {
7	car.Speed += 10
8}
9
10func main() {
11	myCar := Car{Color: "red"}
12	myCar.Accelerate()
13	myCar.Accelerate()
14	fmt.Printf("My %s car is going %d km/h\n", myCar.Color, myCar.Speed)
15}

This prints My red car is going 20 km/h. The := sign creates a variable and lets Go figure out its type on its own, so you get the safety of types without having to spell them out everywhere.

Go even settles arguments about style: it comes with a tool called gofmt that automatically formats your code the one official way. Spaces, line breaks and alignment are never up for debate, so all Go code looks alike.

The superpower: goroutines

Go's most famous feature is how easily it does many things at once. Imagine making breakfast. You could brew the coffee, wait three minutes, and only then start the toast. Or you could start both and let them work side by side.

In Go, you start a task "on the side" by writing the word go in front of it. That creates a goroutine, a lightweight task that runs alongside the rest of your program:

1func makeCoffee(done chan string) {
2	time.Sleep(3 * time.Second)
3	done <- "Coffee is ready"
4}
5
6func makeToast(done chan string) {
7	time.Sleep(2 * time.Second)
8	done <- "Toast is ready"
9}
10
11func main() {
12	start := time.Now()
13	done := make(chan string)
14
15	go makeCoffee(done)
16	go makeToast(done)
17
18	fmt.Println(<-done)
19	fmt.Println(<-done)
20	fmt.Printf("Breakfast ready in %.0f seconds\n", time.Since(start).Seconds())
21}

When we ran it, it printed:

Toast is ready
Coffee is ready
Breakfast ready in 3 seconds
Making breakfast: one thing at a time vs. with goroutines. One at a time: coffee takes 3 seconds, then toast takes 2 seconds, for a total of 5 seconds. With goroutines: coffee and toast start together, toast finishes after 2 seconds and coffee after 3, for a total of 3 seconds. With the word "go" in front, each job runs as its own goroutine, so they overlap and breakfast is ready when the slower one finishes. This is exactly what the article's example program printed

Three seconds instead of five, because both jobs ran at the same time. The toast finished first, so its message arrived first.

The other new idea here is the channel (chan), a pipe that goroutines use to pass messages to each other. Each job drops a message into the done channel when it's finished, and <-done waits until a message comes out. A popular Go saying sums up the idea: "Don't communicate by sharing memory; share memory by communicating." Instead of several tasks fighting over the same data, they hand results to each other, like cooks passing plates through a kitchen window.

Goroutines are also cheap. Each one starts with just a few kilobytes of memory, and Go juggles them across the computer's cores for you. On our laptop, a test program started 100,000 goroutines at once in about half a second. That's why a single Go server can handle a huge number of visitors at the same time, giving each one its own goroutine.

Using every core

Goroutines aren't just for waiting on slow things. They can also split up heavy work. We counted the prime numbers below 2 million in a Go program, sharing the work among more and more goroutines:

More goroutines, faster answer. Counting the prime numbers below 2 million in one Go program, with the work shared among goroutines, measured for this article on a laptop with 14 processor cores as the median of repeated runs. 1 goroutine: 0.509 seconds. 2 goroutines: 0.304 seconds, 1.7 times faster. 4 goroutines: 0.148 seconds, 3.4 times faster. 8 goroutines: 0.095 seconds, 5.4 times faster. 16 goroutines: 0.076 seconds, 6.7 times faster. Go spreads the goroutines across the processor's cores automatically. The gains shrink at the end because the cores share heat and power, and some of them are smaller, slower "efficiency" cores

With 16 goroutines, the same job finished almost 7 times faster, and the program barely changed: a few goroutines picking up blocks of numbers from a channel. The gains level off at the end, partly because a laptop's cores share heat and power, and some of them are smaller, slower cores built to save battery.

Is Go fast?

Yes. Go is a compiled language: before running, your code is translated into the computer's own machine language, like C. We timed the same simple job, counting the prime numbers below 2 million with just one worker, in five languages:

Speed test: Go runs close to C. Counting the prime numbers below 2 million with one worker, timed from start to finish, measured for this article as the median of 5 runs on one Windows laptop. C: 0.36 seconds. JavaScript: 0.38 seconds. Go: 0.39 seconds. Java: 0.60 seconds. Python: 17.60 seconds, off the chart. Versions: GCC 14, Node.js 26, Go 1.22, Java 17 and Python 3.11. Java's time includes about 0.2 seconds to start its virtual machine. Go used 32-bit numbers like C and Java; with its default 64-bit numbers it took 0.56 seconds

Go finished in 0.39 seconds, essentially tied with C and JavaScript on this small test, and about 45 times faster than plain Python. To be fair to every language, the Go version used the same 32-bit numbers as the C and Java versions. With Go's default, larger 64-bit numbers, it took 0.56 seconds, because dividing bigger numbers is a little slower for the processor.

Go is also famous for fast builds. Even large Go programs typically compile in seconds, which was one of its original goals. (See What Is the Python Programming Language? for why plain Python is so much slower, and how it gets around that.)

One file that runs anywhere

Another reason people love Go is how easy it is to share a finished program:

One command, one file, any computer. Your Go code goes through the go build command and becomes a single file: hello.exe for Windows, about 2 MB; hello for Linux, built on Windows; and hello for Mac, built on Windows. Copy the file and run it: no Go, no libraries, nothing else to install. Go bundles everything a program needs into a single file, and it can build that file for other operating systems from your own computer. That makes Go programs very easy to share and to put on servers
  • One file: go build packs your program and everything it needs into a single file. Our "Hello, world!" became a 2 MB hello.exe that runs on any Windows computer, no installation required.
  • Any computer: from the same Windows laptop, changing two settings produced versions for Linux and for Mac. Building for another system is called cross-compiling, and Go makes it trivial.

That's a big deal for servers: instead of installing a language, libraries and matching versions on every machine, you copy one file and run it.

Where Go is used

Where Go is used. Docker: packs apps into "containers" that run anywhere. Kubernetes: runs huge fleets of containers in the cloud. Terraform: sets up cloud servers from a text file. Cloudflare and Uber: busy back-end services handling millions of requests. Ollama: runs AI language models on your own computer. Command-line tools: GitHub's gh tool and the Hugo website builder. Go is sometimes called "the language of the cloud": much of the software that runs today's internet servers is written in it
  • Docker packs apps into containers, neat bundles that run the same way on any computer. It's written in Go.
  • Kubernetes, created at Google, runs and coordinates huge numbers of containers across data centers. Also Go.
  • Terraform lets engineers describe the cloud servers they want in a text file and creates them automatically.
  • Companies like Cloudflare, Uber, Twitch and Google use Go for busy back-end services.
  • Ollama, a popular app for running AI language models on your own computer, is written in Go.
  • Handy command-line tools like GitHub's gh and the Hugo website builder are Go programs, shipped as a single file.

Because so much cloud software is written in it, Go is often called "the language of the cloud".

The downsides

Go doesn't use "exceptions" to signal problems. Instead, functions return an error that you check right away. Here, we try to turn the text "forty" into a number:

1age, err := strconv.Atoi("forty")
2if err != nil {
3	fmt.Println("That's not a number:", err)
4	return
5}

This prints That's not a number: strconv.Atoi: parsing "forty": invalid syntax. That brings us to Go's weak spots:

  • Repetitive error handling. Checking errors this way is clear and explicit, but if err != nil appears so often that it's a running joke among Go programmers.
  • Simple can mean limited. Go deliberately leaves out features other languages have. It took until 2022 to add generics (a way to write one piece of code that works with many types), one of the most requested features.
  • Not built for everything. Go is rarely used for phone apps, desktop apps with windows and buttons, games, or AI research, where other languages have better tools.
  • Not the absolute fastest. Go's garbage collector and safety checks cost a little speed, so for the most demanding work, like game engines or operating systems, C, C++ and Rust are usually chosen.

A short history

A short history of Go, as a timeline. 2007: Robert Griesemer, Rob Pike and Ken Thompson start Go at Google. 2009: Go is announced as open source. 2012: Go 1.0, with a promise not to break old code. 2013: Docker is released. 2014: Kubernetes is released. 2015: Go's compiler is rewritten in Go. 2022: Go 1.18 adds generics

A fun milestone: in 2015, the Go compiler, the program that turns Go code into machine code, was itself rewritten in Go. When a language can build itself, programmers say it's self-hosting.

Should you learn Go?

  • Great reasons: you want to build web servers, back-end services, cloud tools or command-line programs, or you'd like to work with Docker and Kubernetes. Go is also a nice second language: small enough to learn in a few weeks, with clear rules.
  • Good to know: Go is free and runs on Windows, Mac and Linux. The official website, go.dev, has an online playground where you can write and run Go code in your browser, plus a free interactive tour of the language.

A small glossary

  • Go (Golang): a programming language created at Google, announced in 2009.
  • Compiled language: a language whose code is translated into machine code before it runs.
  • Struct: a bundle of named values, like a car's color and speed.
  • gofmt: the tool that formats Go code the one official way.
  • Goroutine: a lightweight task that runs alongside the rest of a program, started with the word go.
  • Channel: a pipe that goroutines use to send messages to each other.
  • Concurrency: handling many tasks at the same time.
  • Core: one of the processing units inside a computer's processor. Modern processors have many.
  • Garbage collector: the part of Go that frees memory a program no longer uses.
  • Cross-compiling: building a program on one kind of computer for another kind.
  • Container: a neat bundle with an app and everything it needs, run by tools like Docker.
  • Generics: a way to write code once that works with many types of values.

Wrapping up

Go was born from frustration with slow builds and complicated code at Google, and it answered with a small, readable language that compiles in seconds and runs nearly as fast as C. Its signature trick, goroutines, makes doing many things at once as simple as typing go, and its single-file programs are a joy to ship to servers.

It doesn't try to be everything, and its error checks can feel repetitive. But if you've used a modern website or app today, there's a good chance a little Go program somewhere was busy helping, many things at once.

Thanks for reading!

Know someone who would enjoy this? Send it their way.

More articles

Read next

Comments

Be kind and specific. Comments with links from new accounts appear after a moderator reviews them.