5 Persisting and managing data in the cloud

 

This chapter covers

  • Understanding databases in a cloud native system
  • Implementing data persistence with Spring Data JDBC
  • Testing data persistence with Spring Boot and Testcontainers
  • Managing databases in production with Flyway

In chapter 1, I distinguished between application services and data services in a cloud native system. So far, we have worked with application services, which should be stateless to play well in a cloud environment. However, most applications are useless if they don’t store any state or data somewhere. For example, the Catalog Service application we built in chapter 3 has no persistent storage mechanism, so you can’t really use it to manage a catalog of books. Once you shut it down, all the books you added to the catalog are gone. As a consequence of being stateful, you can’t even scale the application horizontally.

The state is everything that should be preserved when you shut down a service and spin up a new instance. Data services are the stateful components of a system. For example, they can be data stores like PostgreSQL, Cassandra, and Redis, or they can be messaging systems like RabbitMQ and Apache Kafka.

5.1 Databases for cloud native systems

5.1.1 Data services in the cloud

5.1.2 Running PostgreSQL as a container

5.2 Data persistence with Spring Data JDBC

5.2.1 Connecting to a database with JDBC

5.2.2 Defining persistent entities with Spring Data

5.2.3 Enabling and configuring JDBC auditing

5.2.4 Data repositories with Spring Data

5.3 Testing data persistence with Spring and Testcontainers

5.3.1 Configuring Testcontainers for PostgreSQL

5.3.2 Testing data persistence with @DataJdbcTest and Testcontainers

5.3.3 Integration tests with @SpringBootTest and Testcontainers

5.4 Managing databases in production with Flyway

5.4.1 Understanding Flyway: Version control for your database