Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

From Scratch the lesson

Enough Go to Read These Builds a show in 8 chapters

Goal: read the 10 real build lines the lesson lists

1 of 8 Your guess

Before we start

This track builds seven real systems from an empty file, all in the Go language. A server is the first thing most of them become: one program answering many visitors at once.

Picture that server as a kitchen with many tables. Which picture is closest to how a Go server copes?

Pick the closest. You find out which fits at the end.

one build of one Google program, 200745 minuteseven spread over many machines

2 of 8 The problem

2007: a 45-minute build

In 2007, one major Google program, written in the C++ language, took 45 minutes to build. That was on a build system spread over many machines.

Rob Pike told the story in a 2012 talk, and called what came next a myth: that Go was dreamed up during one of those 45-minute builds.

Step 1 of 4

in: "tcp","127.0.0.1:6379"net.Listenlnerr

3 of 8 The idea

The slip and the note

In many languages a failure makes the program jump somewhere else to complain. Go does not. A cook hands you a plate and a slip. If the slip is blank, eat. If it says "no gas", do not eat the plate.

Press Play. The Redis build's very first line, acted out one piece at a time.

Step 1 of 5

stocka map, name → portionsempty: no jars yet

4 of 8 The idea

Three shapes

Data in these builds takes three shapes. The first one finds a value by its name, the way you find a jar on a shelf by its label.

Press Play. The lesson's second program keeps the kitchen's stock in a map.

Step 1 of 4

doorfree

5 of 8 Try it

A cook per visitor

Now the kitchen gets busy. Each visitor to the Redis build is a connection, an open line from their computer.

Press Play. The first Redis stage serves one visitor at a time, on purpose.

Step 1 of 5

sheet41cook Ahands emptycook Bhands emptyplates: 0

6 of 8 The fix

One key for the sheet

Cooks share things. In the Redis build every goroutine reads and writes one shared map. In the kitchen, every cook adds a mark to one tally sheet.

Press Play. Two cooks plate a dish at the same moment and each adds a mark. The sheet says 41.

Step 1 of 5

7 of 8 Your guess

Your picture now

Goal met: 10 of 10 real lines read, with five words and three shapes. Which picture is closest to a Go server now?

Pick one.

Enough Go to read the buildsA server is a kitchen. Five words, and every build reads.errora slip with the plateif err != nil { stop }defera note by the doorruns on every way outgoroutinego: a cook per visitorcheap: 100,000 in 78 mschannela rail of hookswaits when full or emptymutexone key for the sheetor marks go missingThree shapes: map, jars found by name · struct, a card of named fields · slice, a list that growschalkbrain.com
Enough Go to readthe buildsA server is a kitchen. Five words.errora slip with the plateif err != nil { stop }defera note by the doorruns on every way outgoroutinego: a cook per visitorcheap: 100,000 in 78 mschannela rail of hookswaits when full or emptymutexone key for the sheetor marks go missingThree shapesmap: jars found by namestruct: a card of named fieldsslice: a list that growschalkbrain.com

8 of 8 Keep this

Keep this

A Go function hands back a slip with its answer, and you check it on the next line. defer leaves a note by the door. go starts a cook, a channel is the rail between cooks, and a mutex is the one key for what they share.

The trap: two goroutines writing one thing with no key lose updates and say nothing. Run with -race and it says so.

Read the full lesson