GoogleCloudPlatform / pgadapter

PostgreSQL wire-protocol proxy for Cloud Spanner
https://cloud.google.com/spanner/docs/postgresql-interface#postgresql-client-support
Apache License 2.0
59 stars 21 forks source link

Method to use for PGAdapter with Java Springboot service in GKE #1323

Closed HendPro12 closed 10 months ago

HendPro12 commented 10 months ago

https://cloud.google.com/spanner/docs/pgadapter-start#java-in-process states that the in-process method is the recommended setup for Java applications. Does this remain true when the Java application is deployed to GKE? Or in that case is "side-car" the optimal approach?

olavloite commented 10 months ago

@HendPro12 That's a good question, thanks for bringing it up. There is something to say for both, so it depends a bit on your situation and plans:

  1. Running PGAdapter in-process will allow your Java application and PGAdapter to share the same JVM. This will reduce the total memory usage a bit, as you only need one instead of two JVMs to run on your pod.
  2. Running PGAdapter as a side-car is a standard setup that can be replicated to any other type of service regardless of the programming language that is used for the application. If you plan on also deploying services that are written in a non-JVM language, then standardizing on a setup with PGAdapter as a side-car will give you a more consistent setup across all your applications.
  3. Running PGAdapter as a side-car also allows you to more easily separate logging and resource usage for PGAdapter from your main application.
  4. There should be no significant difference in the performance of the two. The connection between your application and PGAdapter will be the loopback network interface or a Unix Domain Socket in both cases.

So when running a Java application on GKE, I would lean slightly towards using a side-car pattern, unless you know that all your services will always be in Java, and/or if you are on a very tight budget for resources.

I hope this answers your question. If not, then please feel free to reopen.