PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/System Design/Airtable

Design a lazy-initialized connection pool

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of concurrent resource management, lazy initialization, connection pooling, thread-safe synchronization primitives, and correct shutdown and exhaustion semantics.

  • medium
  • Airtable
  • System Design
  • Software Engineer

Design a lazy-initialized connection pool

Company: Airtable

Role: Software Engineer

Category: System Design

Difficulty: medium

Interview Round: HR Screen

Implement a lazily initialized connection pool. You are given an immutable base class Connection with methods query() and close(). Implement: ( 1) class ConnectionPool with __init__(maxConnectionNum), getConnection() -> PooledConnection, and close(); ( 2) class PooledConnection with __init__(parent: ConnectionPool, connection: Connection), query(), and close(). Requirements: a) Only create a new Connection instance when getConnection() is actually called. b) Reuse idle connections first; if none are idle and the number of active connections is below maxConnectionNum, create a new one. c) Define and implement the behavior when the pool is exhausted (e.g., block with timeout or raise an error). d) Ensure PooledConnection.close() returns the underlying connection to the pool rather than closing it; ConnectionPool.close() must close all underlying connections and reject further operations. e) Discuss how to make the pool safe for concurrent callers (synchronization primitives, avoiding double-return and leaks). Provide the core data structures and analyze the time/space complexity of getConnection() and close().

Quick Answer: This question evaluates understanding of concurrent resource management, lazy initialization, connection pooling, thread-safe synchronization primitives, and correct shutdown and exhaustion semantics.

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 ConnectionPool - Airtable (medium)
Airtable logo
Airtable
Sep 6, 2025, 12:00 AM
Software Engineer
HR Screen
System Design
17
0

Implement a Lazily Initialized, Thread-Safe Connection Pool

Context

You are given an immutable base class Connection with the following methods:

  • query(...): executes a query on the underlying resource
  • close(): closes the underlying resource

Design and implement a lazily initialized connection pool that hands out PooledConnection wrappers. The pool should create actual Connection instances only when needed, reuse them when possible, and handle exhaustion and shutdown correctly.

Assume you can construct new Connection objects via a provided factory function (e.g., connection_factory()) and that Connection is safe to use by a single thread at a time.

Requirements

Implement two classes with these methods:

  1. class ConnectionPool
    • init (maxConnectionNum, default_timeout=None)
    • getConnection() -> PooledConnection
    • close()
  2. class PooledConnection
    • init (parent: ConnectionPool, connection: Connection)
    • query(...)
    • close()

Functional requirements:

  • a) Lazy creation: Create a new Connection instance only when getConnection() is called and there are no idle connections available.
  • b) Reuse-first: Reuse idle connections before creating new ones. If none are idle and the number of active connections is below maxConnectionNum, create a new connection.
  • c) Exhaustion policy: Define behavior when the pool is exhausted. Acceptable options include blocking with a timeout or raising an error. Use a pool-level default timeout (default_timeout). If default_timeout is None, block indefinitely; otherwise, block up to default_timeout and raise a timeout error.
  • d) Closing semantics:
    • PooledConnection.close() returns the underlying connection to the pool instead of closing it.
    • ConnectionPool.close() must prevent future getConnection() calls, close all idle connections immediately, and eventually close all in-use connections as they are returned. The method may block until all borrowed connections are returned.
  • e) Concurrency safety: Make the pool safe for concurrent callers. Discuss and use appropriate synchronization primitives; prevent double-return of the same connection and resource leaks.

Also provide:

  • Core data structures used inside the pool.
  • Time and space complexity for getConnection() and close().

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.