Skip to content

Optimize caching, polling, and retry strategies for performance#760

Merged
jamespepper81 merged 4 commits into
mainfrom
dev
Jun 1, 2026
Merged

Optimize caching, polling, and retry strategies for performance#760
jamespepper81 merged 4 commits into
mainfrom
dev

Conversation

@jamespepper81
Copy link
Copy Markdown
Contributor

No description provided.

claude and others added 4 commits June 1, 2026 20:41
Reduce origin (Cloud Run) request load that was driving the ~9x request
spike:

- Update-version checker (app layout): was fetching the full current page
  with `no-store` every 60s on every signed-in tab, forever. Now polls
  ~every 15 min, only while the tab is visible, with jitter so clients
  don't poll in lockstep, and stops once an update is detected. This was
  the single biggest driver of both the request spike and uncached CDN
  bandwidth.
- Market page: the 60s refresh is a Server Action hitting the origin;
  throttled to 5 min (underlying market data revalidates on 60s+ anyway).
- BTC price ticker: throttled from 60s to 5 min.
- Wallet error-retry: replaced the fixed 3s retry with exponential backoff
  (3s/6s/12s, capped at 60s) and debounced the on-focus retry so a focus
  storm can't fire back-to-back origin calls.

https://claude.ai/code/session_01PAJeRubmNYpCjy1PvvyfgJ
Address the Firebase App Hosting CDN cache-miss rate (uncached origin
bandwidth jumped 52 GiB -> 726 GiB). App Hosting only edge-caches
responses whose origin emits a cacheable Cache-Control header, and almost
nothing did.

next.config.ts headers():
- /public static assets (svg/png/jpg/webp/ico/woff/woff2): 1 week + SWR.
- manifest.json: 1 day.
- /landing and /about (public marketing pages): s-maxage 1h + SWR.
- Signed-in app shells (dashboard, analysis, security, chat, report,
  coin-control): s-maxage 5m + SWR. These render an identical shell per
  user — wallet data loads client-side via Server Actions and auth gating
  is client-side — so only the static shell is cached; per-user data
  requests are separate POSTs that always reach the origin. Parameterised
  routes (address/[address] etc.) and /api/* are intentionally excluded.

Also:
- /landing and /about: add `revalidate = 3600` (ISR) to back the headers.
- sitemap: use a stable lastModified instead of `new Date()` so it stops
  appearing "always new" to crawlers on every build.

https://claude.ai/code/session_01PAJeRubmNYpCjy1PvvyfgJ
Code-review follow-up. In the version-update checker, if the
`fetch(window.location.href)` is still in flight when the effect is
cleaned up (component unmounted), the resolved callback could call
`setIsUpdateAvailable` on an unmounted component. The cleanup already
sets the shared `stopped` flag, so check it before the state update.

https://claude.ai/code/session_01PAJeRubmNYpCjy1PvvyfgJ
Optimize caching, polling, and retry strategies for performance
@jamespepper81 jamespepper81 merged commit 08dc4ba into main Jun 1, 2026
8 checks passed
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