Skip to content

tanstack: no single-flight on cache MISS/STALE; HITs queue behind SSR in the same isolate (2–4 s TTFB on HIT) #663

Open

Description

@aline-pereira

Problem

On deco-sites/oficina-tanstack (@decocms/tanstack 7.77.2, workers.dev preview), measured with curl (Oct 8, 2026):

Scenario n mean TTFB max
sequential HIT, spaced 3 s 30 0.20–0.57 s 0.42 s
MISS (any route) 50 2.98 s 7.17 s
12 concurrent, same path, all HIT 68 0.50–0.80 s 2.71 s (staircase: 0.19 / 0.5 / 1.5 / 2.6 s)
  1. No single-flight on MISS/STALE. workerEntry.ts has no per-cacheKey in-flight dedupe in this version, so N concurrent MISSes of the same path run N SSRs.
  2. HITs queue behind SSR/revalidation in the same isolate. revalidateInBackground (via waitUntil, ~l.2998-3002) and concurrent MISS renders hold the single-threaded isolate; HITs that arrive meanwhile wait (the staircase above, and "x-cache: HIT" responses at 2–4 s).
  3. Cache API is per-colo; on workers.dev one client was served by 5 colos (GRU, GIG, EWR, ATL, MIA), multiplying MISSes. (Platform; may differ under a zone with Tiered Cache.)

Proposal

  • Single-flight per cache key for MISS and STALE revalidation (one promise per key in isolate memory).
  • Yield during background revalidation (or cap concurrency) so HITs are not starved.
  • Emit Server-Timing for SSR, loaders and cache.match so sites can separate CPU from upstream I/O.

Found while validating deco-sites/oficina-tanstack#479 (QA-165).

🤖 Generated with Claude Code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions