Project challenges / verified progress
Beacon: build an SSL and uptime monitor in Go

The engineering notebook

One request, one answer

What does it actually mean to say a website is up?

Loading Vault account...
Phase 1 — One check, one answer

Step 01 of 06

Understand the idea

A website monitor asks a server a question and records the answer. Dashboards, alerts, and certificate warnings all build on that simple check. In this lesson, you will write a small program that asks once and reports what happened.

ONE CHECK, TWO WAYS TO ENDhttp.Get(target)one question, asked onceNo answer at allDNS, refusal or deadlineerr != nilAn answer you likethe server handled it and said so2xxAn answer you don'ttransaction fine, service not4xx / 5xx
The top branch is a network fault and the bottom two are server verdicts. Beginner monitors collapse all three into "it responded, so it's fine" — which is exactly why they report a site serving 500s as healthy. Keep the branches apart from the first line of code and they stay apart for the rest of the course.
Step 01

Key technical ideas

What a check can tell you

A monitor cannot know whether a site is always up. It can answer a smaller question: Did this URL respond when I checked it, from this computer, just now? The same site may work from one place and fail from another. Beacon records the result and when the check happened.

Read the HTTP status code

An HTTP response includes a three-digit status code. Codes beginning with 2 usually mean success; 3 means the request was redirected; 4 means there is a problem with the request; and 5 means the server failed. A response alone does not mean the request succeeded, so check the code.

Tell connection errors from HTTP errors

resp, err := http.Get(url) returns a response and an error. If err is not nil, the request failed before the server sent an HTTP response, and resp is nil. Do not use resp in that case. If err is nil, check resp.StatusCode; the server may still have returned an error such as 503.

Close the response body

Go does not read the response body for you. Close it after you finish, or the program may keep connections open. In a loop, enough open connections can stop the program from making new requests. Add defer resp.Body.Close() after checking for an error.

The smallest honest check there is
package main

import (
	"fmt"
	"net/http"
)

func main() {
	resp, err := http.Get("https://example.com")
	if err != nil {
		// Branch one: no transaction happened. resp is nil — do not touch it.
		fmt.Println("unreachable:", err)
		return
	}
	defer resp.Body.Close()

	// Branches two and three: the transaction worked. Now read the verdict.
	fmt.Println("status:", resp.StatusCode)
}

Nine lines holding all three branches, the closed body, and a status code read rather than assumed. Type it out — don't paste it — and run it. Then break it deliberately: point it at https://not-a-real-host.invalid and watch the other branch run. A failure path you have never executed is a failure path you do not have.

The two failures, side by side

No answer arrivedA bad answer arrived

What happened

The request never completed

The request completed fine

In Go

err != nil, resp is nil

err == nil, read resp.StatusCode

Typical cause

DNS, routing, refusal, timeout

Bad deploy, dependency down, bad path

Who you'd wake up

Network or platform

Whoever owns the service

Beacon records it as

A transport error, named by layer

A reachable endpoint, unhealthy

Technical terms used at work

  • Probe — One execution of a check against one target. Beacon's unit of work — and the same word Kubernetes uses for its liveness and readiness checks, which you will meet again in course four.

  • Target — The thing being watched: a URL, or a host and port. One constant today, a configured list by course two.

  • Transport error — A failure that happened before any HTTP response existed. In Go, the non-nil error from the client.

  • Status code — The server's own three-digit verdict on the request it just handled.