Revision · Build & Scale a Real Service
This part turned the book’s concepts into a running service — Snip, a read-heavy URL shortener — and scaled it one deliberate step at a time, re-running the load test so every improvement was a number, not a claim.
What this part covered
Section titled “What this part covered”- The MVP — a minimal axum service with routes, shared state, and a
/healthcheck gives you the smallest thing that runs before you optimize anything. - Storage with Postgres — persist links behind a connection pool, not a single connection, so concurrent requests don’t serialize on one socket.
- Caching with Redis — cache-aside on the hot redirect path buys sub-millisecond reads, and the TTL is a straight speed-vs-staleness trade you set on purpose.
- Load testing & measuring — design against p50/p95/p99 percentiles, not averages, and establish a baseline number you commit to beating with each change.
- Scaling out — statelessness is the precondition; once state lives in Postgres/Redis you can add replicas behind nginx and trade single-box simplicity for near-linear throughput.
- Rate limiting — a fixed-window counter must live in Redis so the limit is shared across replicas, and edge bursts are the price the simple window pays.
- Async work with a queue — enqueue click counts and let a separate worker drain them, keeping the redirect path fast at the cost of eventually-consistent counts — and never leave the queue unbounded.
- Observability — structured logs, a health endpoint for the load balancer, and
/metricscounters (the cache-hit ratio especially) are how you prove the scaling worked. - Resilience — timeouts are the foundation, retries are safe only for idempotent operations, and graceful degradation lets cached redirects survive even when Postgres is down.
- Deploy with Docker Compose — a multi-stage build (build big, ship small) and one
compose upbrings the whole stack — Postgres, Redis, app replicas, nginx — online together.
The takeaway
Section titled “The takeaway”The throughline was what does this buy us, and what does it cost?, made measurable: a cache buys read speed and costs staleness, replicas buy throughput and cost statelessness, a queue buys a fast redirect and costs count freshness. Each win was verified against the load-test baseline before moving on. From here, Where to Go Next points past the single-box stack toward sharding, a CDN, and multi-region — the same trade-offs at larger scale.