Untitled

 avatar
unknown
plain_text
14 days ago
2.6 kB
7
Indexable
Problem Statement

Managing thousands of tenants requires dynamic and efficient database connection handling.

Without connection pooling, the system may suffer from resource exhaustion and reduced performance.

Lack of observability into connection pool metrics can hinder proactive monitoring and troubleshooting.

Proposed Solution

Overview of Connection Pooling

Connection pooling allows the reuse of database connections by maintaining a pool of active connections that can be shared across tenants. This reduces the overhead of opening and closing connections repeatedly, leading to improved performance and resource utilization.

Key Components

HikariCP: A high-performance JDBC connection pool.

Micrometer: A metrics collection library integrated with Spring Boot for exposing connection pool metrics.

SDK Integration: The provided SDK will dynamically return a database connection object based on the tenant and environment.
Externalization of Parameters

All configuration parameters, such as connection pool settings, will be externalized to a application.yml or application.properties file to allow environment-specific customization without modifying the code.

Implementation Details

Connection Pooling with HikariCP

HikariCP will be used to manage connections efficiently. The following configurations will be externalized:

Configuration Parameters (Example in application.yml):

spring:
  datasource:
    hikari:
      maximum-pool-size: 20
      minimum-idle: 5
      idle-timeout: 30000 # 30 seconds
      max-lifetime: 1800000 # 30 minutes
      connection-timeout: 30000 # 30 seconds
      pool-name: "TenantConnectionPool"

Tenant-Specific Connections

The SDK will be used to dynamically fetch the database connection for a specific tenant. HikariCP will reuse these connections based on the pool configuration.

Tenant Context and Connection Retrieval:


Metrics to Collect

Connection Pool Metrics

The following metrics will be collected for observability:

Total Connections (hikaricp.connections): Total number of connections in the pool.

Active Connections (hikaricp.connections.active): Number of currently active connections.

Idle Connections (hikaricp.connections.idle): Number of idle connections available.

Connection Wait Time (hikaricp.connection.acquire.time): Time taken to acquire a connection from the pool.

Connection Errors: Count of failed connection attempts.

Per-Tenant Metrics

Custom metrics can be added for monitoring usage per tenant:

Count of connections used per tenant.

Connection failures per tenant.
Leave a Comment