A short-link redirect looks like the simplest thing a web service can do: take a slug, return a 301 or 302. It is also the one request every click on every link has to pass through, so we built it as its own service with a written latency budget.
This post walks through that service: the choices we made, the reasons recorded in our ADRs, a few trimmed excerpts from the code, and a benchmark of what one request costs in-process. The benchmark is local and narrow, and we will say exactly how narrow. The conclusion is a little anticlimactic.
Split by latency budget, not by domain
The first decision (ADR-0013) was to divide the system by how fast each part has to be, not by business area. A link service that handled both redirects and link CRUD would share one latency budget between two very different workloads.
So there are three tiers:
- Hot path:
edge-redirectonly. Target p50 5 ms and p95 15 ms on a cache hit. Nothing synchronous beyond the cache lookup. - Warm path:
api-core,analytics-api,billing. User-facing CRUD, ClickHouse queries, payments. - Cold path: async workers fed by the event bus, such as
click-ingester, notifications and the URL scanner.
The 5 ms figure is a design target recorded in the ADR. It is not a measured production number, and we are not presenting it as one.
The rule this buys is easy to enforce in code review: if it is not a cache lookup, it does not belong in the redirect handler.
Why Go, and why fasthttp
ADR-0002 picks Go for the latency-sensitive services. The reasons are unglamorous: static binaries that deploy trivially, goroutines for concurrency, short and tunable GC pauses, and a team that already knew the language. Rust was considered and set aside because the development cost was not justified at our scale. The ADR names a trigger for revisiting it: if p99 on cache hits exceeds 50 ms sustained at 10K RPS, benchmark Rust for this one service.
ADR-0003 goes one level down and picks fasthttp over net/http for the HTTP layer of this single service. fasthttp pools its request and response objects, which cuts allocation and GC pressure at high request rates. The ADR is honest about the cost: it does not work with the net/http middleware ecosystem, and its ownership rules (you must not hold a RequestCtx after the handler returns) are an easy way to introduce bugs. Every other Go service in the repo stays on net/http and chi.
That ownership rule shows up in the code. When a click is recorded, the handler copies what it needs out of the context before handing work to a goroutine:
// services/edge-redirect/internal/handler/redirect.go (trimmed) // Snapshot fields before the fasthttp ctx is recycled; the goroutine below // outlives the request cycle. fullIP, _ := netip.AddrFromSlice(clientIP(ctx)) acceptLang := string(ctx.Request.Header.Peek("Accept-Language")) ... h.spawn(func() { h.finishClick(ev, fullIP.Unmap(), acceptLang) }) The lookup: L1, then Redis, then origin
ADR-0004 describes the cache. The source of truth is Postgres behind api-core, and a round trip there on every request would eat the whole budget. So the service asks three places in order.
client | v Caddy (TLS) --> edge-redirect (Go, fasthttp) | | 1. L1: in-process LRU, TTL in seconds | 2. L2: Redis, longer TTL | 3. origin: api-core (gRPC Resolve, else HTTP) | +--> 301/302 back to the client | +--> goroutine: enrich click, Produce() ---> Redpanda | v click-ingester | v ClickHouse The resolver that implements this is short enough to read in one go:
// services/edge-redirect/internal/resolver/resolver.go (trimmed) func (r *Resolver) resolve(ctx context.Context, host, slug string) (*origin.Link, error) { key := cacheKey(host, slug) if v, ok := r.l1.Get(key); ok { return v, nil } if v, ok := r.l2.Get(ctx, key); ok { r.l1.Set(key, v) return v, nil } link, err := r.origin.Resolve(ctx, host, slug) if err != nil { return nil, err } r.l1.Set(key, link) r.l2.Set(ctx, key, link) return link, nil } L1 is hashicorp/golang-lru with expiry. A hit is a map lookup in the same process, with no network at all. The ADR's argument against Redis-only is that every request would pay a network round trip (it estimates 0.5 to 1 ms inside a datacenter) while an in-process hit costs about 50 ns. Redis then absorbs the long tail of less popular slugs so they do not all fall through to origin. The ADR also notes the system degrades sensibly: if Redis is down, L1 still serves recent hits.
The trade-off is that you now have two TTLs, and a short L1 TTL means a deleted link cannot be served forever by one node. That is stated in the LRU's doc comment, and it leads to invalidation.
Cache invalidation
TTLs alone would make edits feel slow. ADR-0004 adds explicit invalidation on link update and delete. What the code does today is this: after every link mutation, api-core deletes the Redis key and publishes the cache key on a Redis pub/sub channel. Each edge process subscribes and evicts its own L1 copy.
// services/edge-redirect/internal/cache/invalidate.go (trimmed) // api-core already DELs the L2 key; this channel only exists to evict the // per-process L1 copy so an edit is live in about a second instead of after // the L1 TTL. const InvalidateChannel = "elido:link:invalidate" The subscriber runs in a background goroutine and is never on the request path. If Redis is unavailable, the only consequence is that L1 entries live out their TTL. Note that the ADR text mentions Redpanda for these events; the implementation we read uses Redis pub/sub, and the code is what we describe here.
Clicks: fire and forget
Analytics is the reason a redirect service has side effects at all, and side effects are where latency budgets go to die. The rule from ADR-0013 is that the response never waits for them.
The handler builds a click event from cheap header copies, then starts a goroutine. That goroutine does the expensive parts (IP classification, scanner flagging, truncating the IP, hashing the visitor) and publishes the event to Redpanda, which speaks the Kafka protocol, through a franz-go producer. A separate service, click-ingester, consumes the topic and writes to ClickHouse. The redirect service never talks to ClickHouse.
The consequence is the usual one for this design: a click can be lost if the process dies between the response and the produce call, and we accept that trade for a hot path that has no dependency on the analytics store being up.
What one request costs
Now the numbers. These come from Go's go test -bench . -benchmem on an Apple M3 laptop, run on 2026-11-18. They are in-process handler benchmarks. There is no network, no TLS and no real client, so they measure our code and nothing around it.
| Benchmark | ns/op | B/op | allocs/op |
|---|---|---|---|
| Redirect, L1 hit, full request including spawning click work | 4032 | 4680 | 71 |
| Redirect, L1 hit, request path only | 3619 | 3728 | 52 |
| Click enrichment (runs off the request path) | 911 | 912 | 19 |
| Redirect through the CTA overlay page | 28781 | 36526 | 297 |
| Blocklist check | 44 | 0 | 0 |
| Query-parameter forwarding (mixed case) | 379 | 192 | 3 |
Read the first two rows together: The request path itself is about 3.6 microseconds, and starting the click work adds about 0.4 more. The click enrichment, at roughly 0.9 microseconds, happens after the response is already decided. The blocklist check allocates nothing, which is the kind of result you hope for from a check that runs on every request. The CTA overlay page costs about eight times a plain redirect, since it does more work per request.
The allocation profile
Fifty-two allocations for a redirect is more than a pooled HTTP library might lead you to expect. Profiling the request path shows where they come from:
- fasthttp header and argument handling, which are the largest allocators.
- A
context.WithTimeoutfor the origin call, created on every request even when L1 answers and the origin is never called. - Client IP parsing with
net.ParseIP, done more than once per request.
You can see the second one in the handler:
// services/edge-redirect/internal/handler/redirect.go (trimmed) resolveCtx, cancel := context.WithTimeout(ctx, h.cfg.OriginTimeout) defer cancel() link, err := h.resolver.Resolve(resolveCtx, host, slug) All three are fixable. Creating the timeout only once the resolver misses L1 is a small change, and parsing the client IP once instead of several times is another.
Why we have not fixed them
At about 3.6 microseconds, the request path uses less than 0.1% of the 5 ms target. If we removed every allocation in the list above and saved, say, a third of that, the user would see no difference. A real redirect spends its time on the TCP handshake, the TLS handshake, and the distance between the client and the server. Those are measured in milliseconds, and no amount of work on net.ParseIP changes them.
There is also a cost on the other side of the ledger. Hand-tuning a handler to shave allocations tends to make it harder to read, and this handler already has to deal with passwords, previews, agent-readable JSON responses and warning pages.
So the plan is deliberately boring: keep the benchmarks in the repo so a regression shows up, fix the cheap allocations when we are in that code anyway, and put effort where the time is. We run in production today as a single EU VPS behind Caddy, so network distance is the next thing we would look at, long before another microsecond of Go.
The benchmark does not tell us about p99 under load, GC behavior at sustained throughput, or cache hit rate on real traffic. It tells us our own code is not the problem. That is a narrower claim than "fast", and it is the one we can back up.
What we would repeat
Split services around the budget, because "only cache lookups on the hot path" cannot be enforced inside a shared service. Push slow work behind a queue. Measure in-process, then say what you did not measure.
Elido is a hosted URL shortener built EU-first with custom domains, QR codes and click analytics. The docs are at elido.app/docs.