Skip to content

feat(backend): API versioning, pool metrics, tenant isolation, event-driven leaderboard cache#1195

Merged
Emmyt24 merged 1 commit into
nova-launch01:mainfrom
joel-metal:feat/backend-1111-1114-api-versioning-metrics-tenancy-cache
May 28, 2026
Merged

feat(backend): API versioning, pool metrics, tenant isolation, event-driven leaderboard cache#1195
Emmyt24 merged 1 commit into
nova-launch01:mainfrom
joel-metal:feat/backend-1111-1114-api-versioning-metrics-tenancy-cache

Conversation

@joel-metal

Copy link
Copy Markdown
Contributor

Summary

Changes

File What changed
src/index.ts Unified v1Router, /api/v1 canonical mount, /api compat alias, registerPoolMetrics call
src/lib/metrics/index.ts Added db_connections_waiting + db_pool_saturation gauges; updated MetricsCollector.updateDatabaseConnections signature
src/lib/metrics/poolMetrics.ts New – Prisma middleware that tracks in-flight queries → pool gauges
src/routes/tokens.ts tenantMiddleware({ required: true }), tenant-scoped creator filter, tenant-namespaced cache keys
src/routes/tokens.test.ts Updated to send X-Tenant-ID header; assertions include creator scope
src/services/leaderboardService.ts Event subscriptions (burn.created, token.created), invalidateCacheByType(), TTL retained as fallback

Versioning policy

  • /api/v1/ is the canonical versioned prefix going forward.
  • /api/ is a permanent backward-compat alias pointing to the same router.
  • The X-API-Version: v1 header is set on every response from v1Router.
  • Future breaking changes introduce /api/v2 without removing v1.

Pool metric names

Metric Type Description
db_connections_active Gauge In-flight queries (≤ pool size)
db_connections_idle Gauge Idle pool slots
db_connections_waiting Gauge Queries queued beyond pool capacity
db_pool_saturation Gauge active / pool_size (alert on > 0.8)

Pool size configured via DB_POOL_SIZE env var (default: 10).

Leaderboard invalidation triggers

Event Invalidated leaderboards
burn.created most-burned, most-active, most-burners
token.created newest, largest-supply

Publish these events from the burn/token write handlers:

await eventBus.publish("burn.created",  { tokenId });
await eventBus.publish("token.created", { tokenId });

Closes #1111
Closes #1112
Closes #1113
Closes #1114

🤖 Generated with Claude Code

…driven cache

nova-launch01#1111 – Mount all routes under /api/v1 (canonical) with /api as a
backward-compat alias.  A unified v1Router inlines rate-limiting per
resource group.  Every response from /api/v1 carries an X-API-Version: v1
header so clients can detect which version served them.

nova-launch01#1112 – Expose connection-pool health as Prometheus gauges:
  db_connections_active, db_connections_idle, db_connections_waiting,
  db_pool_saturation.  A new poolMetrics.ts attaches a Prisma $use
middleware that tracks in-flight query concurrency as a proxy for pool
utilisation.  Saturation > 0.8 is alert-worthy.

nova-launch01#1113 – Enforce tenant isolation on token data access.  The tokens router
now requires a resolvable tenant (X-Tenant-ID header or JWT claim) and
always scopes Prisma queries to creator = tenantId.  The explicit ?creator
query param is dropped so tenants cannot bypass the scope.  Cache keys
are also namespaced per tenant.

nova-launch01#1114 – Replace time-only cache expiry in leaderboardService with
event-driven invalidation.  Subscribes to burn.created and token.created
events on the shared eventBus and invalidates only the affected leaderboard
type (e.g. most-burned/most-active/most-burners on burn; newest/largest-supply
on token creation).  The 5-minute TTL remains as a safety-net for any missed
events.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@drips-wave

drips-wave Bot commented May 28, 2026

Copy link
Copy Markdown

@joel-metal Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Emmyt24 Emmyt24 merged commit 25d930c into nova-launch01:main May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants