Project 9: Build a Database Connection Pool

A connection pool that manages database connections, lending them out as RAII guards that return connections to the pool on drop.

Quick Reference

Attribute Value
Primary Language Rust
Alternative Languages None
Difficulty Level 4: Expert
Time Estimate 2 weeks
Knowledge Area API Design / Resource Management
Tooling Rust, async runtime (Tokio)
Prerequisites All previous projects, async Rust basics

What You Will Build

A connection pool that manages database connections, lending them out as RAII guards that return connections to the pool on drop.

Why It Matters

This project builds core skills that appear repeatedly in real-world systems and tooling.

Core Challenges

  • Designing the guard type → maps to RAII pattern with custom Drop
  • Ensuring connections return on drop → maps to deref and drop interaction
  • Handling async contexts → maps to async/await with ownership
  • Preventing guard leakage → maps to type system preventing misuse

Key Concepts

  • RAII Guards: “Programming Rust” Chapter 13
  • Connection Pooling: Study r2d2 or deadpool crate source
  • Async Rust: “Asynchronous Programming in Rust” book
  • API Design: “Rust API Guidelines” (official)

Real-World Outcome

Deliver a working demo with observable output that proves the feature is correct.


Implementation Guide

  1. Reproduce the simplest happy-path scenario.
  2. Build the smallest working version of the core feature.
  3. Add input validation and error handling.
  4. Add instrumentation/logging to confirm behavior.
  5. Refactor into clean modules with tests.

Milestones

  • Milestone 1: Minimal working program that runs end-to-end.
  • Milestone 2: Correct outputs for typical inputs.
  • Milestone 3: Robust handling of edge cases.
  • Milestone 4: Clean structure and documented usage.

Validation Checklist

  • Output matches the real-world outcome example
  • Handles invalid inputs safely
  • Provides clear errors and exit codes
  • Repeatable results across runs

References

  • Main guide: RUST_BORROW_CHECKER_LIFETIME_PHILOSOPHY.md
  • “Asynchronous Programming in Rust” by Carl Lerche & others