title: Managing a multi-tenant connection pool with separate schema/DB approach
body: <p>Say that I have a multi-tenant monolithic application, which uses a separate schema (or DB) approach to isolate the tenants' data. A single running instance of the application is used by multiple tenants to access their data. The diagram below sums up the idea:</p>
  
  <p><a href="https://i.stack.imgur.com/ymalt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ymalt.png" alt="enter image description here"></a></p>
  
  <p>So far, so good. Now, I have to scale the application up. To do so, I increase the number of running instances, and the load balancer routes each request to one of the instances. By doing so, each instance keeps a connection pool for each tenant's database, since it can serve requests from any tenant. The result is something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/uyosV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uyosV.png" alt="enter image description here"></a></p>
  
  <p>The problem is that it grows up exponentially as the number of tenants increases -- higher number of tenants demands more running instances, both of them demands a higher number of connections which demands an increasing number of resources just to keep track of the connection pool. It gets worse if I have a microservices application.</p>
  
  <p><strong>My question is</strong>: Is this approach maintainable? What are the possible alternatives and how can one implement them?</p>