Connection Pooling
Skill Profile
(Select at least one profile to enable specific modules)
Overview
Connection pooling is a technique used to maintain a cache of database connections that can be reused instead of creating a new connection for each request. This significantly improves application performance by reducing overhead of establishing new connections.
Why This Matters
Connection pooling is critical because:
- Performance: 10-100x faster connection acquisition vs creating new connections
- Resource Efficiency: Reduces database server load and connection overhead
- Scalability: Enables handling more concurrent requests with same resources
- Stability: Prevents connection storms and resource exhaustion
- Cost Efficiency: Reduces infrastructure costs by maximizing connection reuse
Core Concepts & Rules
1. Core Principles
- Follow established patterns and conventions
- Maintain consistency across codebase
- Document decisions and trade-offs
2. Implementation Guidelines
- Start with the simplest viable solution
- Iterate based on feedback and requirements
- Test thoroughly before deployment
Inputs / Outputs / Contracts
Inputs:
- Database connection configuration (host, port, credentials)
- Pool configuration (min/max size, timeouts)
- Query or transaction to execute
Outputs:
- Query results
- Connection handle for manual management
- Pool status metrics
Contracts:
- Connections must be released after use
- Pool must handle connection failures gracefully
- Pool must respect configured limits
- Pool must validate connections before use
Skill Composition
- Depends on: None
- Compatible with: None
- Conflicts with: None
- Related Skills: None
Quick Start / Implementation Example
- Review requirements and constraints
- Set up development environment
- Implement core functionality following patterns
- Write tests for critical paths
- Run tests and fix issues
- Document any deviations or decisions
# Example implementation following best practices
def example_function():
# Your implementation here
pass
Assumptions / Constraints / Non-goals
- Assumptions:
- Development environment is properly configured
- Required dependencies are available
- Team has basic understanding of domain
- Constraints:
- Must follow existing codebase conventions
- Time and resource limitations
- Compatibility requirements
- Non-goals:
- This skill does not cover edge cases outside scope
- Not a replacement for formal training
Compatibility & Prerequisites
- Supported Versions:
- Python 3.8+
- Node.js 16+
- Modern browsers (Chrome, Firefox, Safari, Edge)
- Required AI Tools:
- Code editor (VS Code recommended)
- Testing framework appropriate for language
- Version control (Git)
- Dependencies:
- Language-specific package manager
- Build tools
- Testing libraries
- Environment Setup:
.env.example keys: API_KEY, DATABASE_URL (no values)
Test Scenario Matrix (QA Strategy)
| Type |
Focus Area |
Required Scenarios / Mocks |
| Unit |
Core Logic |
Must cover primary logic and at least 3 edge/error cases. Target minimum 80% coverage |
| Integration |
DB / API |
All external API calls or database connections must be mocked during unit tests |
| E2E |
User Journey |
Critical user flows to test |
| Performance |
Latency / Load |
Benchmark requirements |
| Security |
Vuln / Auth |
SAST/DAST or dependency audit |
| Frontend |
UX / A11y |
Accessibility checklist (WCAG), Performance Budget (Lighthouse score) |
Technical Guardrails & Security Threat Model
1. Security & Privacy (Threat Model)
- Top Threats: Injection attacks, authentication bypass, data exposure
2. Performance & Resources
3. Architecture & Scalability
4. Observability & Reliability
Agent Directives & Error Recovery
(ข้อกำหนดสำหรับ AI Agent ในการคิดและแก้ปัญหาเมื่อเกิดข้อผิดพลาด)
- Thinking Process: Analyze root cause before fixing. Do not brute-force.
- Fallback Strategy: Stop after 3 failed test attempts. Output root cause and ask for human intervention/clarification.
- Self-Review: Check against Guardrails & Anti-patterns before finalizing.
- Output Constraints: Output ONLY the modified code block. Do not explain unless asked.
Definition of Done (DoD) Checklist
Anti-patterns / Pitfalls
- ⛔ Don't: Log PII, catch-all exception, N+1 queries
- ⚠️ Watch out for: Common symptoms and quick fixes
- 💡 Instead: Use proper error handling, pagination, and logging
Reference Links & Examples
- Internal documentation and examples
- Official documentation and best practices
- Community resources and discussions
Versioning & Changelog
- Version: 1.0.0
- Changelog:
- 2026-02-22: Initial version with complete template structure
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: connection-pooling3description: Connection pooling is a technique used to maintain a cache of database Use when this capability is needed.4---56# Connection Pooling78## Skill Profile9*(Select at least one profile to enable specific modules)*10- [ ] **DevOps**11- [x] **Backend**12- [ ] **Frontend**13- [ ] **AI-RAG**14- [ ] **Security Critical**1516## Overview17Connection pooling is a technique used to maintain a cache of database connections that can be reused instead of creating a new connection for each request. This significantly improves application performance by reducing overhead of establishing new connections.1819## Why This Matters20Connection pooling is critical because:21- **Performance**: 10-100x faster connection acquisition vs creating new connections22- **Resource Efficiency**: Reduces database server load and connection overhead23- **Scalability**: Enables handling more concurrent requests with same resources24- **Stability**: Prevents connection storms and resource exhaustion25- **Cost Efficiency**: Reduces infrastructure costs by maximizing connection reuse2627## Core Concepts & Rules2829### 1. Core Principles30- Follow established patterns and conventions31- Maintain consistency across codebase32- Document decisions and trade-offs3334### 2. Implementation Guidelines35- Start with the simplest viable solution36- Iterate based on feedback and requirements37- Test thoroughly before deployment383940## Inputs / Outputs / Contracts41**Inputs:**42- Database connection configuration (host, port, credentials)43- Pool configuration (min/max size, timeouts)44- Query or transaction to execute4546**Outputs:**47- Query results48- Connection handle for manual management49- Pool status metrics5051**Contracts:**52- Connections must be released after use53- Pool must handle connection failures gracefully54- Pool must respect configured limits55- Pool must validate connections before use5657## Skill Composition58* **Depends on**: None59* **Compatible with**: None60* **Conflicts with**: None61* **Related Skills**: None6263## Quick Start / Implementation Example64651. Review requirements and constraints662. Set up development environment673. Implement core functionality following patterns684. Write tests for critical paths695. Run tests and fix issues706. Document any deviations or decisions7172```python73# Example implementation following best practices74def example_function():75 # Your implementation here76 pass77```787980## Assumptions / Constraints / Non-goals8182* **Assumptions**:83 - Development environment is properly configured84 - Required dependencies are available85 - Team has basic understanding of domain86* **Constraints**:87 - Must follow existing codebase conventions88 - Time and resource limitations89 - Compatibility requirements90* **Non-goals**:91 - This skill does not cover edge cases outside scope92 - Not a replacement for formal training939495## Compatibility & Prerequisites9697* **Supported Versions**:98 - Python 3.8+99 - Node.js 16+100 - Modern browsers (Chrome, Firefox, Safari, Edge)101* **Required AI Tools**:102 - Code editor (VS Code recommended)103 - Testing framework appropriate for language104 - Version control (Git)105* **Dependencies**:106 - Language-specific package manager107 - Build tools108 - Testing libraries109* **Environment Setup**:110 - `.env.example` keys: `API_KEY`, `DATABASE_URL` (no values)111112113## Test Scenario Matrix (QA Strategy)114115| Type | Focus Area | Required Scenarios / Mocks |116| :--- | :--- | :--- |117| **Unit** | Core Logic | Must cover primary logic and at least 3 edge/error cases. Target minimum 80% coverage |118| **Integration** | DB / API | All external API calls or database connections must be mocked during unit tests |119| **E2E** | User Journey | Critical user flows to test |120| **Performance** | Latency / Load | Benchmark requirements |121| **Security** | Vuln / Auth | SAST/DAST or dependency audit |122| **Frontend** | UX / A11y | Accessibility checklist (WCAG), Performance Budget (Lighthouse score) |123124125## Technical Guardrails & Security Threat Model126127### 1. Security & Privacy (Threat Model)128* **Top Threats**: Injection attacks, authentication bypass, data exposure129- [ ] **Data Handling**: Sanitize all user inputs to prevent Injection attacks. Never log raw PII130- [ ] **Secrets Management**: No hardcoded API keys. Use Env Vars/Secrets Manager131- [ ] **Authorization**: Validate user permissions before state changes132133### 2. Performance & Resources134- [ ] **Execution Efficiency**: Consider time complexity for algorithms135- [ ] **Memory Management**: Use streams/pagination for large data136- [ ] **Resource Cleanup**: Close DB connections/file handlers in finally blocks137138### 3. Architecture & Scalability139- [ ] **Design Pattern**: Follow SOLID principles, use Dependency Injection140- [ ] **Modularity**: Decouple logic from UI/Frameworks141142### 4. Observability & Reliability143- [ ] **Logging Standards**: Structured JSON, include trace IDs `request_id`144- [ ] **Metrics**: Track `error_rate`, `latency`, `queue_depth`145- [ ] **Error Handling**: Standardized error codes, no bare except146- [ ] **Observability Artifacts**:147 - **Log Fields**: timestamp, level, message, request_id148 - **Metrics**: request_count, error_count, response_time149 - **Dashboards/Alerts**: High Error Rate > 5%150151152## Agent Directives & Error Recovery153*(ข้อกำหนดสำหรับ AI Agent ในการคิดและแก้ปัญหาเมื่อเกิดข้อผิดพลาด)*154155- **Thinking Process**: Analyze root cause before fixing. Do not brute-force.156- **Fallback Strategy**: Stop after 3 failed test attempts. Output root cause and ask for human intervention/clarification.157- **Self-Review**: Check against Guardrails & Anti-patterns before finalizing.158- **Output Constraints**: Output ONLY the modified code block. Do not explain unless asked.159160161## Definition of Done (DoD) Checklist162163- [ ] Tests passed + coverage met164- [ ] Lint/Typecheck passed165- [ ] Logging/Metrics/Trace implemented166- [ ] Security checks passed167- [ ] Documentation/Changelog updated168- [ ] Accessibility/Performance requirements met (if frontend)169170171## Anti-patterns / Pitfalls172173* ⛔ **Don't**: Log PII, catch-all exception, N+1 queries174* ⚠️ **Watch out for**: Common symptoms and quick fixes175* 💡 **Instead**: Use proper error handling, pagination, and logging176177178## Reference Links & Examples179180* Internal documentation and examples181* Official documentation and best practices182* Community resources and discussions183184185## Versioning & Changelog186187* **Version**: 1.0.0188* **Changelog**:189 - 2026-02-22: Initial version with complete template structure190191---192> Converted and distributed by [TomeVault](https://tomevault.io/claim/amnadtaowsoam) — claim your Tome and manage your conversions.193<!-- tomevault:4.0:skill_md:2026-04-13 -->