Scrivio Interview library
LeadershipAdvanced6 min read · updated 12 November 2026

Set the standard for constructing objects in shared libraries and services across 25 teams: hand-written builders, Lombok @Builder, or records with compact constructors. What do you decide and why?

I would not pick one technique for everything. The standard would be records with compact constructors for data carriers and value objects, hand-written builders for public configuration objects in shared libraries, and Lombok @Builder allowed only inside a service, never in a shared library's public API. What matters most is that each codebase is consistent, so the decision is written down with examples and checked in review of library APIs.

Why this question is asked

When 25 teams share libraries, the way objects are constructed becomes part of every public API. A library that changes from a builder to a constructor breaks every caller, and a library that depends on a compiler plugin forces that plugin on every consumer's build. Interviewers ask this at a senior level because the answer is less about syntax and more about trade-offs that last for years: tooling risk, readability, upgrade cost and how a standard actually gets followed. In this answer, we will recap the three options, look at where each fits and what it costs, and then write the standard and the way we would roll it out.

1A Quick Recap of the Three Options

A record, a standard feature since Java 16, is a final class declared by its components; the compiler generates the constructor, the accessors, equals(), hashCode() and toString(). A compact constructor lets us validate and normalise those components before they are assigned. Records need nothing beyond the JDK.

A hand-written builder is a nested class with one method per optional field and a build() method that creates the immutable object. It is more code, but every line is visible and can carry documentation.

Lombok @Builder generates a builder at compile time. Lombok is not a normal annotation processor: it hooks into the internals of the Java compiler to change the code being compiled. That is why it can add methods to an existing class, and also why each new JDK release can break it until Lombok catches up.

2Where Records Fit

Records fit data carriers and value objects: an OrderId, a Money amount, an event payload, a response DTO. These have a small number of fields, the caller usually has all of them, and equality by value is exactly what we want. The compact constructor gives us validation in the one constructor every caller must pass through.

Java
public record Money(BigDecimal amount, Currency currency) {
public Money {
Objects.requireNonNull(currency, "currency");
amount = amount.setScale(currency.getDefaultFractionDigits(), RoundingMode.HALF_EVEN);
}
}
new Money(new BigDecimal("10.5"), Currency.getInstance("EUR")).amount(); // 10.50

Notice that the normalisation happens before assignment, so there is no way to create a Money with three decimal places. Records also have a security benefit we will come back to: they are deserialized through their canonical constructor, so the validation runs there too. Their limit is size: with ten or more fields, or many optional ones, calling the constructor becomes hard to read.

3Where Hand-Written Builders Fit

Public configuration objects in shared libraries are different. A RetryPolicy or an HttpClientSettings type is used by hundreds of call sites in other teams' code, has many optional fields, and will gain new fields over the years. A builder lets the library add a new optional field without breaking any caller, because existing calls simply do not set it. Each builder method can carry Javadoc that explains the default and the unit, and build() can check rules that span fields.

Writing the builder by hand costs perhaps 50 lines per type. For a library type that is used for five years by 25 teams, that cost is small compared with the cost of a confusing API, so in libraries we accept it.

4What Lombok Costs

Lombok removes a lot of boilerplate, and many teams like it. But it has three costs that matter more in shared code than in a single service. First, it is a compiler plugin that must keep up with every JDK upgrade; when the organisation moves to a new JDK, every library that uses Lombok waits for a compatible Lombok release. Second, the generated code is not in the source, so readers, code search and some tools do not see the builder methods or the defaults. Third, Lombok adds nothing at run time, but it makes every shared library build depend on it, and stepping through generated code in a debugger is harder.

So the decision is not that Lombok is bad. It is that inside one service the team that chose it also pays for it, while in a shared library everyone else pays.

Construction standard by kind of type
Kind of typeStandardReason
Value object, DTO, eventRecord with compact constructorNo tools, value equality, validation in one place
Public config type in a shared libraryHand-written builder over an immutable class or recordDocumented defaults, new fields without breaking callers
Internal class inside one serviceTeam choice, Lombok allowedThe owning team pays the upgrade cost
Public API of any shared libraryNo LombokEvery consumer would share the upgrade risk

5Consistency Matters More Than the Choice

Here is the reasoning a senior person uses. Each of the three options is defensible on its own. What hurts is a codebase where three similar classes are built three different ways, because every reader has to stop and work out the pattern again, and reviewers cannot spot a missing validation by habit. So the standard should be simple enough to remember in one sentence: records for data, builders for library configuration, Lombok only inside a service if the team wants it.

Existing code does not have to be rewritten. If a service already uses Lombok everywhere and works, converting it brings risk without benefit. The standard applies to new code and to code we touch for other reasons.

6Writing It Down and Checking It

A standard that is only announced is forgotten within a quarter. We would write a short page with one worked example of each case, including a builder template that teams can copy, and put it next to the other engineering standards. Shared libraries get a review checklist item: does every public configuration type have a builder with documented defaults, and is the public API free of Lombok? An architecture test, for example with ArchUnit, can fail a library build if a public class carries Lombok annotations, though Lombok's annotations are mostly gone from the compiled class files, so checking the source in review or with a lint rule is often simpler.

Finally, we would revisit the standard when the language changes. If derived record creation becomes a final Java feature, records may cover more of what builders do today, and the page should say so.

7Follow-up questions

What if a team insists that Lombok makes them much faster?

Inside their own service, they can use it; the standard allows that. The rule only applies to shared library APIs, where the upgrade risk falls on other teams. I would show them the reason with an example, such as a JDK upgrade that waited for a Lombok release, rather than argue about preference.

Do records replace builders completely?

Not yet. Records are excellent for small data types where the caller has all values. For types with many optional fields, a record's constructor becomes long and positional, so a builder in front of it is still the readable way. A record can be the product of a builder, which combines both strengths.

How do you stop the standard from becoming a bottleneck?

Keep it short, give templates, and review only public library APIs strictly. Internal code gets the guidance but not a gate. The goal is consistent, readable public APIs, not policing every class.

8Conclusion

In this answer, we set a construction standard for 25 teams. Records with compact constructors fit data carriers and value objects and need no tools. Hand-written builders fit public configuration objects in libraries, where validation, defaults and documentation matter and new fields must not break callers. Lombok saves boilerplate but is a compiler plugin that must keep up with JDK upgrades and hides generated code, so it stays out of shared library APIs. Consistency matters more than the exact choice, so we write it down with examples and check library APIs in review.

What to say in the interviewAbout 70 seconds aloud

Open with

I would set a standard by kind of type rather than pick one tool. Value objects, DTOs and events should be records with compact constructors: they need no extra tools, they give value equality, and the compact constructor is the one place where validation and normalisation happen.

Then, if they want more

Public configuration types in shared libraries should get a hand-written builder over an immutable class or record, because they have many optional fields, the defaults and units need documentation, and a builder lets us add a field later without breaking hundreds of callers.

Lombok I would allow inside a single service if that team wants it, but not in the public API of shared libraries, because it is a compiler plugin that has to catch up with each JDK release and it hides the generated code from readers and tools; in a library, every consumer shares that risk.

The most important part is consistency, so I would write a one-page standard with a worked example and a builder template, add a review checklist item for library APIs, and apply it to new and touched code rather than rewriting working services.

About this answer

Last updated
12 November 2026
Versions it names
Java 16
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Set the standard for constructing objects in shared libraries and services across 25...": https://scrivio-interview-library.netlify.app/java/creational-patterns/dd7e765510/