Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Spring Boot: Production Boost

Thomas Vitale
September 01, 2021

Spring Boot: Production Boost

The Spring ecosystem provides you with all you need for building modern applications. In this session, we'll highlight useful features in five areas to get your applications ready for production.

- JVM and Containerization. Producing efficient Spring Boot images with Cloud Native Buildpacks, configuring CPU and memory for the JVM, and handling container resources in Kubernetes.
- Configuration. Avoiding common mistakes when using profiles, planning a configuration strategy using property files, configuration services, and Kubernetes.
- Data Integration. Managing schemas and data with Flyway directly from Spring Boot for imperative and reactive apps.
- Testing. Leveraging sliced tests for targeted integration tests, using mock servers, and relying on Testcontainers for environment parity.
- Monitoring. Configuring health probes for Kubernetes, securing the management endpoints, taking a heap dump, and troubleshooting performance.

Thomas Vitale

September 01, 2021
Tweet

More Decks by Thomas Vitale

Other Decks in Programming

Transcript

  1. Thomas Vitale SpringOne Sep 1st, 2021 Spring Boot: Production Boost

    Boost your journey to production @vitalethomas
  2. Thomas Vitale • Senior Software Engineer at Systematic, Denmark. •

    Spring, Cloud Native, DevOps, Kubernetes, Application Security. • Author of “Cloud Native Spring in Action” (Manning). About Me thomasvitale.com
  3. Packaging Spring Boot JAR & Container Image thomasvitale.com @vitalethomas JAR

    Container Image Gradle bootJar Maven spring-boot:repackage Gradle bootBuildImage Maven spring-boot:build-image JVM & Containers
  4. Configuring Resources for JVM Containers CPU & Memory thomasvitale.com @vitalethomas

    CPU Memory When limit hit Throttle Compressible Resource When limit hit OOMKilled Non Compressible Resource
  5. Data Integration thomasvitale.com @vitalethomas Spring Data for Relational Databases Spring

    Data JPA ‣JPA & Hibernate ‣Repositories ‣JDBC Spring Data JDBC ‣DDD Principles ‣Repositories ‣JDBC Spring Data R2DBC ‣DDD Principles ‣Repositories ‣R2DBC Data Integration
  6. Schema and data management Flyway: Version control for your database

    thomasvitale.com @vitalethomas SQL Migrations Schema changes Java Migrations Data changes V1 Init schema V2 Add column V3 Create table V4 Add constraint time Data Integration
  7. Configuration Options thomasvitale.com @vitalethomas Spring Boot Properties ‣Property fi les

    ‣Command line arguments ‣Environment variables Con fi guration Services ‣Spring Cloud Con fi g Server ‣Spring Cloud Consul Con fi g ‣Spring Cloud Vault ‣Spring Cloud Zookeeper Con fi g Cloud Platform Services ‣Spring Cloud Alibaba ‣Spring Cloud AWS ‣Spring Cloud Azure ‣Spring Cloud GCP Kubernetes Platform ‣Con fi gMaps ‣Secrets ‣Environment variables Con fi guration
  8. Configuration Strategies thomasvitale.com @vitalethomas Con fi guration Properties Property fi

    les ‣Default values ‣Development environment values Con fi guration Service Spring Cloud Con fi g ‣Connection pools ‣Timeouts and retries ‣Feature fl ags ‣External Services (URLs & Passwords) Kubernetes Platform Con fi gMaps & Secrets ‣Spring Active Pro fi les ‣Internal Services (URLs & Passwords) Con fi guration
  9. ConfigMaps & Secrets thomasvitale.com @vitalethomas Mount the volume to the

    /config path, where Spring Boot will automatically read property fi les. Load the Con fi gMap In a volume
  10. Testing Spring Boot thomasvitale.com @vitalethomas Types of auto tests for

    Spring Boot applications Unit Tests ‣JUnit ‣Mockito ‣No Spring context Integration Tests ‣@SpringBootTest ‣Web server ‣Full Spring context Slice Tests ‣@SpringWebMvc ‣@SpringDataR2dbc ‣Sliced Spring context Testing
  11. Testcontainers thomasvitale.com @vitalethomas Testing with external dependencies Docker containers Run

    external dependencies as Docker containers Data Layer Tests Ensure environment parity by testing the data layer with the real database Integration Tests Use containers for databases, message queues, and web servers Testing
  12. Monitoring and management thomasvitale.com @vitalethomas Operating applications in production Spring

    Boot Actuator ‣Health (liveness and readiness) ‣Metrics (Prometheus, OpenMetrics) ‣Flyway, Thread Dumps, Heap Dumps Spring Cloud Sleuth ‣Distributed tracing ‣Instrumentation ‣OpenZipkin and OpenTelemetry Monitoring & Management
  13. Liveness and Readiness Probes thomasvitale.com @vitalethomas When not available, Kubernetes

    will restart the container When not ready, Kubernetes will not send any tra ff i c to the container
  14. Thomas Vitale SpringOne Sep 1st, 2021 Spring Boot: Production Boost

    Boost your journey to production @vitalethomas