PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/System Design/Airtable

Design a lazy ConnectionPool

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of concurrent resource management, thread-safety, lazy initialization, connection pooling semantics, and lifecycle handling in a multi-threaded Python environment.

  • medium
  • Airtable
  • System Design
  • Software Engineer

Design a lazy ConnectionPool

Company: Airtable

Role: Software Engineer

Category: System Design

Difficulty: medium

Interview Round: HR Screen

##### Question Design and implement a thread-safe, lazily initialized ConnectionPool: classes ConnectionPool and PooledConnection with __init__, getConnection, close. Only create Connection on getConnection when no idle exists; reuse idle connections; cap active connections at maxConnectionNum.

Quick Answer: This question evaluates understanding of concurrent resource management, thread-safety, lazy initialization, connection pooling semantics, and lifecycle handling in a multi-threaded Python environment.

Related Interview Questions

  • Design a scalable search service with sharding - Airtable (medium)
  • Design an async API with idempotency - Airtable (medium)
  • Design JSON serialization for circular references - Airtable (hard)
  • Design a lazy-initialized connection pool - Airtable (medium)
Airtable logo
Airtable
Aug 4, 2025, 10:55 AM
Software Engineer
HR Screen
System Design
4
0

Thread-Safe, Lazily Initialized Connection Pool

Context

You need to design a thread-safe connection pool in Python that lazily creates connections and reuses them. The pool should cap the number of total connections and block callers when no connections are available. A PooledConnection wrapper should ensure that calling close returns the connection to the pool instead of closing the underlying connection.

Assumptions:

  • Language: Python, multi-threaded environment.
  • A connection factory (callable) can be provided to create new underlying connections. For demonstration, a simple stub Connection is used.

Requirements

Implement the following classes and methods:

  1. ConnectionPool
  • init (maxConnectionNum, connection_factory=None)
  • getConnection(timeout=None)
  • close()
  1. PooledConnection
  • init (pool, raw_connection)
  • close()

Behavioral constraints:

  • Lazy initialization: do not create connections in init .
  • Reuse idle connections when available.
  • Create a new connection on getConnection only if there are no idle connections and the total created is below maxConnectionNum.
  • Cap total connections at maxConnectionNum. When the cap is reached and no idle connections exist, getConnection should block (optionally with timeout) until one is returned.
  • PooledConnection.close returns the connection to the pool (idempotent); it should not close the underlying connection unless the pool is closed.
  • Pool close() closes idle connections immediately, marks the pool as closed, and causes future getConnection calls to fail. Connections returned after close should be closed rather than re-pooled.

Solution

Show

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More System Design•More Airtable•More Software Engineer•Airtable Software Engineer•Airtable System Design•Software Engineer System Design
PracHub

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

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • 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.