Quick revision
The short answer
Common anti-patterns in Spring applications are god service classes with thousands of lines mixing many features, anemic domain models where entities only have getters and setters and rules are duplicated across services, JPA entities exposed directly in REST APIs, circular dependencies between services or packages, database tables shared by several services so their releases are coupled, and util or common packages that collect unrelated code. Each one makes change more expensive by hiding coupling or scattering rules.
What to remember
In this answer, we went through six architecture anti-patterns in Spring applications. God services concentrate unrelated changes in one class; anemic domain models scatter and duplicate business rules; entities in REST APIs cause lazy loading problems and tie the API to the schema; circular dependencies weld classes together; shared tables couple service releases; and util packages collect unrelated code that everything depends on. Each one hides coupling, and each has a well-known fix.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Common anti-patterns in Spring applications are god service classes with thousands of lines mixing many features, anemic domain models where entities only have getters and setters and rules are duplicated across services, JPA entities exposed directly in REST APIs, circular dependencies between services or packages, database tables shared by several services so their releases are coupled, and util or common packages that collect unrelated code. Each one makes change more expensive by hiding coupling or scattering rules.
Why this question is asked
An anti-pattern is a solution that looks reasonable when we write it and causes trouble later. Spring makes many things easy, including some of these: injecting any bean anywhere, mapping a table to a class with one annotation, returning that class from a controller. Interviewers ask about anti-patterns to see whether we recognise them in a codebase and can explain the cost in concrete terms rather than as matters of taste. In this answer, we will go through six common ones, show what each looks like, and explain why each is harmful and what to do instead.
1God Service Classes
A god class is a class that knows and does too much. In Spring applications it usually appears as a service such as OrderService that has grown to 3,000 lines and 40 dependencies, handling ordering, pricing, refunds, emails and reporting.
It is harmful because every change to any of those areas touches the same file, so merge conflicts and accidental breakage are constant. Its tests are hard to write because constructing it needs dozens of mocks. And nobody can understand it fully, so people add another method rather than improve the existing ones, which makes it grow further. The fix is to split it by use case or by feature, for example PlaceOrder, RefundOrder and OrderReporting, each with only the dependencies it needs.
2The Anemic Domain Model
An anemic domain model is one where entities are just data, with getters and setters and no behaviour, and every business rule lives in services. Martin Fowler named it in the early 2000s, describing it as procedural code dressed in objects.
The harm is duplication. When the rule that an order cannot be cancelled once shipped lives in OrderService.cancel(), another developer writing AdminService or a batch job writes the same check again, slightly differently. Over time the rules drift apart, and the entity can be put into an invalid state by anyone who calls a setter.
Notice that the fix is not to move all logic into entities; services still orchestrate use cases. The point is that rules about an object's own state belong with that state, so they are written once.
3Exposing JPA Entities in REST APIs
Returning entities from controllers is convenient, and it is one of the most costly anti-patterns. Jackson serialises every getter, so lazy associations either trigger extra queries, the N+1 problem, or throw LazyInitializationException; bidirectional relationships produce infinite JSON cycles; internal fields such as audit columns appear in the API; and incoming JSON bound directly to an entity can set fields the client should never touch, which is called mass assignment. Above all, the API contract is now the database schema, so a column rename breaks clients. The fix is request and response DTOs, often Java records, shaped for each endpoint.
4Circular Dependencies
A circular dependency is when A depends on B and B depends on A, directly or through a chain. In Spring it can appear between beans, such as OrderService injecting CustomerService and CustomerService injecting OrderService, or between packages, where orders imports customers and customers imports orders.
Since Spring Boot 2.6, circular references between beans are prohibited by default, and the application fails at startup with a message describing the cycle. Teams sometimes re-enable them with spring.main.allow-circular-references=true or break them with @Lazy, which hides the design problem. The harm is that neither side can be understood, tested or changed without the other, and the two classes effectively become one. The fix is to extract the shared logic into a third class, or reverse one dependency with an event.
5Shared Database Tables Between Services
When two services read and write the same tables, the table schema is a contract between them that nobody owns. Adding a column, changing a type or splitting a table requires both services to change and deploy together. So services that look independent are coupled in their release cycles, and a careless query from one can lock rows the other needs.
The fix is data ownership: each table belongs to one service, and other services get the data through its API or events, or keep their own copy of the fields they need.
6Util and Common Packages
Almost every codebase has a util or common package. It starts with a date helper and a string helper, and grows into a home for anything without an obvious place: pricing helpers, email formatting, a copy of an order mapper. Because everything depends on it, it becomes a central point of coupling, and changes to it risk breaking every feature. The fix is to place code with the feature that uses it, and keep a shared package only for small, genuinely generic utilities, or better, use the standard library.
| Anti-pattern | Main harm | Usual fix |
|---|---|---|
| God service | every change collides, hard to test | split by use case or feature |
| Anemic domain model | rules duplicated and bypassed | put state rules on the entity |
| Entities in REST APIs | N+1, cycles, leaks, schema as contract | request and response DTOs |
| Circular dependencies | classes cannot change apart | extract a class or use an event |
| Shared tables across services | coupled releases and locks | one owner per table, APIs or events |
| Util or common package | hidden coupling, misplaced logic | move code to its feature |
7Follow-up questions
Is the anemic model always an anti-pattern?
Not always. For simple CRUD services where the only rules are validation, data classes and a service are clear enough. It becomes harmful when the same business rules are needed in several places and get duplicated, or when objects can be put into invalid states.
How do you detect these anti-patterns automatically?
ArchUnit can detect package cycles, forbid controllers returning entity types and forbid dependencies on util packages from certain layers. Static analysis tools flag very large classes and constructors with many parameters. Spring itself reports bean cycles at startup since Boot 2.6.
Which of these would you fix first in a legacy codebase?
Usually entities in APIs, because they cause production incidents through N+1 queries and accidental data exposure, and the fix can be applied endpoint by endpoint. Shared tables come next if services must be deployed together. God classes are best split gradually, starting with the parts that change most often.
8Conclusion
In this answer, we went through six architecture anti-patterns in Spring applications. God services concentrate unrelated changes in one class; anemic domain models scatter and duplicate business rules; entities in REST APIs cause lazy loading problems and tie the API to the schema; circular dependencies weld classes together; shared tables couple service releases; and util packages collect unrelated code that everything depends on. Each one hides coupling, and each has a well-known fix.
Open with
The first one I see most often is the god service: an OrderService with thousands of lines and dozens of dependencies that handles ordering, refunds, PDFs and reports.
Then, if they want more
Every change collides there and testing it needs a pile of mocks, so I split it by use case. Second, the anemic domain model, where entities are just getters and setters and all rules live in services.
The harm is duplication: the rule that a shipped order cannot be cancelled ends up written in three services, slightly differently, and anyone can call setStatus. Rules about an object's own state belong on the object.
Third, returning JPA entities from REST controllers, which causes lazy loading during serialisation, so N+1 queries or LazyInitializationException, JSON cycles, leaked internal fields and mass assignment, and it makes the schema the API contract.
Fourth, circular dependencies between services or packages, which Spring Boot rejects at startup by default since 2.6; working around them with @Lazy hides the problem, so I extract a third class or use an event. Fifth, tables shared by several services, which couples their release cycles because a schema change needs both to deploy together.
And finally util or common packages that collect unrelated code, so everything depends on them. Most of these can be caught early with ArchUnit rules.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Boot 2.6
- 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 "Name common architecture anti-patterns in Spring applications and explain why each is...": https://scrivio-interview-library.netlify.app/java/application-architecture/ce36a08f71/