Docs

Documentation versions (currently viewingVaadin 25 (prerelease))

Deploy a Project

Deploy your Vaadin application to Fly.io and connect it to a database.

After building your Vaadin walking skeleton locally, you’ll probably want to deploy it so others — friends, colleagues, or customers — can try it out.

Deploying a Vaadin application is no different than deploying any other Spring Boot application. Most Vaadin applications run on a single server, but you can also run them on clusters as long as the runtime environment supports session affinity.

Note
What is Session Affinity?

In a cluster, session affinity ensures that all requests from the same user session always go to the same server. This avoids the need for session replication, which can improve performance. The trade-off is that if a server fails, all sessions stored on it are lost.

You’ll now learn how to deploy your walking skeleton to Fly.io. The purpose is to get your application up and running quickly, not to prepare it for production.

Before you begin:

  • Sign up for a Fly.io account.

  • Install the Fly.io CLI

  • Login with your account.

For details, see the Fly.io documentation.

Important

Fly.io isn’t completely free, but it does offer a free trial for new users.

Deploy the Skeleton

In the project root, run:

Source code
terminal
fly launch --ha=false -y

The --ha=false flag prevents Fly.io from starting multiple machines. This matters because Vaadin applications are stateful, and without session affinity, running multiple instances will cause session issues. Fly.io does not provide session affinity out of the box.

The -y flag accepts all default parameters. You’ll get an interactive session if you remove it, allowing you to change the parameters.

After deployment, the CLI will display the URL where your application is available.

Add a Database

By default, a new walking skeleton uses an in-memory H2 database. This is fine for testing, but all data is lost when the application restarts. For a more realistic deployment, you’ll want to connect it to a persistent PostgreSQL database.

Create a Database

Run:

Source code
terminal
fly postgres create -n <postgres-app-name> --initial-cluster-size 1 --volume-size 10 --vm-size shared-cpu-1x -r arn

This creates a single-machine PostgreSQL cluster with 10 GB of disk space, 1 shared CPU, and 256 MB of memory, located in the Stockholm region. For an interactive session that lets you pick from various options, run fly postgres create without flags.

Then attach the database to your application:

Source code
terminal
fly postgres attach <postgres-app-name> --app <app-name>

This adds a DATABASE_URL secret to the application. The CLI will also print it to the terminal. It looks like this:

Source code
properties
DATABASE_URL=postgres://<username>:<password>@<hostname>:5432/<database>?sslmode=disable

Java applications need a JDBC URL, username, and password instead of this URL. To provide them, set new secrets:

Source code
terminal
fly secrets set DATABASE_JDBC_URL="jdbc:postgresql://<hostname>:5432/<database>?sslmode=disable" DATABASE_USER=[username] DATABASE_PASSWORD=[password]

Replace the placeholders with values from the DATABASE_URL.

Update Your Application

Add the PostgreSQL JDBC driver to your project. In pom.xml, include:

Source code
XML
<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <scope>runtime</scope>
</dependency>

Then, create a new file src/main/resources/application-prod.properties with the following content:

Source code
properties
spring.datasource.url=${DATABASE_JDBC_URL}
spring.datasource.username=${DATABASE_USER}
spring.datasource.password=${DATABASE_PASSWORD}
spring.datasource.driver-class-name=org.postgresql.Driver

Redeploy the application with:

Source code
terminal
fly deploy

Your walking skeleton now uses PostgreSQL instead of H2, while Hibernate manages the schema.

For a production-ready setup, see the guides: Add Flyway and Replace H2.

Clean Up

To avoid unwanted charges, remove the deployed resources when you’re done:

Source code
terminal
fly apps destroy <app-name> <postgres-app-name> -y

This permanently deletes both the application and the database.