CQRS Meets Modern Java
summary
Repository with 3,000 orders triggers about 5,000 SQL statements and a ~3 second response via a naïve JPA mapping, causing the N+1 selects problem and over‑/under‑fetching. Replacing the monolithic DTO endpoints with separate command records (Java 17 sealed interfaces and records), Jackson type info for polymorphic commands, and a SQL-first query side (jOOQ-like multiset queries) yields a single SQL statement and about 3x faster reads while keeping commands as simple inserts/updates.
AI-written summary · about
