TL;DR: Records are more than a way to cut getter boilerplate from DTOs. They are a modelling tool. Use them for value objects that check their own rules, closed sets of outcomes with sealed types, typed configuration, query projections and composite keys, and your production code gets smaller, safer and easier to read.
Generated AI image by Google Gemini Nano Banana
Introduction
Records have been final since Java 16, and in most codebases I’ve worked in they ended up in one place: the dto package. Request body in, response body out, job done. It’s a fair first use. It removes a lot of Lombok and hand-written equals().
But stopping there misses most of the point. Records were designed as transparent carriers for immutable data. Since Java 21 they also work with sealed interfaces and record patterns, and together these give you a lightweight way to do data-oriented programming in plain Java.
In this post, we’ll explore where records belong in production backend systems, and where they don’t. Whether you’re building a payments service on Spring Boot 3 or tidying up a legacy domain model, you’ll find patterns you can apply on Monday.