Search code examples
cassandrascylla

How to properly connect client application to Scylla or Cassandra?


Let's say I have a cluster of 3 nodes for ScyllaDB in my local network (it can be AWS VPC). I have my Java application running in the same local network.

I am concerned how to properly connect app to DB.

  • Do I need to specify all 3 IP addresses of DB nodes for the app?
  • What if over time one or several nodes die and get resurrected on other IPs? Do I have to manually reconfigure application?
  • How is it done properly in big real production cases with tens of DB servers, possibly in different data centers?

I would be much grateful for a code sample of how to connect Java app to multi-node cluster.


Solution

  • You need to specify contact points (you can use DNS names instead of IPs) - several nodes (usually 2-3), and driver will connect to one of them, and will discover the all nodes of the cluster after connection (see the driver's documentation). After connection is established, driver keeps the separate control connection opened, and via it receives the information about nodes that are going up & down, joining or leaving the cluster, etc., so it's able to keep information about cluster topology up-to-date.

    If you're specifying DNS names instead of the IP addresses, then it's better to specify configuration parameter datastax-java-driver.advanced.resolve-contact-points as true (see docs), so the names will be resolved to IPs on every reconnect, instead of resolving at the start of application.