Skip to content

Selected workNo. 01

Zero-to-Prod

A production-engineering laboratory: break one small system on purpose, keep the evidence.

Status
Active · local lab · not deployed to production
Stack
Go, PostgreSQL, RabbitMQ, Docker Compose
Checked
Against the repository, 2026-11-14

Zero-to-Prod studies how a small, stateful, asynchronous system behaves at the boundaries that matter in production: a crash between commit and acknowledgement, a database restore that reuses IDs, TLS and identity boundaries, secret rotation, overload, failover and incident response. Work Items, a Go API and worker over PostgreSQL and RabbitMQ, is the reference system. Each topic is an experiment with a recorded method, result and decision.

The problem

Tutorials show the happy path. Production failures happen at boundaries: a restore hands out the same numeric IDs again, so a stale broker message can point at a different row; a credential rotation fails halfway; a certificate expires on one hop while the others keep working.

The lab exists to make those failures happen deliberately, measure what actually occurs, and record the decision that follows, including the experiments that did not meet their targets.

Architecture

The API accepts a Work Item and a processing request in one PostgreSQL transaction that also writes an outbox row. A publisher sends that row to RabbitMQ afterwards, so accepted work is durable even if the broker or the process dies between the commit and the publish.

The worker completes the result, marks the item done and the job succeeded in one transaction, and only then acknowledges the message. Messages carry a random delivery identity that the worker checks against the database, so after a restore a stale message cannot act on a reused ID; an explicit offline redrive command republishes accepted jobs.

Separate labs layer on the same service in isolated, disposable Compose projects: a security lab (HTTPS ingress, identity provider, verified TLS on every hop), observability, capacity, availability and recovery, delivery, and operations.

Fig. 1Work Items: accepted work survives a crash

Architecture of the Work Items reference system: a client reaches the API through an nginx ingress and oauth2-proxy; the API and its outbox publisher, PostgreSQL, RabbitMQ and a worker form the durable processing path.

Scroll the figure sideways to see all of it.

The reference system with the security-lab edge. Every box is traced to source lines in the editable Archify file diagrams/zero-to-prod.architecture.json.
Open at full size (new tab)
Read this figure as text
  1. A client sends HTTPS requests to the nginx ingress, which allows only listed routes and asks oauth2-proxy to check the session. Keycloak is the identity provider and is reached only through the ingress; the API fetches its signing keys the same way.
  2. The Work Items API validates the access token itself, then commits a processing job and an outbox row to PostgreSQL in one transaction.
  3. The outbox publisher, in the same binary as the API, claims unpublished rows, publishes them to RabbitMQ with publisher confirms and marks them published.
  4. RabbitMQ delivers to the worker, which verifies the delivery identity against PostgreSQL and completes the job in one transaction before acknowledging.

One request, step by step

One request followed from acceptance to acknowledgement. The order of the steps is the design: nothing is acknowledged before it is durable, and a restore cannot make a stale message act on a reused ID.

Fig. 2Work Items: one request from accept to acknowledgement

Sequence of one processing request: accept in one transaction, respond 202, publish with confirmation, deliver, verify the delivery identity, complete in one commit, then acknowledge.

Scroll the figure sideways to see all of it.

Sequence drawn from api/store.go, api/outbox_publisher.go, worker/message.go and worker/complete.go. Source: diagrams/zero-to-prod.sequence.json.
Open at full size (new tab)
Read this figure as text
  1. The client posts to /items/{id}/process. The API commits a processing job and an outbox row (with a random delivery id) in one transaction and answers 202 Accepted.
  2. The outbox publisher claims the next unpublished row, publishes it to RabbitMQ and waits for the broker's confirmation. Without a confirmation the row stays unpublished and is tried again.
  3. After a confirmed publish the publisher marks the row published.
  4. RabbitMQ delivers the message to the worker. The worker verifies the delivery id against PostgreSQL; a stale message after a restore is rejected.
  5. The worker records the result and marks the job done in one commit, and only then acknowledges the message.

Engineering decisions

  • Durable acceptance before publishing

    Accepted work is persisted with an outbox row before anything is sent to the broker; success is only recorded with the business result.

    ADR 0001, ADR 0003

  • Random delivery identity and explicit redrive

    Numeric IDs can be reused after a snapshot restore, so each delivery carries a random identity checked against the database; lost deliveries are redriven by an explicit, auditable offline command.

    ADR 0009

  • Server-verified TLS from a name-constrained internal CA

    PostgreSQL and RabbitMQ are reached over verified TLS from a separate internal CA limited to exactly the service names, with failure modes (untrusted issuer, wrong name, expiry) exercised.

    ADR 0006 to ADR 0008

  • Admission control at the ingress

    Per-peer and aggregate request budgets with 429 shedding, measured before and after.

    ADR 0010

  • Resumable secret rotation

    A protected-file secret boundary and an API database password rotation that can be interrupted and resumed without a third password or re-enabling the old one.

    ADR 0011

  • Observability with bounded cost

    Prometheus metrics, OpenTelemetry traces and logs, trace context persisted in the outbox and carried in AMQP headers, bounded label cardinality, and written SLOs.

    ADR 0012

Trade-offs

  • At-least-once delivery

    The outbox makes accepted work durable, but a message can arrive more than once. The worker treats a job that already finished as acknowledged rather than processing it again.

    ADR 0003

  • Restore recovery is an operator step

    Random delivery identities stop stale messages after a restore, but republishing accepted jobs is an explicit offline command, not an automatic repair.

    ADR 0009

  • Verified TLS has a running cost

    A private CA limited to exact service names and verified handshakes on every hop is stricter than most labs. The documented gap is how it fits high-availability hostnames.

    ADR 0006 to ADR 0008

  • Shedding load protects the API, not the capacity plan

    Ingress budgets return 429 under overload. Whether those limits match measured capacity is one of the open integration gaps.

    ADR 0010, ADR 0013

Implementation

Services
Go (API and worker), PostgreSQL 18, RabbitMQ 4, React, Vite, TypeScript (UI)
Security lab
nginx ingress, Keycloak, oauth2-proxy, Valkey, private CAs and verified TLS
Observability
OpenTelemetry, Prometheus, Grafana, Loki, Jaeger
Delivery and supply chain
Docker Compose, GitHub Actions, govulncheck, Trivy, SBOM

Testing and verification

Verification results for Zero-to-Prod
CheckResult
Application TLS257 checks pass
Keycloak TLS227 checks pass
Internal TLS (PostgreSQL, RabbitMQ)129 checks pass
Authentication86 checks pass
Authorization74 checks pass
Log hygiene38 checks pass
Ingress and reachability77 checks pass (native Linux)
Go tests, restore recovery, secret rotationpass against disposable PostgreSQL and RabbitMQ

Results re-run in November 2026 with the repository's own tools in rootless Docker; the counts are those printed by each run and differ from the older figures recorded in individual experiment write-ups as the suites grew. Reproduce them with tools/security-lab-local (verify-app-tls, verify-keycloak-tls, verify-internal-tls, verify-authentication, verify-authorization, verify-log-hygiene and verify). The CI gate on main covers the Go tests, govulncheck and the API and worker image scans; the destructive lab verifications are run by hand and their evidence is committed with each experiment.

Security and reliability

  • Crash points between commit, publish, processing and acknowledgement are exercised with real process crashes, duplicate and concurrent deliveries, a PostgreSQL outage and snapshot recovery with stale broker messages.
  • Authentication and authorization are deny-by-default with a principal-by-action matrix verified in the security lab; log-hygiene checks scan service logs for credentials, cookies and tokens.
  • Every shipped image passes a vulnerability gate in CI (Go standard-library advisories through govulncheck, plus an image scan with an SBOM). Third-party lab images are not yet gated; see the limitations.

Operations

  • Runs locally with Docker Compose; every lab uses its own project name, ports and disposable volumes.
  • Measured numbers are single-host lab measurements, not production claims. For example the availability lab recorded database point-in-time recovery in 13.18 s and fenced promotion in 5.55 s on one machine.
  • The operations lab's own readiness review reports 89.16% availability and 97.27% freshness during a fault window, below its 99.5% and 99% targets, with the recovered period meeting them. The repository records that miss rather than hiding it.

Known limitations

  • Local and single-host only: no cloud provider, no independent-host or regional failover, no human on-call exercise. The repository's own verdict is controlled local experimentation only.
  • Third-party lab images (nginx, oauth2-proxy, Keycloak, PostgreSQL, RabbitMQ, Valkey, Grafana and others) still carry HIGH or CRITICAL scanner findings. Since 2026-11-14 a manual and weekly workflow reports them for the 14 pinned images, but nothing gates on them and reachability was not analysed.
  • Documented integration gaps remain design decisions: HA hostnames versus the internal CA, classic versus quorum queues, ingress limits versus measured capacity, plaintext telemetry hops, single-API rotation tooling, and alerting for the authenticated profile.
  • The security lab's verification tool is a single large Bash program; it works but is hard to change safely.

Sources

Editable diagram sources: diagrams/zero-to-prod.architecture.json and diagrams/zero-to-prod.sequence.json in the portfolio repository.