<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alexis MP</title>
    <description>The latest articles on DEV Community by Alexis MP (@alexismp).</description>
    <link>https://dev.to/alexismp</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F286186%2F4809f064-16a5-4867-b4ea-431fda8fe62a.jpeg</url>
      <title>DEV Community: Alexis MP</title>
      <link>https://dev.to/alexismp</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alexismp"/>
    <language>en</language>
    <item>
      <title>AlloyDB Integration for Modern Java Apps — Connectivity and Auth</title>
      <dc:creator>Alexis MP</dc:creator>
      <pubDate>Thu, 12 Nov 2026 06:56:01 +0000</pubDate>
      <link>https://dev.to/googlecloud/alloydb-integration-for-modern-java-apps-connectivity-and-auth-5721</link>
      <guid>https://dev.to/googlecloud/alloydb-integration-for-modern-java-apps-connectivity-and-auth-5721</guid>
      <description>&lt;p&gt;&lt;em&gt;(this is part of a&lt;/em&gt; &lt;a href="https://dev.to/googlecloud/a-modern-java-developers-guide-for-google-cloud-databases-3ckg"&gt;&lt;em&gt;Java tour of Google Cloud Databases series&lt;/em&gt;&lt;/a&gt;&lt;em&gt;)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://cloud.google.com/products/alloydb" rel="noopener noreferrer"&gt;AlloyDB for PostgreSQL&lt;/a&gt; is Google Cloud’s database for enterprise-grade workloads with full PostgreSQL compatibility and a cloud-native architecture. Connecting a Java application to AlloyDB is done through the &lt;strong&gt;AlloyDB Java Connector&lt;/strong&gt; , a crucial component that goes beyond a standard JDBC driver.&lt;/p&gt;

&lt;h3&gt;
  
  
  The AlloyDB Java Connector’s Magic
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;alloydb-jdbc-connector&lt;/code&gt; is a client library that functions as a smart socket factory for the standard PostgreSQL JDBC driver. It abstracts away the establishment of a secure database connection and takes care of :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;mTLS 1.3 Encryption:&lt;/strong&gt; automatic secure TLS 1.3 connection to the AlloyDB instance (no need to manage SSL/TLS certificates here).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IAM-Based Authorization:&lt;/strong&gt; as a better alternative to (static) database passwords, the connector uses IAM for authentication and ADC (&lt;a href="https://docs.cloud.google.com/docs/authentication/provide-credentials-adc" rel="noopener noreferrer"&gt;Application Default Credentials&lt;/a&gt;) to obtain a short-lived access token.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic IP Resolution:&lt;/strong&gt; The connector communicates with the AlloyDB Admin API to fetch the current IP address (a Private IP, a Public IP, or a Private Service Connect) of the database instance, so you do not need to handle it explicitly, no hard-coding or environment variable needed. This makes events like failovers or maintenance easier to manage.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;NOTE on using the Java Connector&lt;/strong&gt; rather than the &lt;strong&gt;Auth Proxy:&lt;/strong&gt; for JVM applications, the Java Connector runs in-process as a JDBC &lt;code&gt;SocketFactory&lt;/code&gt;, eliminating the need to deploy and manage a separate sidecar container. The standalone Auth Proxy is best for non-JVM tools, legacy apps where you cannot modify the JDBC classpath, or environments with strict GraalVM native-image constraints.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzbevcq3we4zflhnm5sds.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzbevcq3we4zflhnm5sds.png" width="800" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  But first, some groundwork
&lt;/h3&gt;

&lt;p&gt;I’ll assume that you already have a project with an existing &lt;strong&gt;AlloyDB Cluster&lt;/strong&gt; and primary Instance running in a specific region. If you don’t have that, check out the &lt;a href="https://cloud.google.com/alloydb/docs/cluster-create" rel="noopener noreferrer"&gt;AlloyDB cluster creation guide&lt;/a&gt; or head directly to the console’s &lt;a href="https://console.cloud.google.com/alloydb/get-started" rel="noopener noreferrer"&gt;getting started section&lt;/a&gt;. You’ll need the admin password, the &lt;code&gt;roles/alloydb.admin&lt;/code&gt; role, some tables in the public schema (use &lt;a href="https://neon.com/postgresql/postgresql-getting-started/postgresql-sample-database" rel="noopener noreferrer"&gt;DVD Rental&lt;/a&gt; if you don’t have anything), and of course be able to reach the AlloyDB instance from your local machine (or from Cloud Shell).&lt;/p&gt;

&lt;p&gt;I also strongly recommend that you install these in your favorite agent tool as you progress through the code and instructions of this series :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the &lt;a href="https://cloud.google.com/products/data-agent-kit" rel="noopener noreferrer"&gt;Data Agent Kit&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;the &lt;a href="https://cloud.google.com/blog/topics/developers-practitioners/introducing-the-google-cloud-developer-plugin-for-ai-coding-agents" rel="noopener noreferrer"&gt;Developer Plugin for AI Coding Agents&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you like learning from codelabs, try: &lt;a href="https://codelabs.developers.google.com/connect-to-alloydb-on-cloudrun" rel="noopener noreferrer"&gt;Connect your application to AlloyDB data and deploy on Cloud Run&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let’s start with creating a Service Account, the identity your Java application will use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud iam service-accounts create java-alloydb-connector \
    --display-name=&lt;span class="s2"&gt;"Java Application DB Connector"&lt;/span&gt;
&lt;span class="c"&gt;# locally you'll need to impersonate this account or use your own IAM user&lt;/span&gt;
&lt;span class="c"&gt;# on Cloud Run/GCE/GKE, attach this SA to the compute service/workload&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Then grant it the required IAM roles: both &lt;code&gt;roles/alloydb.client&lt;/code&gt; (needed to request an ephemeral mTLS certificate and connect to the instance) and &lt;code&gt;roles/serviceusage.serviceUsageConsumer&lt;/code&gt; (required for IAM database authentication):&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud projects add-iam-policy-binding &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;PROJECT_ID&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; \
    --member=&lt;span class="s2"&gt;"serviceAccount:java-alloydb-connector@&amp;lt;PROJECT_ID&amp;gt;.iam.gserviceaccount.com"&lt;/span&gt; \
    --role=&lt;span class="s2"&gt;"roles/alloydb.client"&lt;/span&gt;

gcloud projects add-iam-policy-binding &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;PROJECT_ID&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; \
    --member=&lt;span class="s2"&gt;"serviceAccount:java-alloydb-connector@&amp;lt;PROJECT_ID&amp;gt;.iam.gserviceaccount.com"&lt;/span&gt; \
    --role=&lt;span class="s2"&gt;"roles/serviceusage.serviceUsageConsumer"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now enable IAM authentication on the instance to tell your AlloyDB instance to accept IAM tokens, not just passwords (this takes effect immediately, no instance restart required):&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud alloydb instances update &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;INSTANCE_ID&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; \
    --cluster=&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;CLUSTER_ID&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; \
    --region=&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;REGION&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; \
    --database-flags=alloydb.iam_authentication=on
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Finally, register the IAM principal inside AlloyDB and grant it PostgreSQL table permissions. Notice how the .gserviceaccount.com suffix must be stripped for Service Accounts!&lt;/p&gt;

&lt;p&gt;You can register the IAM user directly with gcloud (this automatically grants the internal alloydbiamuser role):&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud alloydb users create &lt;span class="s2"&gt;"java-alloydb-connector@&amp;lt;PROJECT_ID&amp;gt;.iam"&lt;/span&gt; \
    --cluster=&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;CLUSTER_ID&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; \
    --region=&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;REGION&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; \
    --type=IAM_BASED
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Then log in to your database as an admin (e.g., postgres) and grant schema and table privileges (IAM users must be created via gcloud, Terraform, or the Console because AlloyDB blocks granting the internal alloydbiamuser role directly in SQL):&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- Connect to your target database first&lt;/span&gt;
\&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="n"&gt;my_database&lt;/span&gt;

&lt;span class="c1"&gt;-- Grant permissions (IAM users are created with NO privileges by default)&lt;/span&gt;
&lt;span class="k"&gt;GRANT&lt;/span&gt; &lt;span class="no"&gt;CONNECT&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="k"&gt;DATABASE&lt;/span&gt; &lt;span class="s2"&gt;"my_database"&lt;/span&gt; &lt;span class="k"&gt;TO&lt;/span&gt; &lt;span class="s2"&gt;"java-alloydb-connector@&amp;lt;PROJECT_ID&amp;gt;.iam"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;GRANT&lt;/span&gt; &lt;span class="no"&gt;USAGE&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="k"&gt;SCHEMA&lt;/span&gt; &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="k"&gt;TO&lt;/span&gt; &lt;span class="s2"&gt;"java-alloydb-connector@&amp;lt;PROJECT_ID&amp;gt;.iam"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;GRANT&lt;/span&gt; &lt;span class="k"&gt;SELECT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;INSERT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;UPDATE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;DELETE&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="k"&gt;ALL&lt;/span&gt; &lt;span class="no"&gt;TABLES&lt;/span&gt; &lt;span class="k"&gt;IN&lt;/span&gt; &lt;span class="k"&gt;SCHEMA&lt;/span&gt; &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="k"&gt;TO&lt;/span&gt; &lt;span class="s2"&gt;"java-alloydb-connector@&amp;lt;PROJECT_ID&amp;gt;.iam"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Make sure to use double quotes in SQL as they’re required because of the &lt;code&gt;@&lt;/code&gt; and dots.&lt;/p&gt;
&lt;h3&gt;
  
  
  How-To: Connecting to AlloyDB with a JDBC or Spring Boot app
&lt;/h3&gt;

&lt;p&gt;Configuring HikariCP to work with the AlloyDB Java Connector requires specifying key properties that instruct the standard PostgreSQL driver to delegate socket creation to the connector. This requires Java 11 or higher (but I hope you’re using Java 17, 21 LTS, or higher!).&lt;/p&gt;
&lt;h4&gt;
  
  
  “Plain” JDBC
&lt;/h4&gt;

&lt;p&gt;First, dependencies (&lt;code&gt;pom.xml&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;dependencies&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.postgresql&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;postgresql&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;42.7.14&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;com.google.cloud.alloydb&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;alloydb-jdbc-connector&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;1.4.0&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;com.zaxxer&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;HikariCP&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;7.1.0&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/dependencies&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here’s a complete sample that configures HikariCP with the AlloyDB &lt;code&gt;SocketFactory&lt;/code&gt; and queries the film table from the DVD Rental schema to verify both IAM authentication and table privileges:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Notice that the JDBC URL &lt;code&gt;jdbc:postgresql:///%s&lt;/code&gt; contains no host information. This is a key indicator that the &lt;code&gt;SocketFactory&lt;/code&gt; is in control, as it is responsible for finding and connecting to the correct instance IP address.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For connectivity troubleshooting, check out the bottom of this post and make sure to read the &lt;a href="https://cloud.google.com/alloydb/docs/connection-overview" rel="noopener noreferrer"&gt;AlloyDB Connection Overview&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Using Spring Boot
&lt;/h4&gt;

&lt;p&gt;Spring Boot simplifies database connectivity by automatically configuring a HikariCP connection pool based on your properties, allowing you to integrate the AlloyDB Connector with almost no manual coding.&lt;/p&gt;

&lt;p&gt;You only need to add the AlloyDB Connector to your existing Spring Boot project. Spring Boot’s &lt;code&gt;spring-boot-starter-data-jpa&lt;/code&gt; or &lt;code&gt;spring-boot-starter-jdbc&lt;/code&gt; already includes HikariCP (just ensure &lt;code&gt;org.postgresql:postgresql&lt;/code&gt; is on the classpath):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;com.google.cloud.alloydb&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;alloydb-jdbc-connector&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;1.4.0&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Using &lt;code&gt;application.properties&lt;/code&gt; is the standard way to define your connection string within your project:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight properties"&gt;&lt;code&gt;&lt;span class="c1"&gt;# No host or port is needed; the SocketFactory handles it.
&lt;/span&gt;&lt;span class="na"&gt;spring.datasource.url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;jdbc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;postgresql&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;///my_database?socketFactory=com.google.cloud.alloydb.SocketFactory&amp;amp;alloydbInstanceName=projects/&amp;lt;PROJECT_ID&amp;gt;/locations/&amp;lt;REGION&amp;gt;/clusters/&amp;lt;CLUSTER_ID&amp;gt;/instances/&amp;lt;INSTANCE_ID&amp;gt;&amp;amp;alloydbEnableIAMAuth=true&lt;/span&gt;
&lt;span class="na"&gt;spring.datasource.username&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;alloydb&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;connector&lt;/span&gt;@&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;PROJECT_ID&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;iam&lt;/span&gt;
&lt;span class="c1"&gt;# No password required when alloydbEnableIAMAuth is true
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Tips&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If this long JDBC URL isn’t your thing, you can use the &lt;code&gt;com.google.cloud:spring-cloud-gcp-starter-alloydb&lt;/code&gt; dependency, which lets you configure &lt;code&gt;spring.cloud.gcp.alloydb.database-name&lt;/code&gt;, &lt;code&gt;spring.cloud.gcp.alloydb.instance-connection-uri&lt;/code&gt;, and &lt;code&gt;spring.cloud.gcp.alloydb.iam-auth-enabled=true&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you want to keep your code clean of specific project IDs or instance names, you can leave your &lt;code&gt;application.properties&lt;/code&gt; empty and set these environment variables in your deployment environment:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;SPRING\_DATASOURCE\_URL&lt;/code&gt;&lt;/strong&gt;&lt;code&gt;=jdbc:postgresql:///my\_database?socketFactory=com.google.cloud.alloydb.SocketFactory&amp;amp;alloydbInstanceName=projects/my-project/locations/us-central1/clusters/my-cluster/instances/my-instance&amp;amp;alloydbEnableIAMAuth=true&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;SPRING\_DATASOURCE\_USERNAME&lt;/code&gt;&lt;/strong&gt;&lt;code&gt;=java-alloydb-connector@my-project.iam&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(If your organization still requires static database passwords instead of IAM authentication, do not hard-code them. Instead use&lt;/em&gt; &lt;a href="https://cloud.google.com/security/products/secret-manager" rel="noopener noreferrer"&gt;&lt;em&gt;Google Cloud Secret Manager&lt;/em&gt;&lt;/a&gt; &lt;em&gt;to inject those dynamically using Spring Cloud GCP’s&lt;/em&gt; &lt;em&gt;&lt;code&gt;spring.config.import=sm://&lt;/code&gt; and&lt;/em&gt; &lt;em&gt;&lt;code&gt;spring.datasource.password=${sm://alloydb-password}).&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Passwordless Auth in Action
&lt;/h4&gt;

&lt;p&gt;When Spring Boot starts, it detects the jdbc:postgresql prefix in the URL and initializes the PostgreSQL driver. Because the URL contains the &lt;code&gt;socketFactory&lt;/code&gt; parameter, the driver delegates the actual network connection to the AlloyDB Connector. The connector then uses &lt;strong&gt;Application Default Credentials (ADC)&lt;/strong&gt; to authenticate. This means that if your app is running on Cloud Run with the correct Service Account attached, the connection happens automatically and securely without any passwords in your config files.&lt;/p&gt;

&lt;p&gt;This short app will help you test the connectivity to the database:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Here’s how to run it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;SPRING_DATASOURCE_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"jdbc:postgresql:///my_database?socketFactory=com.google.cloud.alloydb.SocketFactory&amp;amp;alloydbInstanceName=projects/&amp;lt;PROJECT_ID&amp;gt;/locations/&amp;lt;REGION&amp;gt;/clusters/&amp;lt;CLUSTER_ID&amp;gt;/instances/&amp;lt;INSTANCE_ID&amp;gt;&amp;amp;alloydbEnableIAMAuth=true"&lt;/span&gt;
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;SPRING_DATASOURCE_USERNAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"java-alloydb-connector@&amp;lt;PROJECT_ID&amp;gt;.iam"&lt;/span&gt;

mvn spring-boot:run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Using Micronaut or Quarkus?
&lt;/h4&gt;

&lt;p&gt;Whether you choose &lt;strong&gt;Micronaut&lt;/strong&gt; or &lt;strong&gt;Quarkus&lt;/strong&gt; , the underlying principles for connecting to AlloyDB remain the same.&lt;/p&gt;

&lt;p&gt;Because the AlloyDB Java Connector operates at the &lt;strong&gt;JDBC driver level&lt;/strong&gt; , the framework simply acts as a wrapper for the connection pool. You still include the same &lt;code&gt;alloydb-jdbc-connector&lt;/code&gt; dependency, and the “magic” continues to happen through the &lt;code&gt;SocketFactory&lt;/code&gt; and &lt;code&gt;alloydbInstanceName&lt;/code&gt; properties:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quarkus (&lt;/strong&gt;&lt;code&gt;application.properties&lt;/code&gt;** using Quarkus’s Agroal pool):**&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight properties"&gt;&lt;code&gt;&lt;span class="na"&gt;quarkus.datasource.db-kind&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;postgresql&lt;/span&gt;
&lt;span class="na"&gt;quarkus.datasource.username&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;alloydb&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;connector&lt;/span&gt;@&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;PROJECT_ID&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;iam&lt;/span&gt;
&lt;span class="na"&gt;quarkus.datasource.jdbc.url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;jdbc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;postgresql&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;///my_database&lt;/span&gt;
&lt;span class="na"&gt;quarkus.datasource.jdbc.additional-jdbc-properties.socketFactory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cloud&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;alloydb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SocketFactory&lt;/span&gt;
&lt;span class="na"&gt;quarkus.datasource.jdbc.additional-jdbc-properties.alloydbInstanceName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;projects&lt;/span&gt;&lt;span class="o"&gt;/&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;PROJECT_ID&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;/&lt;/span&gt;&lt;span class="n"&gt;locations&lt;/span&gt;&lt;span class="o"&gt;/&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;REGION&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;/&lt;/span&gt;&lt;span class="n"&gt;clusters&lt;/span&gt;&lt;span class="o"&gt;/&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;CLUSTER_ID&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;/&lt;/span&gt;&lt;span class="n"&gt;instances&lt;/span&gt;&lt;span class="o"&gt;/&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;INSTANCE_ID&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="na"&gt;quarkus.datasource.jdbc.additional-jdbc-properties.alloydbEnableIAMAuth&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Micronaut (&lt;/strong&gt;&lt;code&gt;application.yml&lt;/code&gt;** using HikariCP):**&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;datasources&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;jdbc:postgresql:///my_database?socketFactory=com.google.cloud.alloydb.SocketFactory&amp;amp;alloydbInstanceName=projects/&amp;lt;PROJECT_ID&amp;gt;/locations/&amp;lt;REGION&amp;gt;/clusters/&amp;lt;CLUSTER_ID&amp;gt;/instances/&amp;lt;INSTANCE_ID&amp;gt;&amp;amp;alloydbEnableIAMAuth=true&lt;/span&gt;
    &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;java-alloydb-connector@&amp;lt;PROJECT_ID&amp;gt;.iam&lt;/span&gt;
    &lt;span class="na"&gt;driver-class-name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;org.postgresql.Driver&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just as with Spring, these frameworks delegate the mTLS encryption, dynamic IP resolution, and IAM-based authentication to the connector library. Moving between cloud-native frameworks doesn’t change how you secure your database traffic or manage identities: Application Default Credentials (ADC) is used to achieve a passwordless, secure connection to your AlloyDB instance.&lt;/p&gt;

&lt;h4&gt;
  
  
  A note on the AlloyDB Connector in GraalVM Native Mode
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;When compiling your application into a GraalVM Native Image (whether with Spring Boot, Micronaut, or Quarkus), there is one specific challenge: &lt;strong&gt;Reflection and SSL.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The PostgreSQL JDBC driver instantiates &lt;code&gt;com.google.cloud.alloydb.SocketFactory&lt;/code&gt; dynamically via reflection. To prevent GraalVM’s static analysis from stripping the class during native compilation, register it for reflection:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Spring Boot 3+:&lt;/strong&gt; Add &lt;code&gt;@RegisterReflectionForBinding(com.google.cloud.alloydb.SocketFactory.class)&lt;/code&gt; to your main application or &lt;code&gt;@Configuration&lt;/code&gt; class.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quarkus:&lt;/strong&gt; Add &lt;code&gt;@RegisterForReflection(targets = com.google.cloud.alloydb.SocketFactory.class)&lt;/code&gt; to a CDI bean or configuration class.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Troubleshooting
&lt;/h3&gt;

&lt;p&gt;A common point of confusion and failure is the format of the username. The format differs for user accounts, groups, and service accounts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;IAM User Account (or IAM Group):&lt;/strong&gt; Use the full email address (e.g., &lt;code&gt;db-user@example.com&lt;/code&gt; or &lt;code&gt;all-devs-group@example.com&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Service Account:&lt;/strong&gt; Use the email address, but strip the &lt;code&gt;.gserviceaccount.com suffix&lt;/code&gt; (e.g., for &lt;code&gt;my-sa@my-project.iam.gserviceaccount.com&lt;/code&gt;, the database username is &lt;code&gt;my-sa@my-project.iam&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you get a &lt;code&gt;FATAL: password authentication failed for user or AlloyDB IAM authentication failed&lt;/code&gt; error, check these common pitfalls:&lt;/p&gt;

&lt;h4&gt;
  
  
  The Suffix:
&lt;/h4&gt;

&lt;p&gt;Did you accidentally include &lt;code&gt;.gserviceaccount.com&lt;/code&gt; in the database username or &lt;code&gt;CREATE USER&lt;/code&gt; command? (remove it).&lt;/p&gt;

&lt;h4&gt;
  
  
  The alloydbiamuser Role:
&lt;/h4&gt;

&lt;p&gt;Did you create the user via &lt;code&gt;gcloud alloydb users create — type=IAM\_BASED&lt;/code&gt; (or Console/Terraform)? Creating a user with raw SQL &lt;code&gt;CREATE USER&lt;/code&gt; will not work for IAM authentication because AlloyDB restricts &lt;code&gt;GRANT alloydbiamuser&lt;/code&gt; to the control plane.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Environment &amp;amp; Local Impersonation:
&lt;/h4&gt;

&lt;p&gt;Is the environment where the Java code is running actually authenticated as the target principal&lt;br&gt;&lt;br&gt;
=&amp;gt; &lt;strong&gt;Cloud Run:&lt;/strong&gt; Ensure the Service Account is attached to the Cloud Run service definition and has both &lt;code&gt;roles/alloydb.client&lt;/code&gt; and &lt;code&gt;roles/serviceusage.serviceUsageConsumer&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
=&amp;gt; &lt;strong&gt;Locally (connecting as a Service Account):&lt;/strong&gt; Impersonate the Service Account so ADC mints tokens for that SA instead of your personal email:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud auth application-default login \
    --impersonate-service-account=java-alloydb-connector@&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;PROJECT_ID&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;.iam.gserviceaccount.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  The Delay:
&lt;/h4&gt;

&lt;p&gt;IAM policy changes can take 60–120 seconds to propagate. If you just created the Service Account or role binding, wait a minute and retry.&lt;/p&gt;




</description>
      <category>googlecloudplatform</category>
      <category>java</category>
      <category>alloydb</category>
    </item>
    <item>
      <title>A Modern Java Developer’s Guide for Google Cloud Databases</title>
      <dc:creator>Alexis MP</dc:creator>
      <pubDate>Mon, 09 Nov 2026 11:16:05 +0000</pubDate>
      <link>https://dev.to/googlecloud/a-modern-java-developers-guide-for-google-cloud-databases-3ckg</link>
      <guid>https://dev.to/googlecloud/a-modern-java-developers-guide-for-google-cloud-databases-3ckg</guid>
      <description>&lt;p&gt;In this Series so far: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A Modern Java Developer’s Guide for Google Cloud Databases (this piece)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/googlecloud/alloydb-integration-for-modern-java-apps-connectivity-and-auth-5721"&gt;AlloyDB Integration for Modern Java Apps — Connectivity and Auth&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Streamlining AlloyDB Development with Spring Boot, Quarkus, Micronaut, AlloyDB Express, and AlloyDB Omni (coming soon)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As a Java developer I’ve learned to rely on JDBC, on the efficiency of connection pools, and on my favorite ORM or frameworks (Spring, Quarkus, or Micronaut). These are stable, predictable technologies that I can count on for building enterprise apps.&lt;/p&gt;

&lt;p&gt;This short intro and upcoming detailed posts are meant to serve as a guide for &lt;strong&gt;Java developers in their Google Cloud Database journey&lt;/strong&gt; , including when moving from conventional on-premises databases to a cloud-native approach. We’ll cover configuration, security, performance, monitoring, and overall developer experience.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1heaog2i9umgt9hqtodk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1heaog2i9umgt9hqtodk.png" width="800" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;No need to abandon your stack to use Google Cloud databases: all of them plug right into standard JDBC, HikariCP, and your favorite frameworks. Whether you’re relying on the AlloyDB Java Connector for automated mTLS or designing schemas for globally distributed Spanner, this series will help you pick and configure the right tool for your workload.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AlloyDB&lt;/strong&gt; gives you full PostgreSQL wire compatibility backed by a Google-engineered storage layer and a 99.99% SLA (including maintenance) for demanding transactional and AI workloads. Java developers typically use the AlloyDB Java Connector with standard JDBC and HikariCP.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cloud SQL&lt;/strong&gt; removes operational toil when running MySQL, PostgreSQL, and SQL Server databases with read pools, data caching, and near-zero downtime maintenance. Connecting from Java is done using the Cloud SQL Java Connector or using Auth Proxy alongside standard JDBC and Spring Boot.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Spanner&lt;/strong&gt; is a globally distributed database that pairs horizontal scalability, strong consistency, and a 99.999% SLA with multi-model support: relational, graph, vector, and key-value. You can wire it into Java applications using either the Spanner JDBC Driver, the native Java Client Library, Spring Data Spanner, or PGAdapter with JPA.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Firestore&lt;/strong&gt; is a serverless NoSQL document database offering a Native and a MongoDB-compatible mode. It was designed for schema flexibility, real-time sync, automatic scaling, and up to a 5 nine SLA. Java devs will typically use the Firestore Java Client Library, Spring Cloud GCP, or even the standard MongoDB Java Driver.&lt;/p&gt;

&lt;p&gt;Here’s a &lt;a href="https://gist.github.com/alexismp/2976cf53d946a6bc2175957d4a430de2" rel="noopener noreferrer"&gt;tabular presentation&lt;/a&gt; summarizing all of this knowledge for Java developers and architects.&lt;/p&gt;

&lt;p&gt;Upcoming Java-focused blogs here will cover :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;AlloyDB for PostgreSQL&lt;/strong&gt; (including &lt;a href="https://cloud.google.com/alloydb/omni" rel="noopener noreferrer"&gt;AlloyDB Omni&lt;/a&gt; for local and edge use-cases, and &lt;a href="https://cloud.google.com/blog/products/databases/introducing-alloydb-express-for-rapid-testing-and-prototyping" rel="noopener noreferrer"&gt;AlloyDB Express&lt;/a&gt; for rapid testing and prototyping)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cloud SQL&lt;/strong&gt; (focusing on &lt;strong&gt;MySQL&lt;/strong&gt; though the same connector patterns apply to PostgreSQL and SQL Server)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Spanner&lt;/strong&gt; and &lt;strong&gt;Firestore&lt;/strong&gt; (focusing on their native Google Cloud APIs).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fab86q050nzkaupw9suu9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fab86q050nzkaupw9suu9.png" width="800" height="411"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We’ll use &lt;strong&gt;Spring Boot&lt;/strong&gt; as the primary framework but also show how these building blocks apply to &lt;strong&gt;Quarkus and Micronaut&lt;/strong&gt; developers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AlloyDB AI&lt;/strong&gt; and the &lt;strong&gt;MCP Toolbox for Databases&lt;/strong&gt; (featuring the newly released &lt;a href="https://github.com/googleapis/mcp-toolbox-sdk-java" rel="noopener noreferrer"&gt;&lt;strong&gt;MCP Toolbox Java SDK v1.0&lt;/strong&gt;&lt;/a&gt;) are also on the menu, all from a Java developer’s perspective. Onwards!&lt;/p&gt;




</description>
      <category>java</category>
      <category>database</category>
      <category>googlecloud</category>
    </item>
    <item>
      <title>From Python to Rust, Go, to… Java? Steering Your AI Coding Agent Through Architecture Trade-Offs</title>
      <dc:creator>Alexis MP</dc:creator>
      <pubDate>Mon, 26 Oct 2026 12:40:13 +0000</pubDate>
      <link>https://dev.to/googlecloud/from-python-to-rust-go-to-java-steering-your-ai-coding-agent-through-architecture-trade-offs-3mlj</link>
      <guid>https://dev.to/googlecloud/from-python-to-rust-go-to-java-steering-your-ai-coding-agent-through-architecture-trade-offs-3mlj</guid>
      <description>&lt;p&gt;When you pair-program with an autonomous AI coding agent, something magical happens: you go from an idea to a deployed, production-grade cloud application in an afternoon. But something else happens, too. If you don’t actively steer your agent’s architectural compass, it will happily ride the defaults of its training data or jump onto the latest Hacker News hype train.&lt;/p&gt;

&lt;p&gt;Here is the story of building &lt;strong&gt;Akkord&lt;/strong&gt; , an AI-powered sheet music harmonizer and guitar arranger running on Google Cloud, and what happened when I challenged my coding agent to rethink the stack across &lt;strong&gt;Python&lt;/strong&gt; , &lt;strong&gt;Rust&lt;/strong&gt; , &lt;strong&gt;Go&lt;/strong&gt; , and &lt;strong&gt;Modern Java (JDK 21/25)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffwj0po2dmtqbl9445fkd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffwj0po2dmtqbl9445fkd.png" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Akkord: Computer Vision Meets Musical Counterpoint
&lt;/h3&gt;

&lt;p&gt;Musicians, especially guitarists, frequently run into two problems with PDF sheet music:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Bare scores with no chords:&lt;/strong&gt; You have a classical or folk melody on a 5-line staff, and you want playable guitar chords and a tasteful bass line added directly above the staves.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scores with questionable chords:&lt;/strong&gt; You download a lead sheet where every measure just pounds the root note in the bass (Am -&amp;gt; Dm -&amp;gt; E -&amp;gt; Am), doubling the melody note in parallel octaves and ignoring harmonic counterpoint.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Akkord&lt;/strong&gt; automates both workflows end-to-end:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Pixel-Level Staff &amp;amp; TAB Geometry Detection:&lt;/strong&gt; It rasterizes each PDF page and scans horizontal ink-density slices (accounting for tilted scans and stripping outer eighth/sixteenth-note beams) to distinguish &lt;strong&gt;5-line musical staves&lt;/strong&gt; from &lt;strong&gt;6-line guitar TABs&lt;/strong&gt; , computing exact bounding boxes (S1..Sn) in PDF points.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Visual Rulers for Multimodal AI Grounding:&lt;/strong&gt; Instead of asking an LLM to guess (x, y) coordinates blindly, Akkord generates a &lt;strong&gt;Guide Image&lt;/strong&gt; for every page with red vertical X-coordinate rulers (40pt..560pt) and color-coded translucent bands over each detected staff system, plus extracted vector text tokens (re-joining spaced chord tokens like G m into Gm).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multimodal Harmonic &amp;amp; Counterpoint Analysis:&lt;/strong&gt; It sends the clean score, the coordinate guide image, and the extracted tokens to &lt;strong&gt;Gemini (&lt;code&gt;gemini-4-argon&lt;/code&gt; / &lt;code&gt;gemini-3.8-flash&lt;/code&gt;)&lt;/strong&gt; with strict musical rules:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Avoid systematic root-position monotony and melody doubling: propose slash chords (&lt;/em&gt;&lt;em&gt;Am/G, Dm/F, E7/G#) using contrary motion and walking-bass lines.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Never confuse a 3-sharp guitar score in A Major with F# Minor just because the guitar reads an octave higher and uses low ledger lines (&lt;/em&gt;&lt;em&gt;E2, F#2, G#2)!&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Collision-Free Vector PDF Overlay:&lt;/strong&gt; Using a &lt;strong&gt;2pt ink-density grid&lt;/strong&gt; and a &lt;strong&gt;spiral low-ink search&lt;/strong&gt; , Akkord places vector chord pills, uniform-sized chord corrections with superscript footnote numbers (G → G7/B ¹), 6-string fretboard diagrams, and an appended harmonic report page, without drawing over a notehead, lyric, or tie.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cloud-Native Batch Pipeline:&lt;/strong&gt; Users sign in with Google OAuth 2.0, pick a Google Drive folder (or drop PDFs), and process batches asynchronously via &lt;strong&gt;Cloud Run&lt;/strong&gt; , &lt;strong&gt;Cloud Tasks&lt;/strong&gt; , &lt;strong&gt;Cloud Firestore&lt;/strong&gt; , and &lt;strong&gt;Cloud Storage&lt;/strong&gt; , complete with a 25-PDF/day quota, automatic next-day deferral, and an 18:00 daily usage &amp;amp; token-cost digest email.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpb981n4xo8766mq2jwzv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpb981n4xo8766mq2jwzv.png" width="800" height="605"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How the Agent Harness Led Me to 100% Python
&lt;/h3&gt;

&lt;p&gt;When I started building Akkord inside my AI agent harness with no particular language or framework SKILLS installed, I didn’t specify a programming language. I focused entirely on the domain: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Read music sheets from Google Drive, analyze the harmony with Gemini, and write chords onto the PDF.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The agent reached for &lt;strong&gt;Python 3.12&lt;/strong&gt; :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Web &amp;amp; APIs:&lt;/strong&gt; FastAPI + Uvicorn&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PDF &amp;amp; Image Processing:&lt;/strong&gt; PyMuPDF (fitz) + Pillow + ReportLab&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AI &amp;amp; Cloud:&lt;/strong&gt; google-genai SDK + direct REST calls to Firestore, Cloud Storage, Cloud Tasks, and Drive API v3&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Why the Agent Chose Python (And Why It Works Just Fine!)
&lt;/h3&gt;

&lt;p&gt;AI coding agents love Python for rapid iterative prototyping. When I asked the agent to tweak the staff-line clustering algorithm so outer beams wouldn’t look like a 6th staff line, or to adjust the spiral ink-avoidance penalty inside pdf_annotator.py, the edit-test loop just took two seconds.&lt;/p&gt;

&lt;p&gt;And honestly? &lt;strong&gt;The Python version on Cloud Run works great and I was able to deliver the entire app in less than than 24h.&lt;/strong&gt; Because the main latency in Akkord is the multimodal Gemini call (typically &lt;strong&gt;4 to 12 seconds&lt;/strong&gt; per score), Python’s ~350 ms of local PDF pixel scanning and vector drawing barely matters on a single file.&lt;/p&gt;

&lt;p&gt;Still, as a developer, you look at nested Python &lt;code&gt;for&lt;/code&gt; loops iterating over millions of grayscale pixels in &lt;code&gt;pdf\_layout.py&lt;/code&gt; and &lt;code&gt;pdf\_annotator.py&lt;/code&gt;, plus a ~320 MB container memory footprint, and you start thinking: &lt;em&gt;Surely, I can do better!&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  “Rewrite It for Speed!” — The Trendy 100% Rust Reflex
&lt;/h3&gt;

&lt;p&gt;Curious, I gave the agent a classic developer prompt:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;If I were to rewrite everything in another more efficient language with faster execution, what should it be?&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you ask an LLM in 2026 for “maximum efficiency and faster execution,” its first instinct is almost always &lt;strong&gt;Rust&lt;/strong&gt; (Axum + Tokio + image + pdf-writer).&lt;/p&gt;

&lt;p&gt;To be fair, Rust makes the pixel-scanning loops in &lt;code&gt;pdf\_layout.py&lt;/code&gt; and the spiral ink-collision search in &lt;code&gt;pdf\_annotator.py&lt;/code&gt; &lt;strong&gt;15x to 25x faster&lt;/strong&gt; , compiling them down to SIMD-vectorized machine code with zero garbage collection pauses and a tiny ~25 MB RAM footprint.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The catch?&lt;/strong&gt; Writing OAuth 2.0 session management, multipart Google Drive uploads, dynamically nested Cloud Firestore REST JSON envelopes, and HTML email builders in pure Rust means fighting borrow-checker lifetimes on deeply nested JSON trees, all for code that spends 99.9% of its life waiting on network I/O.&lt;/p&gt;

&lt;h3&gt;
  
  
  Splitting the Brain — The Go + Rust Polyglot Architecture
&lt;/h3&gt;

&lt;p&gt;So I refined my prompt:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Consider writing different parts in different languages if it makes sense.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Immediately, the agent pivoted from a monolithic rewrite to a &lt;strong&gt;Polyglot Architecture&lt;/strong&gt; that splits the system along its true hardware boundary:&lt;br&gt;&lt;br&gt;
&lt;strong&gt;I/O-bound Cloud Orchestration&lt;/strong&gt; vs. &lt;strong&gt;CPU-bound Pixel &amp;amp; Vector Geometry&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Part 1: Go (cmd/akkord, internal/…) for the Cloud Server &amp;amp; Orchestrator
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Using 100% Go standard library (net/http, compress/zlib, crypto/hmac, archive/zip), Go handles Cloud Run cold starts in &lt;strong&gt;&amp;lt;80 ms&lt;/strong&gt; , manages goroutine worker pools and SSE streaming effortlessly, and speaks REST JSON to Gemini API, Firestore, GCS, and Google Drive with clean, readable structs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Part 2: Rust (akkord-pdf-engine) for the Native PDF Vision &amp;amp; Vector Engine
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Invoked by Go via a zero-overhead JSON stdin/stdout bridge, the native Rust binary uses rayon data parallelism, image, imageproc, ab_glyph, and lopdf to rasterize pages, detect 5-line staves vs. 6-line TABs, compute the 2pt ink grid, and inject raw PDF content streams (BT/ET, Bézier curves c, vector rectangles re) in an estimated &lt;strong&gt;~25–40 ms per page!&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fomlqk4c7m9lzl57xzobr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fomlqk4c7m9lzl57xzobr.png" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Nudging the Agent Toward Modern Java (JDK 21/25 LTS)
&lt;/h3&gt;

&lt;p&gt;The Go + Rust polyglot architecture is awesome, if your team is happy maintaining both a &lt;code&gt;Cargo.toml&lt;/code&gt; and a &lt;code&gt;go.mod&lt;/code&gt; in the same Dockerfile.&lt;/p&gt;

&lt;p&gt;But what if you work in an organization where the platform, security, observability, and engineering teams are standardized on the &lt;strong&gt;JVM&lt;/strong&gt;?&lt;br&gt;&lt;br&gt;
Many LLMs still carry an outdated mental model of Java from the Java 8 era (remember heavyweight application servers, thread-per-request exhaustion, slow startup?).&lt;/p&gt;

&lt;p&gt;When you nudge the agent to evaluate &lt;strong&gt;Modern Java (Java 21 / Java 25 LTS)&lt;/strong&gt; for the exact same workload, the technical picture changes dramatically:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Project Loom (Virtual Threads — JEP 444):&lt;/strong&gt; Just like Go’s goroutines, Java’s Virtual Threads (&lt;code&gt;Executors.newVirtualThreadPerTaskExecutor()&lt;/code&gt;) allow Akkord to fan out dozens of concurrent Google Drive downloads, Gemini API requests, and Firestore writes with simple, readable blocking code and near-zero OS thread overhead.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JIT Vectorization &amp;amp; the Vector API&lt;/strong&gt; (&lt;code&gt;jdk.incubator.vector&lt;/code&gt;) for PDF Pixel Math: Python was slow on &lt;code&gt;pdf\_layout.py&lt;/code&gt; and &lt;code&gt;pdf\_annotator.py&lt;/code&gt; because Python boxes every integer and interprets loops bytecode-by-bytecode. In modern Java, primitive &lt;code&gt;byte[]&lt;/code&gt; and &lt;code&gt;int[]&lt;/code&gt; arrays on the HotSpot C2 compiler (or GraalVM JIT) are automatically unrolled and compiled into*&lt;em&gt;AVX-512 / ARM Neon SIMD instructions *&lt;/em&gt;. Scanning a 1240×1754 page for 5-line staves or running the 2pt spiral ink-collision search in pure Java takes** ~25–45 ms**, within striking distance of Rust, &lt;em&gt;without needing a second language or FFI boundary!&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mature, Pure-Java PDF &amp;amp; Graphics Ecosystem:&lt;/strong&gt; Instead of shelling out to C binaries or stitching together separate crates for font metrics and PDF dictionaries, Java has PDFBox 3.x and hardware-accelerated Java2D (&lt;code&gt;BufferedImage&lt;/code&gt;, &lt;code&gt;Graphics2D&lt;/code&gt;, TrueType glyph layout) built right in.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;First-Class Google Cloud &amp;amp; Enterprise Ecosystem:&lt;/strong&gt; Google’s official Java SDKs for &lt;strong&gt;Gemini&lt;/strong&gt; , &lt;strong&gt;Firestore&lt;/strong&gt; , &lt;strong&gt;Cloud Storage&lt;/strong&gt; , &lt;strong&gt;Cloud Tasks&lt;/strong&gt; , and &lt;strong&gt;Google Drive&lt;/strong&gt; are tier-1 citizens with built-in gRPC connection pooling, automatic retries, and OpenTelemetry tracing. Additionally, framework libraries like &lt;code&gt;LangChain4j&lt;/code&gt; provide clean, idiomatic wrappers around Gemini API calls, streamlining prompt orchestration and structured AI outputs in Java.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fixing Cold Starts with GraalVM Native Image:&lt;/strong&gt; Compile the Java service with &lt;strong&gt;GraalVM Native Image&lt;/strong&gt; (via Quarkus, Micronaut, or Spring Boot 3.4+) and you get a &lt;strong&gt;~50–90 ms Cloud Run cold start&lt;/strong&gt; and a &lt;strong&gt;~60 MB RAM footprint&lt;/strong&gt; , matching Go while keeping 100% of your codebase in a single, type-safe language.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fn8t9ij5ifc9wqlgesyx5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fn8t9ij5ifc9wqlgesyx5.png" width="800" height="437"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The Complete Architecture Showdown&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion: Steer Your Agent, Don’t Let Defaults Steer You
&lt;/h3&gt;

&lt;p&gt;Here are three lessons about working with modern AI coding assistants:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Agents default to frictionless velocity first.&lt;/strong&gt; Left unprompted, an agent will pick Python + FastAPI because it minimizes token count and maximizes first-draft success. And for 80% of cloud apps, including our working Python release of Akkord, that’s a fantastic starting point!&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Vague optimization prompts trigger trendy answers.&lt;/strong&gt; Ask an agent &lt;em&gt;“what is the fastest language?”&lt;/em&gt; in the abstract, and it will hand you a 100% Rust rewrite, even if 90% of your time in the app is waiting on an LLM API and Google Drive.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Specific architectural nudges unlock the best engineering insights.&lt;/strong&gt; When you ask your agent to &lt;em&gt;consider polyglot boundaries&lt;/em&gt; (leading to &lt;strong&gt;Go + Rust&lt;/strong&gt; ) or to &lt;em&gt;evaluate modern capabilities of an established enterprise platform&lt;/em&gt; (leading to &lt;strong&gt;Modern Java with Virtual Threads, SIMD vectorization, and GraalVM&lt;/strong&gt; ), the agent stops repeating clichés and starts doing real systems engineering.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Even if you standardize your backend services on Modern Java, keeping a standalone developer or admin &lt;strong&gt;CLI in Go remains a highly practical choice&lt;/strong&gt;. Go’s instant startup time, cross-compilation to single, self-contained static binaries with zero JVM dependency, and lightweight memory footprint make it exceptionally well-suited for fast command-line tooling.&lt;/p&gt;

&lt;p&gt;Your AI agent knows how to write Python, Rust, Go, and modern Java fluently. The secret is remembering that &lt;strong&gt;you are still the Architect&lt;/strong&gt;. Don’t hesitate to challenge your tools, ask &lt;em&gt;“what about language X?”&lt;/em&gt;, and steer them toward the stack that fits your team, your runtime, and your company best!&lt;/p&gt;




</description>
      <category>agents</category>
      <category>ai</category>
      <category>architecture</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>Your private PDF merge service</title>
      <dc:creator>Alexis MP</dc:creator>
      <pubDate>Fri, 10 Apr 2020 10:51:06 +0000</pubDate>
      <link>https://dev.to/googlecloud/your-private-pdf-merge-service-4b40</link>
      <guid>https://dev.to/googlecloud/your-private-pdf-merge-service-4b40</guid>
      <description>&lt;p&gt;Have you ever had to create a multi-page PDF document from individual files?&lt;/p&gt;

&lt;p&gt;This post walks you through packaging an efficient Linux command merging PDF files, into a web app and hosting it on Cloud Run. You can then make this privacy-preserving service available to your friends and family or even within your enterprise via a simple browser. Full code is in &lt;a href="https://github.com/alexismp/pdf-merger" rel="noopener noreferrer"&gt;this GitHub repo&lt;/a&gt; and live service is &lt;a href="https://pdf-merger-unite-nmv4siw5tq-ew.a.run.app/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6pf8ir13ogxiclp7mlny.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6pf8ir13ogxiclp7mlny.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  The magic Linux command to merge PDF files
&lt;/h1&gt;

&lt;p&gt;There’s a pretty &lt;a href="https://stackoverflow.com/questions/2507766/merge-convert-multiple-pdf-files-into-one-pdf" rel="noopener noreferrer"&gt;good discussion on StackOverflow&lt;/a&gt; comparing different approaches and results (speed, document size, etc…). I ended up using &lt;a href="https://manpages.debian.org/jessie/poppler-utils/pdfunite.1" rel="noopener noreferrer"&gt;&lt;em&gt;pdfunite&lt;/em&gt;&lt;/a&gt; but feel free to use something else. The change would probably be a single liner.&lt;/p&gt;
&lt;h1&gt;
  
  
  Creating a (web) app from a CLI tool
&lt;/h1&gt;

&lt;p&gt;The first step to making this available as a web app is to be able to invoke the command-line tool from your language of choice, in my case Java. I &lt;a href="https://github.com/alexismp/pdf-merger/blob/master/src/main/java/org/alexismp/pdfmerger/LocalStorageService.java#L132" rel="noopener noreferrer"&gt;used &lt;code&gt;ProcessBuilder&lt;/code&gt;&lt;/a&gt;, starting it with &lt;code&gt;inheritIO()&lt;/code&gt; and &lt;code&gt;Process.waitFor()&lt;/code&gt; completion.&lt;/p&gt;

&lt;p&gt;This obviously requires that &lt;code&gt;pdfunite&lt;/code&gt; is installed on the underlying OS, but more on that as we package the app in a container.&lt;/p&gt;

&lt;p&gt;Popular Java web frameworks include Spring Boot, Micronaut, Spark, etc. or even raw HTTP Servlets. I went for SpringBoot and used a &lt;a href="https://github.com/alexismp/pdf-merger/blob/master/src/main/java/org/alexismp/pdfmerger/PDFMergerController.java" rel="noopener noreferrer"&gt;single controller&lt;/a&gt; to manage the &lt;code&gt;MultipartFile&lt;/code&gt; upload and delegated all PDF file storage and manipulation to a &lt;a href="https://github.com/alexismp/pdf-merger/blob/master/src/main/java/org/alexismp/pdfmerger/LocalStorageService.java" rel="noopener noreferrer"&gt;dedicated service&lt;/a&gt; which takes care of removing from the filesystem every file it uses or generates.&lt;/p&gt;

&lt;p&gt;The front-end is dead simple; it supports four file uploads and preserves the order of files being merged (the limit of four was chosen arbitrarily; the back-end imposes no such limit). There’s huge room for improvement as discussed in this &lt;a href="https://github.com/alexismp/pdf-merger/blob/master/README.md" rel="noopener noreferrer"&gt;README&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Note here that you really don’t have to use Java or even SpringBoot - since we’ll be packaging this as a container in the next step we really could have used any combination of language and framework here.&lt;/p&gt;
&lt;h1&gt;
  
  
  Packaging this in a Container (without a Dockerfile)
&lt;/h1&gt;

&lt;p&gt;The one nice thing about Java is its vibrant ecosystem and in my case this means using &lt;a href="https://github.com/GoogleContainerTools/jib" rel="noopener noreferrer"&gt;Jib&lt;/a&gt;, an open source tool to build and push an optimized container image without having to write a Dockerfile or even install docker. In my case I used the Maven plugin and executed &lt;code&gt;mvn compile jib:build&lt;/code&gt; (gradle is also supported). This Dockerfile-less approach to building containers is available for many programming languages through &lt;a href="https://github.com/GoogleCloudPlatform/buildpacks" rel="noopener noreferrer"&gt;Buildpacks&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdc11mov4r37e953uipfv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdc11mov4r37e953uipfv.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The key thing here though is to make sure the containerized app will indeed be able to make the call to the &lt;code&gt;pdfunite&lt;/code&gt; binary. There is no way with Jib to add linux packages so I &lt;a href="https://github.com/alexismp/pdf-merger/blob/master/pom.xml#L63" rel="noopener noreferrer"&gt;replaced the default Jib base image&lt;/a&gt; in my &lt;code&gt;pom.xml&lt;/code&gt; with a simple image based on &lt;code&gt;openjdk:11-jre-slim&lt;/code&gt; and added the &lt;code&gt;pdfunite&lt;/code&gt; binary (&lt;code&gt;apt-get install poppler-utils&lt;/code&gt;). You actually do not need to build this image and can instead use the one I made available.&lt;/p&gt;

&lt;p&gt;Once your app is packaged into a container, the image is pushed (as part of Jib’s build process) to the Google Cloud Registry for easier and faster deployments with this tag: &lt;code&gt;gcr.io/PROJECT-ID/pdfmerger&lt;/code&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Meet Cloud Run
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frta7snk5aeecftr9fdhg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frta7snk5aeecftr9fdhg.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://cloud.run" rel="noopener noreferrer"&gt;Cloud Run&lt;/a&gt; is Google’s fully-managed solution that automatically scales stateless containers with a pay-per-use model. It is remarkably simple to use and a good fit to expose this small Java web application to the world or within your organization.&lt;/p&gt;

&lt;p&gt;With our image being already available from Cloud Registry we can simply deploy a new service with &lt;a href="https://cloud.google.com/sdk/gcloud" rel="noopener noreferrer"&gt;&lt;code&gt;gcloud&lt;/code&gt;&lt;/a&gt; :&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ gcloud run deploy --image gcr.io/PROJECT-ID/pdfmerger&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;You can provide options to specify the service name, the use of the &lt;em&gt;managed&lt;/em&gt; platform (vs. hosting on a Kubernetes cluster), the deployment region. You can allow unauthenticated requests if you’d like to make this accessible as a public website or restrict its access via Cloud IAM (if this is meant to be a service accessible to other apps in your organization). Here are the relevant options when using &lt;a href="//console.cloud.google.com"&gt;&lt;code&gt;console.cloud.google.com&lt;/code&gt;&lt;/a&gt; :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fyx48vqh7x7kvw6wt9iz6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fyx48vqh7x7kvw6wt9iz6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frvz2byhhnrtu8774aa13.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frvz2byhhnrtu8774aa13.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpemaeu4h9iemtj8u43au.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpemaeu4h9iemtj8u43au.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Because &lt;a href="https://ahmet.im/blog/cloud-run-is-a-knative/" rel="noopener noreferrer"&gt;Cloud Run is built on Knative&lt;/a&gt;, you can also deploy the same app on Anthos GKE with &lt;a href="https://cloud.google.com/run/choosing-a-platform" rel="noopener noreferrer"&gt;Cloud Run for Anthos&lt;/a&gt;, a great option for some corporate settings.&lt;/p&gt;

&lt;p&gt;Once deployment completes (which should be fairly quick), Cloud Run gives you a URL :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7x8m1uhxwfsrssestoec.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7x8m1uhxwfsrssestoec.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F25btawp0ylpvfl3m39qf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F25btawp0ylpvfl3m39qf.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The 40 MB file size limitation seemed reasonable and is enforced using SpringBoot’s  &lt;code&gt;application.properties&lt;/code&gt;. I’ve also bumped up the memory setting for Cloud Run to 2 GB.&lt;/p&gt;

&lt;h1&gt;
  
  
  A word on concurrency
&lt;/h1&gt;

&lt;p&gt;Cloud Run has concurrency built-in, which means that multiple requests can hit the same container instance. This is a great way to better utilize resources but also to limit cold starts. It however means that you need to build your service with concurrency in mind; or always use concurrent APIs and services. &lt;/p&gt;

&lt;p&gt;In our case, this means that concurrent users (all those using a given container instance) share the same filesystem and it is important to keep that in mind to avoid mixing users files in any way. For this app, I addressed this by grouping files by user with a common prefix and preserving their order in a List.&lt;/p&gt;

&lt;h1&gt;
  
  
  Just a starting point
&lt;/h1&gt;

&lt;p&gt;You can quickly deploy your own copy of this webapp using the &lt;a href="https://github.com/GoogleCloudPlatform/cloud-run-button" rel="noopener noreferrer"&gt;Cloud Run button&lt;/a&gt; (linked off of the repo's &lt;a href="https://github.com/alexismp/pdf-merger" rel="noopener noreferrer"&gt;&lt;code&gt;README&lt;/code&gt;&lt;/a&gt;). This will encapsulate all the steps discussed so far and present you with a URL with the deployed service.&lt;/p&gt;

&lt;p&gt;As it stands there are still a few limitations with this web app but hopefully it has shown you one way that you can make a popular command-line tool available via a serverlessly-hosted web service.&lt;/p&gt;

&lt;p&gt;All of the code discussed is available in the &lt;a href="https://github.com/alexismp/pdf-merger" rel="noopener noreferrer"&gt;GitHub repo&lt;/a&gt; and a live instance of the app is &lt;a href="https://pdf-merger-unite-nmv4siw5tq-ew.a.run.app" rel="noopener noreferrer"&gt;running here&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  The sky's the limit
&lt;/h1&gt;

&lt;p&gt;It’s not just about PDF! You can adapt this to use &lt;em&gt;ImageMagick&lt;/em&gt; (to transform images), &lt;em&gt;ffmpeg&lt;/em&gt; (e.g. to &lt;a href="https://bernd.dev/2020/04/trim-videos-instantly/" rel="noopener noreferrer"&gt;trim videos&lt;/a&gt;), &lt;em&gt;Inkscape&lt;/em&gt;, or any other OS program that can be containerized. If you’re looking to generate a PDF from productivity suite formats, then consider using &lt;a href="https://github.com/as-a-service/pdf" rel="noopener noreferrer"&gt;this similar example&lt;/a&gt; which is using LibreOffice.&lt;/p&gt;

</description>
      <category>googlecloud</category>
      <category>cloudrun</category>
      <category>pdf</category>
      <category>java</category>
    </item>
  </channel>
</rss>
