PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCareers
|Home/Coding & Algorithms/Harvey

Implement a Database Connection Pool

Last updated: May 5, 2026

Quick Overview

This question evaluates skills in concurrent resource management, synchronization primitives, and robust connection lifecycle handling within database connectivity and systems programming.

  • medium
  • Harvey
  • Coding & Algorithms
  • Software Engineer

Implement a Database Connection Pool

Company: Harvey

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Implement a simple database connection pool. You are given a mock database client with a function such as `db.query(connection, sql)` or an equivalent simulated query API. Complete the connection-pool logic so callers can safely acquire and release database connections. Requirements: - The pool has a fixed maximum number of database connections. - `acquire()` returns an available connection if one exists. - If no connection is available but the pool has not reached its maximum size, create a new connection and return it. - If the pool is at capacity and all connections are busy, `acquire()` should wait until a connection is released. - `release(connection)` returns a connection to the pool and wakes one pending waiter, if any. - Prevent invalid releases, double releases, and connection leaks. - The implementation should be safe under concurrent requests. Discuss edge cases such as query failures, timeouts while waiting for a connection, and graceful shutdown of the pool.

Quick Answer: This question evaluates skills in concurrent resource management, synchronization primitives, and robust connection lifecycle handling within database connectivity and systems programming.

Related Interview Questions

  • Evaluate Symbol Expressions - Harvey (medium)
  • Implement a Cursor-Based Text Editor - Harvey (medium)
  • Highlight Exact Source Matches - Harvey (medium)
  • Design Spreadsheet Formula Cells - Harvey (medium)
  • Implement retrieval and evaluation for a simple RAG - Harvey (medium)
Harvey logo
Harvey
Feb 25, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
2
0
Loading...

Implement a simple database connection pool.

You are given a mock database client with a function such as db.query(connection, sql) or an equivalent simulated query API. Complete the connection-pool logic so callers can safely acquire and release database connections.

Requirements:

  • The pool has a fixed maximum number of database connections.
  • acquire() returns an available connection if one exists.
  • If no connection is available but the pool has not reached its maximum size, create a new connection and return it.
  • If the pool is at capacity and all connections are busy, acquire() should wait until a connection is released.
  • release(connection) returns a connection to the pool and wakes one pending waiter, if any.
  • Prevent invalid releases, double releases, and connection leaks.
  • The implementation should be safe under concurrent requests.

Discuss edge cases such as query failures, timeouts while waiting for a connection, and graceful shutdown of the pool.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Harvey•More Software Engineer•Harvey Software Engineer•Harvey Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • Careers
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.