Performance, Load, and Stress Testing Spring Boot REST APIs
Measure, diagnose, and improve a Spring Boot order API with Gatling, Prometheus, Grafana, and PostgreSQL — one controlled experiment at a time.
Chapters
A vocabulary for measuring
Seven kinds of performance test, what each one can and cannot tell you, and the SLI/SLO vocabulary that turns "is it fast?" into a question you can answer.
A reproducible test environment
Stand up PostgreSQL, Prometheus, and Grafana with Docker Compose, and pin down the variables — CPU, memory, data volume, warm-up — that make two test runs comparable.
Instrument before you measure
Wire Actuator and Micrometer into the order API, expose Prometheus metrics, and learn which metric names answer which diagnosis questions — before the first Gatling run.
The Order Management API
Build the baseline Spring Data JPA service — schema, indexes, entities, repository, service, controller — designed to be measured, not to be perfect.
Realistic test data
Generate a million orders with a deterministic SQL script, extract feeder files for Gatling, and pick a data-reset strategy that keeps test runs isolated.
Gatling simulations
Four complete Gatling simulations — read-heavy, mixed write, paginated search, and a stepped stress test — plus feeders, open vs closed models, and assertions that fail the run.
Running a load test correctly
Warm-up, steady state, and cool-down; the one-variable-at-a-time experiment loop; coordinated omission; and how to tell client-side latency from server-side latency.
Reading the results
How to read a Gatling report, the PromQL queries that explain what it shows, and a symptom-to-bottleneck table that turns a latency graph into a hypothesis.
Diagnosing common Spring Boot bottlenecks
The recurring bottleneck shapes — database, application, JVM runtime, infrastructure — each with its metric signature and the cheapest experiment that proves or kills the hypothesis.
Evidence-based optimizations
Five optimizations done the way they should be done — hypothesis first, one change, measured re-test — covering indexes, N+1, projections, HikariCP sizing, thread pools, and caching.
Stress, spike, and soak testing
Three boundary-finding test profiles — stepped stress, sudden spike, multi-hour soak — plus what healthy overload behavior looks like and how to find the breaking point safely.
Performance tests in CI and Kubernetes
A GitHub Actions regression job, which tests belong at which pipeline stage, Kubernetes resource settings for honest benchmarks, and why CPU throttling lies about latency.
The production checklist
The full measurement-to-optimization workflow condensed, the mistakes that invalidate results, and a capstone exercise that walks the whole loop on a bottleneck you induce yourself.