Skip to main content

Inside Magpie's backend

This section follows one route, gateway.example.test:8080 with a fixed credential pair, through Magpie. You will see who owns it, where it waits, which requests a worker makes, when results become durable, and how a rotator uses them. You can follow the explanations without knowing Go. Code links and named functions let you inspect the implementation afterward.

If proxy routes, workspaces, or judges are unfamiliar, begin with How Magpie works.

One process with several responsibilities​

The default backend is one Go process. A goroutine is a concurrent task inside that process. API handlers, worker pools, maintenance jobs, and rotating listeners run together and share database and Redis clients.

Scroll to see a wide diagram, or open a larger view.

Read the arrows as data dependencies. The statistics transaction happens asynchronously after checking. A listener does not wait for an in-flight check to finish before choosing from already committed evidence.

Read in this order​

Allow about an hour for the chapters and checkpoints. Use the code-reading exercises as a second pass if you want to make backend changes.

ChapterTimeQuestion it answers
Startup and shutdown5 minWhat starts, what is ready, and what survives a restart?
API requests and workspace ownership5 minHow does a request get permission to touch a route?
Import and scraping7 minHow do input addresses become managed proxies?
Queue scheduling and leases8 minHow do workers share millions of recurring checks?
The checker10 minWhat is one cycle, and why can workspaces disagree?
Results, storage, and replay10 minWhen is a result durable, and what happens after failure?
Rotating traffic5 minHow does a listener choose an upstream?
Background jobs and replicas5 minWhat runs around the loop without making each check heavier?
Code map and reading exercises5 minWhich files and tests should I read next?

Keep these storage boundaries in mind​

PlaceWhat it holdsWhat recovery means
PostgreSQLResource ownership, encrypted managed credentials, settings, committed check history, current evidence, outboxesRestore the durable record from backups.
Redis proxy queueActive route payloads, due times, temporary leasesReconstruct active inventory from PostgreSQL. This cannot recreate lost measurements.
Redis statistics streamResults waiting for PostgreSQL ingestionReplay surviving entries, subject to Redis persistence and overload policy.
Process memoryCompiled settings, caches, HTTP clients, fallback results, unflushed usageRebuild derived state after restart. Buffered results and counters can be lost.
Backend data volumeGlobal settings and an automatically generated JWT signing key when configured that wayPreserve the volume and secrets across container replacement.

PostgreSQL commit is the durable check-result boundary. A successful upload, a completed network request, and Redis accepting a result are earlier stages with different guarantees.

The source walkthrough provides a compact companion for developers. The public chapters explain the same contracts step by step.

Start with startup and shutdown.