Knowledge Base

Setup Routing Policies for Different User Types To Direct them to Different Servers

Problem statement

There is a Causal Cluster Setup with 3 Cores and 1 Read Replica. There are 2 user groups - OLTP users and OLAP users. OLTP user queries should only go to the 2 Followers and not to the Read Replica. OLAP user queries should only go to the Read Replica and not to any of the Followers. The reason being that OLTP users should not be impacted by the long running queries from OLAP users.

How to achieve this in Causal Cluster setup?

To assist with this, Multi-DC setup is required, which was introduced in Neo4j version 3.2. First set up the multi-dc license. More information can be obtained from the Neo4j Operations Manual -

Configure the Causal Cluster(CC) with 3 Cores and 1 Read Replica as described in the Neo4j documentation. Then make the corresponding changes in neo4j.conf file to configure which apps/users should access which instances of the cluster. The below configuration creates a server group with oltp_app and also enables multi-dc license, which is required for server groups.

Core 1, Core 2 and Core 3
causal_clustering.load_balancing.config.server_policies.oltp=groups(oltp_app); halt();

Now, to service only the OLAP users on Read Replica configure the read replica as follows:

causal_clustering.load_balancing.config.server_policies.olap=groups(olap_app); halt();

How to use the Driver from the application?

The application used by OLTP users will have the driver configuration below:

Client Application URL:

Driver driver = GraphDatabase.driver( "bolt+routing://" , AuthTokens.basic( "neo4j", "password"), 15, TimeUnit.SECONDS ).toConfig() );

We specify the server_policy name in the URI - bolt+routing:// When using the above URI the READ ONLY queries will only be routed to the 2 Followers since the Core server_groups are set as oltp_app.

The documentation link for Routing Context in present in the drivers section:

Multi-DC feature is only available in Neo4j version 3.2 and above.