Skip to content

Implement a multi-tenant client pool with TTL-based eviction and health checks #423

Description

@Kingsman-99

Overview

Extend MultiTenantClient to support a true connection pool: each tenant's client is kept alive up to a TTL, health-checked periodically, and evicted on failure or expiry. This is critical for server-side usage (e.g. a Next.js API route serving many tenants).

Requirements

  • MultiTenantClient({ maxClients: number, ttlMs: number, healthCheckIntervalMs: number })
  • getClient(tenantId: string, config?: StellarSplitClientConfig): StellarSplitClient — returns existing or creates new client
  • LRU eviction when maxClients is reached
  • TTL-based eviction: clients older than ttlMs are evicted on next access
  • Background health check: pings each client's RPC every healthCheckIntervalMs; evicts unhealthy clients
  • pool.stats(): PoolStats returning { size, hits, misses, evictions, healthCheckFailures }
  • Write tests covering LRU eviction, TTL expiry, health check eviction, and pool stats accuracy

Acceptance Criteria

  • LRU eviction working under maxClients limit
  • TTL eviction working correctly
  • Health check evicts unhealthy clients
  • pool.stats() returns accurate metrics
  • npm test passes with zero failures
  • TypeScript compiles with zero errors
  • ESLint passes with zero errors

Definition of Done

All CI checks must pass before the PR is reviewed.

Activity

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions