The Capstone: Shipping linkly
The track ends with one project that uses every phase: a small but real service, taken all the way to production with the tools and practices a DevOps team uses. It is built in the DevOps Capstone course; this lesson shows what you will build and why each piece is there, so you can see the goal from the start.
The service: linkly
linkly is a link shortener: you send it a long URL, it gives you a short code, and visiting the code redirects to
the URL. It is provided ready-made, written in Go. Your job is everything around it.
| Endpoint | What it does |
|---|---|
POST /links |
stores a new short code and its target URL in PostgreSQL |
GET /{code} |
redirects to the target; Redis caches popular codes in front of the database |
GET /healthz |
liveness probe: the process is up |
GET /readyz |
readiness probe: the database and cache are reachable |
GET /metrics |
Prometheus metrics: request counts, errors, latency histograms |
It uses the Go standard library's net/http router, pgx for PostgreSQL, go-redis, the Prometheus Go client,
log/slog JSON logs and OpenTelemetry tracing, and it reads all configuration from environment variables (the
"twelve-factor" style), so the same image runs everywhere.
Why Go: it compiles to one static binary, so the container image can be a few megabytes with no shell or package manager inside. The tools you operate it with (Docker, Kubernetes, Terraform, Prometheus) are written in Go too.
The heart of a link shortener fits in a few functions. The database gives each link a numeric id, and the short code
is that id written in base 62. Input validation decides which targets are allowed; a shortener that redirects to
javascript: URLs is a security hole:
package main
import (
"errors"
"fmt"
"net/url"
"strings"
)
const alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
// encode turns a database id into a short base62 code: 125 -> "21".
func encode(id uint64) string {
if id == 0 {
return string(alphabet[0])
}
var b []byte
for id > 0 {
b = append(b, alphabet[id%62])
id /= 62
}
for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
b[i], b[j] = b[j], b[i]
}
return string(b)
}
// decode reverses encode and rejects codes with characters outside the alphabet.
func decode(code string) (uint64, error) {
if code == "" {
return 0, errors.New("empty code")
}
var id uint64
for _, r := range code {
i := strings.IndexRune(alphabet, r)
if i < 0 {
return 0, fmt.Errorf("invalid character %q in code", r)
}
id = id*62 + uint64(i)
}
return id, nil
}
// validateTarget accepts only absolute http(s) URLs with a host.
func validateTarget(raw string) error {
u, err := url.Parse(raw)
if err != nil {
return err
}
if u.Scheme != "http" && u.Scheme != "https" {
return fmt.Errorf("scheme %q not allowed", u.Scheme)
}
if u.Host == "" {
return errors.New("missing host")
}
return nil
}
func main() {
for _, id := range []uint64{1, 61, 62, 125, 1_000_000, 56_800_235_583} {
code := encode(id)
back, _ := decode(code)
fmt.Printf("id %-12d -> %-7s -> %d\n", id, code, back)
}
if _, err := decode("ab-c"); err != nil {
fmt.Println("decode:", err)
}
for _, target := range []string{"https://example.com/docs", "javascript:alert(1)", "https://", "ftp://files.example.com"} {
if err := validateTarget(target); err != nil {
fmt.Printf("reject %-26s %v\n", target, err)
} else {
fmt.Printf("accept %s\n", target)
}
}
}id 1 -> 1 -> 1
id 61 -> Z -> 61
id 62 -> 10 -> 62
id 125 -> 21 -> 125
id 1000000 -> 4c92 -> 1000000
id 56800235583 -> ZZZZZZ -> 56800235583
decode: invalid character '-' in code
accept https://example.com/docs
reject javascript:alert(1) scheme "javascript" not allowed
reject https:// missing host
reject ftp://files.example.com scheme "ftp" not allowed
Six characters cover more than 56 billion links. Pure functions like these are tested with ordinary go test in
the pipeline; the System Design lesson discusses the design trade-offs (counters vs
hashes, caching, hot keys).
The DevOps around it
| Component | Technology | What you build | Phase |
|---|---|---|---|
| Containerization | Docker | a multi-stage build into a distroless image that runs as a non-root user | 2 |
| CI | GitHub Actions | lint, test, build, Trivy scan as a gate, push to a registry | 3 |
| Manifests | Helm | a chart with a Gateway API HTTPRoute (Ingress with a maintained controller as the alternative), autoscaling, resource requests and limits, probes | 4 |
| IaC | OpenTofu / Terraform | the network, the database and the Kubernetes cluster | 5 |
| CD | Argo CD | syncs the chart's values from a GitOps repository to the cluster | 6 |
| Observability | Prometheus, Grafana, Loki | dashboards for request rate, errors and latency; alerts; central logs | 6 |
The image is the first piece. Its Dockerfile is short because Go needs no runtime:
FROM golang:1.27 AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/linkly ./cmd/linkly
FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /out/linkly /linkly
USER nonroot:nonroot
EXPOSE 8080
ENTRYPOINT ["/linkly"]How a change flows
developer ──push──▶ GitHub ──▶ CI: lint · test · build · Trivy scan · push image
│
▼ (new image tag)
GitOps repo: values.yaml updated by a pull request
│
▼ (Argo CD notices the commit)
Kubernetes cluster: rolling update of linkly
│
▼
Prometheus + Grafana + Loki: did latency or errors change?Every arrow is automated, every step leaves a record in Git or in the pipeline, and rolling back is a git revert
in the GitOps repository.
Two ways to run it
The capstone is planned with two tracks, so the whole track can be finished without spending money:
- Local track (default): a kind or k3d cluster on your machine; OpenTofu creates the cluster and in-cluster
PostgreSQL and Redis through the kind and Helm providers; a local container registry; GitHub Actions pushing to
that registry, or run locally with
act. - Cloud track (optional): the same project on EKS or GKE with a managed database. Every lesson says what the resources it creates cost and ends with a teardown step. Check current pricing before you start, and set a billing alert first.
What makes it a portfolio piece
At the end you have a public repository (or two: the app and its GitOps repo) that shows, in files anyone can read, that you can containerise, test, scan, provision, deploy, observe and roll back a service. Add a README with an architecture diagram, screenshots of the dashboards, an SLO document and one written postmortem of a failure you caused on purpose. DevOps Careers & Your Portfolio says more about presenting it.
Test yourself
Why does linkly expose both /healthz and /readyz?
- One is for humans, one for machines
- Liveness says the process is alive; readiness says it can serve traffic because its dependencies are reachable
- They are the same endpoint with two names
- Prometheus needs both
Why can the final image use distroless/static with no shell or C library?
- Go programs do not need an operating system
- The binary is built with
CGO_ENABLED=0, so it is statically linked and needs nothing else in the image - Distroless images include Go
- Because it runs on Kubernetes
In the capstone's flow, how is a bad release rolled back?
- SSH into each node
- Revert the commit in the GitOps repository; Argo CD syncs the cluster back
- Delete the cluster
- Rebuild the old image by hand