Skip to content

Evaluate service layer refactoring for links/redirect.rs #332

@piffio

Description

@piffio

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

  1. KV lookup for short code (sub-10ms edge read)
  2. D1 fallback on KV miss
  3. 301 redirect issued immediately
  4. 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****

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions