Context
src/api/links/redirect.rs is the hot path for all link redirects and currently
makes direct KV/repository calls, bypassing the service layer. Intentionally
excluded from the service layer migration (refactor/fix-backend-layer-violations)
due to performance concerns.
Current pattern
- KV lookup for short code (sub-10ms edge read)
- D1 fallback on KV miss
- 301 redirect issued immediately
- Async analytics write to D1 (fire-and-forget, post-response)
Question to evaluate
Can LinkService (or a new RedirectService) be introduced without adding latency?
Options:
- Thin service wrapper — same direct KV/D1 calls internally
- Partial refactoring — service for analytics write, direct for KV lookup
- Leave as-is — document the direct-call exception in architecture notes
Acceptance criteria
- Redirect latency must not regress (measure p50/p99 before and after)
- Code compiles cleanly and all integration tests pass
- If refactored: zero direct
crate::repositories:: or crate::kv:: calls in handler****
Context
src/api/links/redirect.rsis the hot path for all link redirects and currentlymakes direct KV/repository calls, bypassing the service layer. Intentionally
excluded from the service layer migration (refactor/fix-backend-layer-violations)
due to performance concerns.
Current pattern
Question to evaluate
Can LinkService (or a new RedirectService) be introduced without adding latency?
Options:
Acceptance criteria
crate::repositories::orcrate::kv::calls in handler****