feat(backend): API versioning, pool metrics, tenant isolation, event-driven leaderboard cache#1195
Merged
Emmyt24 merged 1 commit intoMay 28, 2026
Conversation
…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>
|
@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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/api/v1). All routes mounted on a unifiedv1Routerwith/apikept as a backward-compat alias. Every response includesX-API-Version: v1header.db_connections_active,db_connections_idle,db_connections_waiting,db_pool_saturation). NewpoolMetrics.tsattaches a Prisma middleware to track in-flight query concurrency as a pool-utilisation proxy.tenantMiddleware({ required: true })applied to the tokens router; every Prisma query is scoped tocreator = tenantId. Cache keys namespaced per tenant so slices never bleed across tenants. Requests without a resolvable tenant are rejected with HTTP 400.leaderboardServicesubscribes toburn.createdandtoken.createdevents via the sharedeventBusand invalidates only the affected leaderboard type (scoped, not global). The 5-minute TTL remains as a safety net.Changes
src/index.tsv1Router,/api/v1canonical mount,/apicompat alias,registerPoolMetricscallsrc/lib/metrics/index.tsdb_connections_waiting+db_pool_saturationgauges; updatedMetricsCollector.updateDatabaseConnectionssignaturesrc/lib/metrics/poolMetrics.tssrc/routes/tokens.tstenantMiddleware({ required: true }), tenant-scopedcreatorfilter, tenant-namespaced cache keyssrc/routes/tokens.test.tsX-Tenant-IDheader; assertions includecreatorscopesrc/services/leaderboardService.tsburn.created,token.created),invalidateCacheByType(), TTL retained as fallbackVersioning policy
/api/v1/is the canonical versioned prefix going forward./api/is a permanent backward-compat alias pointing to the same router.X-API-Version: v1header is set on every response fromv1Router./api/v2without removing v1.Pool metric names
db_connections_activedb_connections_idledb_connections_waitingdb_pool_saturationactive / pool_size(alert on > 0.8)Pool size configured via
DB_POOL_SIZEenv var (default: 10).Leaderboard invalidation triggers
burn.createdmost-burned,most-active,most-burnerstoken.creatednewest,largest-supplyPublish these events from the burn/token write handlers:
Closes #1111
Closes #1112
Closes #1113
Closes #1114
🤖 Generated with Claude Code