'ArangoDB Connection Pool Implementation in Microservices Architecture

For learning purposes, I decided to create a micro services based architecture application, and I want each independent app to have its own DB Connection pool. I am confused however as to how to implement that with ArangoDB.

Let's say I have a UserApp that includes commands like SignUp, Login etc. and I have another called RecommendationApp that includes commands like GetRecommendedProduct, UpdateRecommendedProduct, etc.

Now I want the UserApp and the RecommendationApp each to have a separate DB Pool, so that each command inside that application can quickly access the DB by fetching a connection from the DB Pool, if there are available connections in the DB Pool.

I have thought of the following approach, but I don't think that implements DB pooling as it is still a singleton design pattern.

The UserApp and RecommendationApp will each call createPool() once they are up and running. Then inside each of the Commands classes, they'll call the getInstance() function which to my understanding will only return the arangoDB instance if it isn't used by another app in the same application. Therefore, I don't think that implements DB Pooling. Can anyone help direct me to how I can fix that to implement the functionality I want.

 public class Arango {

    private static ArangoDB.Builder builder; 
    private  ArangoDB arangoDB;
    private static Arango instance;

    public void createPool(int maxConnections){ 
           builder = new ArangoDB.Builder()
                    .host(arangoHost, getPort())
                    .user(arango_user)
                    .password(arango_password)
                    .maxConnections(maxConnections)
                    .serializer(new ArangoJack())
                    .connectionTtl(null)
                    .keepAliveInterval(600); 
          arangoDB = builder.build();
   }  
   public static Arango getInstance() {
         if(instance == null) {
             instance = new Arango();
         }
         return instance;
   }
}

How To use the Arango Class:

public class SignUp {
       public String execute() {
             Arango arango=Arango.getInstance();
       }
}

public class UserApp{
       public static void main(String[] args){
             Arango arango = Arango.getInstance();
             arango.createPool(10);
      }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source