catalog
A REST API for events and venues: Spring Boot, PostgreSQL, Flyway, a container — and its unloaded latency
During the flash sale, how many reads of the event page happen for each change an admin makes?
GET
/catalog/events?city=&page=&size=
/catalog/events/{id}
404
POST
/catalog/events
201
Location
PUT
DELETE
200
204
/catalog/venues
Everything under /catalog: the edge and the gateway route without rewriting paths.
/catalog
size ≤ 50
BigDecimal
NUMERIC(10,2)
TIMESTAMPTZ
problem+json
201 Created
In the interview: resources + verbs, pagination strategy, error model.
@Transactional
The API never returns entities: only records (EventOut, VenueOut). A new column must not leak; a lazy association must not explode.
EventOut
VenueOut
@GetMapping public PageOut<EventOut> list( @RequestParam(required = false) String city, @RequestParam(defaultValue = "0") @Min(0) int page, @RequestParam(defaultValue = "20") @Min(1) @Max(50) int size)
@Valid @RequestBody EventIn
400
?size=500
400 problem+json
Listing 20 events, each with its venue. How many SQL queries?
join fetch
select e from Event e join fetch e.venue
V1__create_catalog.sql
V2__seed_catalog.sql
V3__...
ddl-auto: validate
generate_series
Realistic data volume on purpose: a query instant on 10 rows can take tens of ms on 200,000.
FROM maven:3.9-eclipse-temurin-21 AS build RUN --mount=type=cache,target=/root/.m2 mvn -B -q package -DskipTests FROM eclipse-temurin:21-jre COPY --from=build /src/target/app.jar app.jar USER app ENTRYPOINT ["java", "-XX:MaxRAMPercentage=75", "-jar", "app.jar"]
db
depends_on: condition: service_healthy
pg_isready
db-data
down
down -v
/actuator/health/readiness
Inside a container, the database is db, not localhost.
localhost
k6 run load/smoke.js # 1 VU, 30 s, think time 0.5 s
GET /catalog/events/{id}
GET /catalog/events?city=
One laptop's numbers — record yours in results/lab1.md.
results/lab1.md
count(*)
Which endpoint will break first under load? Write the hypothesis for lab 2.
docker compose up --build
Outline: (1) why catalog first; (2) the API contract; (3) layers and DTOs; (4) JPA, N+1, the pool; (5) Flyway; (6) Dockerfile and Compose; (7) smoke test and service time.