Skip to content
Toolkit

Performance Baseline — Cardsite Link Manager

Hot paths

Two endpoints dominate production traffic:

PathDescriptionTarget p95
GET /l/{shortcode}Short-link redirect< 200 ms
GET /b/{slug}Public biolink page< 500 ms

Both are measured by scripts/load-test.js (k6).


Running the load test

Prerequisites

# macOS
brew install k6

# Linux
sudo gpg -k
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg \
  --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | \
  sudo tee /etc/apt/sources.list.d/k6.list
sudo apt-get update && sudo apt-get install k6

# Docker
docker pull grafana/k6

Quick run (local)

# Start the API locally first
cd apps/api && go run ./cmd/server &

# Run with defaults (100 VUs, ~5 min)
k6 run scripts/load-test.js

# Run against production
k6 run \
  -e BASE_URL=https://prod.cardsite.io \
  -e SHORT_CODE=<a real short code> \
  -e BIOLINK_SLUG=<a real biolink slug> \
  scripts/load-test.js

Save results for comparison

k6 run --out json=results-$(date +%Y%m%d).json scripts/load-test.js

Thresholds (pass/fail gates)

MetricThreshold
redirect_latency p95< 200 ms
biolink_latency p95< 500 ms
redirect_errors rate< 1 %
biolink_errors rate< 1 %
http_req_failed rate< 1 %

The k6 script fails on any breached threshold. No CI job runs it; run it by hand before a release.


Baseline results (establish after first production run)

No baseline has been recorded yet. Fill in this table after running against the production instance with real data, and re-run before each major release.

DateVUsDurationRedirect p50Redirect p95Redirect p99Biolink p50Biolink p95Biolink p99Error rate
TBD1005 min———————

Profiling the redirect path

The redirect handler (/l/{shortcode}) must be fast because it's on every link click. Profile it:

The API exposes no pprof endpoint. Profile with a test binary or with go test -cpuprofile against the redirect handler's tests, or read /metrics (Prometheus) through the stack in scripts/observability/.

Key flame-graph hotspots to watch:

  • repository.LinkRepository.GetByShortCode — cache miss DB query
  • services.GeoIPService.Lookup — MaxMind lookup per request
  • services.DisplayRulesService.Match — display-rule evaluation

Caching the redirect

The redirect handler populates Redis on first hit and serves from cache on subsequent requests. Expected:

  • Cache hit: < 5 ms total
  • Cache miss: 20–80 ms (DB + GeoIP)

If p95 > 200 ms under load, check:

  1. Redis is running and connected (curl /ready | jq .checks.redis)
  2. Cache TTL is not too short (default: 10 min)
  3. DB connection pool is not exhausted (/metrics | grep db_pool)

Scaling guidance

VUsp95 redirectAction
< 100< 50 msNo action
100–50050–200 msCheck Redis hit rate
500–1 000200–500 msAdd read replica for stats queries
> 1 000> 500 msHorizontal scale (2+ API instances behind LB)

Multi-instance deployment: the API is stateless (JWT + Redis sessions), so horizontal scaling is safe. Use a shared PostgreSQL primary with a read replica for track_links / statistics queries.

Source: docs/PERFORMANCE.md

Library