Skip to content
ipreveal.me

Case study

A small service, built to be inspected.

ipreveal.me answers one question, so the interesting part is everything around the answer: how requests are counted, cached, logged and shipped. This page describes the system as it is configured, and where it cuts corners.

01

The request path

ipreveal.me request and log pathsA client reaches the TLS edge, then Varnish. Varnish sends page and asset requests to nginx, which serves the static Next.js export, and API requests to the Go Fiber service. The API consults Redis for rate limiting and local MaxMind GeoLite2 files for lookups, and writes a JSON log file that Alloy ships to Loki.Self-hosted Docker Compose stackObservabilityClientbrowser, curlTLS edgeHSTSVarnishcaches /lookuproutes /apinginxstatic Next.jsexport (HTML, JS)Go + Fiber APIhandlers, limiterRedissliding windowGeoLite2local .mmdb filespages/api/*api.logJSON, truncated IPAlloytails the fileLoki60-day retention
  1. A client requests a page or an API route.
  2. Varnish receives it. Paths under /api/ go to the Go API; everything else goes to nginx, which serves the pre-built static frontend.
  3. The API checks the rate limit in Redis, resolves the real client IP, reads the MaxMind GeoLite2 files on local disk and answers.
  4. Each request is written to a JSON log file that Alloy ships to Loki.

02

API service

The backend is a Go service on Fiber. Middleware runs in a fixed order: security headers, panic recovery, request ID, real-IP resolution, rate limiting, then request logging, so a rejected request still gets an ID and a log line.

Geolocation
MaxMind GeoLite2 databases read from local files. A lookup never makes an outbound network call.
Lookup input
Parsed with net/netip. IPv4-mapped IPv6 is unmapped; loopback, private, link-local, multicast, unspecified and CGNAT (100.64.0.0/10) addresses are rejected with 422.
Output
Plain text for scripts, JSON for programs, one handler per datum. Fields without data are omitted.
Tests
Go tests run with the race detector in CI, alongside a lint gate.

03

Real IP and rate limiting

Behind a proxy, the TCP peer is the proxy, not the visitor. The API honours forwarding headers (Cf-Connecting-Ip, True-Client-Ip, X-Forwarded-For) only when the peer is inside a configured set of trusted proxy ranges (the private ranges, by default). X-Forwarded-For is read from the right, taking the first hop that is not trusted, so entries a client prepends cannot choose the address that gets rate limited.

The limiter is a sliding-window log in a Redis sorted set, keyed by client IP. The default is 100 requests per 60 seconds. If Redis is unreachable the service fails open by default and logs the error; set the option off and it returns 503 instead.

04

Caching

Varnish caches only the lookup routes (/api/lookup/* and /api/json/lookup/*), whose answer depends on the path alone. Routes that describe the caller (/api/ip, /api/json/all and friends) always pass through, because caching them would hand one visitor another visitor’s address. Lookup responses carry Cache-Control: public, max-age=3600; Varnish honours it and defaults to one hour.

The VCL also holds HTML for a short 30 seconds and static assets for an hour, so a page deploy shows up quickly.

05

Logs and privacy

The API writes one JSON line per request to a file: method, path, status, latency, request ID, the User-Agent (control characters stripped, 200 characters at most) and the client IP truncated, to its IPv4 /24 or IPv6 /48 prefix, before it is written. Grafana Alloy tails the file and pushes it to Loki, with level, method, path and status as labels. Loki is configured with 60-day retention (1440 hours), and a test script in the infra repository fails if that setting drifts.

Truncation is a deliberate middle path: enough to spot abuse from a network, not enough to identify a household. Other request headers are not logged.

06

Build and delivery

CI
GitLab CI per repository. Tests and lint run first and gate the image build.
Images
Backend and frontend each build a Docker image, pushed to the registry with a version tag.
Deploy
A successful build triggers the infra pipeline with the new version of that component.
Environments
Docker Compose with a base file plus dev and prod overlays, and profiles to start only part of the stack.
Hosting
Self-managed servers; code lives in a self-hosted GitLab.

07

This frontend

Next.js with a static export: the build produces plain HTML, CSS and JavaScript that nginx serves, with no Node process in production. Fonts are self-hosted at build time, the map on the plate is an SVG path generated from public-domain Natural Earth data at build time, and the page makes no requests to third parties.

The theme is set by a small blocking same-origin script before first paint, so there is no flash, and no inline scripts are needed. That lets the Content Security Policy stay at script-src 'self'.

08

Trade-offs, stated plainly

  • Fail-open limiter. Availability is chosen over strictness: if Redis is down, requests are served unmetered.
  • Truncated, not hashed, IPs in logs. They stay readable for debugging at network granularity, at the cost of being less private than a keyed hash.
  • City-level data. GeoLite2 is free and good enough to name a place; it is not a position fix, and the plate says so.
  • Cache scope. Only lookups are cached. That leaves the busiest route, “what is my IP”, uncached on purpose.
  • No published performance numbers. Latency and uptime figures are left out until they are measured and can be shown.