Skip to content

Better Timeout Logic; Added Idempotency Key to DB#19

Merged
Howard-nolan merged 1 commit intomainfrom
feature/reliability
Dec 19, 2025
Merged

Better Timeout Logic; Added Idempotency Key to DB#19
Howard-nolan merged 1 commit intomainfrom
feature/reliability

Conversation

@Howard-nolan
Copy link
Owner

Change Summary:

  • Added request timeouts, readiness endpoint, and cache-aware handlers with idempotent shorten inserts; wrapped the server in http.TimeoutHandler and handled DB timeouts explicitly.
  • Introduced idempotency key support (schema + insert logic) and documented readiness in OpenAPI; added ready route, updated README with test commands.
  • Expanded tests: handler unit tests now cover timeouts/idempotency and redirect timeouts; integration test runs against in-memory DB.

How It Works:

  • ShortenHandler reads the request ID as an idempotency key, uses ExecContext with an upsert-by-key, returns 408 on context cancel, and reuses the existing code on conflict.
  • RedirectHandler checks cache, then QueryRowContext; returns 408 on context cancellation, 404 on miss.
  • /readyz pings the DB with PingContext; server wraps the router with http.TimeoutHandler. Schema includes a unique idempotency_key on links.

Additional Notes (optional):

  • Integration tests run with go test -tags=integration ./...; unit tests via go test ./....

@Howard-nolan Howard-nolan merged commit 8ea1376 into main Dec 19, 2025
github-actions bot added a commit that referenced this pull request Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant