Performance Engineering
Performance engineering is a loop: define SLOs, measure under realistic load, fix the hottest path, remeasure.
Introduction
Performance engineering is a loop: define SLOs, measure under realistic load, fix the hottest path, remeasure. For TechLearningPRO Orders on Boot 3 / Java 21, tools include k6/Gatling for load, JFR / async-profiler for production-shaped profiles, and JMH only for true micro-benchmarks.
Without SLOs (for example p95 under 200ms and error rate under 0.1%), teams over-optimise vanity paths. Laptop datasets lie — stage with production-like cardinality and payload sizes.
Virtual threads are a step-change for I/O-bound Boot web apps on Java 21, but they do not fix N+1 SQL or an undersized Hikari pool. Measure first.
This lesson installs the discipline that turns monitoring data into durable latency wins.
Purpose of this lesson
Run an SLO-driven performance loop on Orders with load tests, profiling, and Java 21-aware fixes.
Understanding the topic
SLOs make performance measurable; tools answer where time goes.
- SLOs: latency and error budgets before tuning.
- Load: k6/Gatling against prod-shaped staging.
- Profile: JFR/async-profiler under real traffic patterns.
- Micro: JMH only for isolated hot methods — not whole HTTP stacks.
- Java 21: virtual threads for blocking I/O concurrency when the stack is ready.
Step-by-step explanation
- Write SLOs for checkout (p95/p99 and error rate).
- Load-test staging with realistic SKUs, users, and payload sizes.
- Profile the slow window; fix top SQL, pools, or I/O — not random JVM flags.
- Enable virtual threads if I/O-bound and remeasure against the same SLO.
Informative example
SLO knobs + virtual threads for Orders (Boot 3 / Java 21).
# application.ymlspring:threads:virtual:enabled: truedatasource:hikari:maximum-pool-size: 20connection-timeout: 3000jpa:open-in-view: false# k6 sketch — checkout SLO probeimport http from 'k6/http';import { check } from 'k6';export const options = {thresholds: {http_req_duration: ['p(95)<200'],http_req_failed: ['rate<0.001'],},};export default function () {const res = http.post('https://orders.example/api/orders', payload, params);check(res, { 'status 201': (r) => r.status === 201 });}
Real-world use
TechLearningPRO spent a week tuning GC flags while checkout p99 was dominated by missing indexes. After an async-profiler session under k6 load, one composite index and disabling open-in-view met the SLO — GC flags never shipped.
Security implications
Perf work must not weaken auth or leak data via caches.
- Do not disable security filters for speed.
- Cache keys for private data must include tenant/principal.
- Keep profiler outputs free of secret material when sharing dumps.
Best practices
- Define SLOs before changing code.
- Load-test in a prod-shaped staging environment.
- Prefer fixing SQL and pools over micro-benchmark theatre.
Common mistakes
- Optimising without an SLO or baseline.
- Profiling on empty local databases.
- Adopting virtual threads while blocking the carrier with synchronized pin-heavy libraries without measuring.
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1BeginnerQuestionWhy define SLOs before optimising?+
Answer
2IntermediateQuestionWhen should you use JMH vs k6?+
Answer
3IntermediateQuestionHow do virtual threads help Spring Boot web apps?+
Answer
Hands-on exercise
Lab. Set a p95 SLO for POST /api/orders. Run a short k6 test, capture a JFR or async-profiler snapshot under load, fix the top frame or SQL, and show the delta against the same threshold.
Summary
Performance engineering keeps Orders honest against SLOs. Next: structure the codebase with Clean Architecture so optimisations stay testable.