Skip to content

Auth strategy assessment: Couch /_session vs in-house JWT - #16

Closed
PeterBaker0 wants to merge 2 commits into
mainfrom
feat/auth-strategy-benchmark-817d
Closed

Auth strategy assessment: Couch /_session vs in-house JWT#16
PeterBaker0 wants to merge 2 commits into
mainfrom
feat/auth-strategy-benchmark-817d

Conversation

@PeterBaker0

@PeterBaker0 PeterBaker0 commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Summary

Critical assessment of Couch GET /_session identity resolution vs in-house JWT, measured with the ACL perf harness under PROFILE=true.

Clarification

There is no ACL TTL — document ACL is changes-fed. The 5s knob is SESSION_CACHE_TTL_MS (principal / session-response cache). Defaults already use 5s.

Measured results (sticky Bearer JWT clients)

Variant overall ops/s HTTP auth ms/req auth share Δ overall vs 5s
Couch session TTL=0 245.7 1.966 26% -14.5%
Couch session TTL=1s 277.6 0.028 0.5% -3.4%
Couch session TTL=5s (keep-as-is) 287.3 0.019 0.3% baseline
Couch session TTL=30s 292.2 0.019 0.3% +1.7%
Hybrid Bearer local JWT + 5s 284.4 0.016 0.3% -1.0%
Local JWT-only + 5s 280.0 0.018 0.3% -2.5%
Local JWT-only, no cache 258.9 0.717 11% -9.9%

Upstream Couch remains ~55–75% of HTTP mean duration; auth is noise once the 5s principal cache is warm.

Verdict

  • Keep Couch /_session + 5s cache for mixed Basic/Cookie/JWT — already removes almost all session tax vs TTL=0.
  • Hybrid (JWT_LOCAL_VERIFY=true with session still on) is the right upgrade for JWT-heavy apps; ops/s ≈ keep-as-is, but Bearer skips /_session even at TTL=0.
  • JWT-only only if you drop Basic/Cookie and accept JWT exp as revocation (role changes in _users won’t apply until re-mint).
  • 30s TTL is not worth the wider demotion lag under sticky load.
  • In-house JWT does not create a stronger trust domain — Couch still validates the same keys on the upstream hop.

Full write-up: docs/auth-strategy-assessment.md. Re-run: pnpm test:perf:auth.

Code

  • Hybrid Bearer fast-path when both session resolve and JWT_LOCAL_VERIFY are on
  • Local JWT principals join the same LRU+TTL cache
  • pnpm test:perf:auth + report assembler; PERF_ADMIN_JWT for Bearer-only admin setup

Test plan

  • pnpm test (unit, 209)
  • pnpm lint / pnpm typecheck
  • pnpm test:perf:auth (7 variants; tables in assessment doc)
Open in Web Open in Cursor 

cursoragent and others added 2 commits July 25, 2026 02:32
Allow JWT_LOCAL_VERIFY alongside Couch /_session so Bearer clients skip the
session RTT while Basic/Cookie keep Couch as source of truth. Cache local JWT
principals under SESSION_CACHE_TTL_MS. Add pnpm test:perf:auth to compare TTL
variants, hybrid JWT, and in-house JWT-only under PROFILE=true.

Co-authored-by: Peter Baker <PeterBaker0@users.noreply.github.com>
Fill docs/auth-strategy-assessment.md from PROFILE=true ACL harness runs
across session TTL 0/1s/5s/30s, hybrid Bearer JWT, and local JWT-only.
Mint admin JWT for Bearer-only proxy setup; assemble reports from on-disk
variant dirs so partial re-runs merge cleanly.

Co-authored-by: Peter Baker <PeterBaker0@users.noreply.github.com>
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.

2 participants