Skip to content

API-Fallbacks, Stale-Cache & Snapshots für Ausfallsicherheit + Tests/CI - #1

Draft
devbadya wants to merge 1 commit into
mainfrom
cursor/reliability-fallbacks-and-hardening-0272
Draft

devbadya wants to merge 1 commit into
mainfrom
cursor/reliability-fallbacks-and-hardening-0272

Conversation

@devbadya

@devbadya devbadya commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Problem

Markets, Coins und Fear & Greed fielen zeitweise aus: Wenn eine externe API (CoinGecko, CoinMarketCap, Alternative.me) nicht antwortete, lief der Cache-TTL ab und die Endpoints lieferten 503. Nach jedem Neustart/Deploy war der Cache zudem komplett leer.

Lösung

Automatische API-Fallbacks:

Daten Primär Fallback
Fear & Greed Alternative.me CoinMarketCap F&G → eigener Composite aus Marktdaten
Alle Coins CoinMarketCap CoinGecko (gleiche Datenform, gekennzeichnet als Fallback)
Markets CoinGecko Überblick aus den gecachten CMC-Coins gebaut
CMC Live CoinMarketCap letzte bekannte Liste aus dem Cache statt 502

Letzte gute Daten bleiben erhalten:

  • Cache ohne TTL: schlägt ein Refresh fehl, werden die letzten guten Daten weiter ausgeliefert (statt 503).
  • Disk-Snapshots unter server/.cache/: nach Neustart/Deploy sind sofort Daten da (Warm-Start).
  • Retry mit Backoff für CoinGecko/CMC/Alternative.me (kein Retry bei 4xx/Rate-Limit).

Härtung (Quick Wins):

  • Rate-Limiter greift nur noch auf /api-Routen, nicht mehr auf statische Assets.
  • /api/health zeigt pro Datensatz: verfügbar, Quelle, Alter, letzter Fehler (ok / degraded / starting).
  • CSP: unsafe-inline-Scripts nur noch für das Legacy-Frontend (public/), nicht für den React-Build.

Tests & CI:

  • Vitest-Suite mit 35 Tests (Dedup/Ähnlichkeit, F&G-Klassifikation/Composite, Fallback-Mapping, Pagination, Retry, Snapshot-Store).
  • GitHub Actions: Server-Typecheck + Tests, Client-Lint + Build.
  • 3 bestehende Lint-Fehler im Client behoben (usePolling, CoinDetail, main.tsx), npm audit auf 0 Findings.

Verifiziert

  • Alle 35 Tests grün, Server-Typecheck sauber, Client-Lint + Build sauber.
  • Server manuell gebootet: ohne CMC-Key → Coins kommen automatisch über CoinGecko-Fallback.
  • Mit absichtlich kaputtem CoinGecko-Key neu gestartet → Warm-Start aus Snapshots, Markets aus CMC-Fallback gebaut, alle Endpoints liefern weiter Daten; /api/health weist Quelle und letzten Fehler pro Datensatz aus.
Open in Web Open in Cursor 

…lity

- Fear & Greed: alternative.me -> CMC F&G -> composite from market data
- Coins: CoinMarketCap -> CoinGecko fallback (same data shape)
- Markets: CoinGecko -> overview built from cached CMC coins
- Last-good data is kept (no TTL) and persisted to server/.cache for warm starts
- Retry with backoff for CoinGecko/CMC/alternative.me (no retry on 4xx)
- /api/cmc/live serves cached list instead of 502 when live update fails
- Rate limiter now only applies to /api routes, not static assets
- /api/health reports per-dataset availability, source, age and last error
- CSP: unsafe-inline scripts only for legacy public/ frontend
- Fix pre-existing lint errors in client (usePolling, CoinDetail, main.tsx)
- Add vitest suite (35 tests) and GitHub Actions CI (typecheck, tests, lint, build)

Co-authored-by: Sebastian <devbadya@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