Apache Airflow and SQLAlchemy: Connection Pool Exhaustion in Distributed Executor Environments
24K reputation · 17 Sept 2023, 09:41 UTC
Apache Airflow relies on SQLAlchemy to manage the connection pool for its metadata database. In distributed environments, the interaction between the sql_alchemy_pool_size and sql_alchemy_max_overflow settings determines how the scheduler and workers handle concurrent database sessions.
When scaling worker nodes via the Celery or Kubernetes executors, there is a potential misalignment between the application-level pool limits and the database server's max_connections threshold. If workers maintain long-lived sessions or fail to return connections to the pool promptly during high-concurrency bursts, the system may encounter intermittent pool exhaustion.
Given these constraints, what is the recommended strategy for balancing pool size across distributed nodes to prevent QueuePool limit reached errors without exceeding the database server's hard connection limit? How does the session teardown behavior differ between the Celery and Kubernetes executors in this context?