Performance Baseline — Cardsite Link Manager
Hot paths
Two endpoints dominate production traffic:
| Path | Description | Target 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)
| Metric | Threshold |
|---|---|
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.
| Date | VUs | Duration | Redirect p50 | Redirect p95 | Redirect p99 | Biolink p50 | Biolink p95 | Biolink p99 | Error rate |
|---|---|---|---|---|---|---|---|---|---|
| TBD | 100 | 5 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 queryservices.GeoIPService.Lookup— MaxMind lookup per requestservices.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:
- Redis is running and connected (
curl /ready | jq .checks.redis) - Cache TTL is not too short (default: 10 min)
- DB connection pool is not exhausted (
/metrics | grep db_pool)
Scaling guidance
| VUs | p95 redirect | Action |
|---|---|---|
| < 100 | < 50 ms | No action |
| 100–500 | 50–200 ms | Check Redis hit rate |
| 500–1 000 | 200–500 ms | Add read replica for stats queries |
| > 1 000 | > 500 ms | Horizontal 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