KlikTaut
A URL shortener API with click analytics, built in Go on Fiber v3. Redirects are served from Redis in about 2 ms while clicks are recorded in the background, and every link exposes device, browser, referrer, and 7-day traffic breakdowns.
KlikTaut is a URL shortener backend with click analytics. It turns a long URL into a short one, either a random 7-character code or a custom alias, then records what happens after that link is shared: device, browser, OS, referrer, and timestamp for every visit. The data rolls up into per-link analytics and an overview across all links.
It is an API-only service, meant to sit behind a dashboard or be called from scripts. Links, analytics, and stats share one small endpoint set, and every response uses the same envelope with a documented error code, so a client can tell what failed from the code.
Key Features
- Short Links With Custom Aliases: Random base62 codes or a chosen alias; reserved words and aliases already in use are rejected with 409.
- Fast Redirect Path: The short code is read from Redis, and the click row plus the link counter are written in a background goroutine, so the 302 never waits on the database.
- Per-Link Analytics: Total clicks, unique visitors, device and browser breakdown, top referrers, and a 7-day click series.
- Overview Statistics: Totals across the whole instance, including active, expired, and deleted links plus clicks today.
- Lifecycle Management: Expiration, soft delete, and partial updates that take effect on the redirect path immediately.
- API Key and Rate Limiting: Middleware with constant-time key comparison and Redis counters for both the API and the redirect path.
- Docs From the Spec: An OpenAPI 3.0 file served through Scalar, with auth and try-it-out requests in the page.
Technical Challenge
The redirect path is the only endpoint that gets hit constantly, and two requirements pull against each other. Reading from PostgreSQL on every visit is too slow for a link shortener, but skipping the write loses the analytics that justify the product.
So the service splits the two. A request checks Redis first; only a miss reaches PostgreSQL, and the result is cached. The click goes to a goroutine, so the 302 never waits on an insert. That leaves cache correctness: PATCH and DELETE delete the cache key instead of waiting for a TTL, so a deactivated or expired link stops redirecting immediately rather than minutes later.
The rest of the service is layered, with handlers, services, and repositories, so HTTP concerns, business rules, and SQL stay in separate files. Bots are detected from the user agent and left out of the click totals, but they still show up in the device breakdown, since link previews fetch URLs too and the owner should see that traffic without it inflating the click count.
Outcome
Load tested at 5000 requests and 50 concurrent clients against a warm cache:
- p50 redirect latency (ms): 2.24
- p95 redirect latency (ms): 4.95
- p99 redirect latency (ms): 6.61
- Throughput, requests per second: 19000
The target was p50 under 50 ms, so the margin is large. The numbers are local measurements on the development machine and exclude the async click write. A cold cache or a cold free-tier container will be slower; the free tier spins down after about 15 minutes idle, so the first request can take 30 to 60 seconds. The service also ships with a distroless Docker image that runs migrations on boot, a Render blueprint, and CI that covers vet, lint, race tests, and a build.
Known Limits
unique_visitorscounts distinct IP addresses, so visitors behind one NAT count as a single visitor.- Rate limiting uses a fixed window, which allows a burst of up to twice the limit around a window boundary.
- If Redis goes down, rate limiting fails open and redirects fall back to PostgreSQL. Availability was chosen over strictness at this scale.
Tech Stack
- Language: Go 1.27
- HTTP Framework: Fiber v3
- Database: PostgreSQL 17 (GORM)
- Cache & Rate Limiting: Redis 8
- Validation: go-playground/validator
- API Docs: OpenAPI 3.0 served through Scalar
- Deployment: Docker (distroless) with migrations on boot, Render blueprint
