When a plain layered design is the better choice
Evaluate architectural trade-offs to determine when simple layered designs outperform hexagonal architecture for thin CRUD and stable systems.
Contentsand lesson path
On this page
- The Seduction of Clean Architecture Dogma
- Contexts Where Plain Layered Design Wins
- The Evolutionary Path: From Layered to Hexagonal
Lessons of Clean & Hexagonal Architecture
- Which way dependencies point: layers, the MVC family, ports and adapters Concept · 25 min
- Driving ports, driven ports and the composition root Concept · 20 min
- Moving a layered service to hexagonal Lab · 30 min
- Testing the core with in-memory adapters Lab · 20 min
- When a plain layered design is the better choice Concept · 10 min
- Dependency rule check Knowledge check · 6 questions
What you will learn
- Compare layered, hexagonal, onion and clean architecture by dependency direction, place MVC-family presentation patterns (MVC, MVP, MVVM) within them, and judge when the extra indirection is not worth its cost.
Prerequisites: Software Design Principles
01. The Seduction of Clean Architecture Dogma
In technical conferences and software craftsmanship literature, Hexagonal and Clean Architecture are frequently presented as universal ideals. Architects are told that every system must be structured with concentric rings, that domain entities must never touch framework annotations, and that every external interaction must be abstracted behind an interface.
This dogmatic approach ignores a fundamental economic reality: architecture is an investment that incurs ongoing maintenance overhead. Every boundary seam, port interface, adapter class, and data mapper introduced into a codebase extracts an operational tax in cognitive load, code navigation friction, and boilerplate maintenance.
A mature architect does not ask: "Is this design theoretically pure?" Instead, an architect asks: "Does the complexity of the domain and the volatility of the infrastructure justify the economic cost of these abstraction layers?" In many software systems, a plain, disciplined layered architecture is not merely acceptable—it is the strictly superior choice.
02. Contexts Where Plain Layered Design Wins
A plain layered design—where web controllers call service classes that directly invoke database ORMs—is the more cost-effective choice in several clearly identifiable contexts:
- Thin CRUD Applications: Many applications exist solely to create, read, update, and delete database records. An internal employee directory, a customer contact book, or an administrative catalog manager rarely contains complex domain calculations or multi-step invariants. In these systems, a
Customerentity in the domain model would simply mirror thecustomersdatabase table column for column. Introducing a domain entity, a persistence entity, a DTO, and four mappers to copy five strings across layers produces massive ceremony with zero business value. - Stable, Single-Database Systems: The speculative argument that "we might switch from PostgreSQL to MongoDB next year" is overwhelmingly false in commercial enterprise software. Most organizations choose a database engine and remain on it for the entire lifespan of the application. If infrastructure is completely stable, abstracting it behind generic ports solves an imaginary problem.
- Early-Stage Prototypes and Exploratory Spikes: When a startup is validating product-market fit, business requirements change daily. Introducing rigid hexagonal boundaries slows down exploratory refactoring. Moving fast with an Active Record framework (such as Django or Rails) allows teams to validate user demand before investing in architectural insulation.
- Data Ingestion and ETL Pipelines: Systems focused on high-throughput batch processing, reporting, or data synchronization benefit far more from database-native SQL performance (set-based bulk updates, joins, and window functions) than from object-oriented domain abstraction layers.
- Small Cross-Functional Teams with Low Attrition: When a tight-knit team of three engineers maintains a focused service with deep collective domain context, formal port-and-adapter seams add ceremony without solving real communication friction. Architecture must scale with organizational team topologies as described by Conway's Law.
03. The Evolutionary Path: From Layered to Hexagonal
Choosing a plain layered architecture for a new service does not mean abandoning good engineering discipline. Teams can write clean, modular layered code that preserves a clear upgrade path toward hexagonal architecture if domain complexity eventually warrants it.
Disciplined Layered Practices:
- Avoid Anemic Procedural Spaghetti: Even in a layered design, keep business logic inside service classes rather than scattering SQL updates across HTTP controller handlers.
- Maintain Package Seams: Organize modules by business feature rather than technical layer. If an order service is cleanly isolated in an
orderspackage with clear public methods, inverting its dependencies later requires minimal effort. - Refactor Upon Friction: Monitor concrete indicators of architectural pain: are unit tests becoming impossibly slow because every test hits a live database? Are changes to an external payment provider breaking core calculation logic? When these concrete forces manifest, refactor that specific subsystem to hexagonal ports and adapters.
Architectural Selection Heuristic
-
Choose Plain Layered Architecture When:
- The system is primarily CRUD with minimal business invariants.
- The team is small (1–4 developers) with a single shared repository.
- The application is an internal tool or early prototype.
- The database schema is stable and mirrors user interaction models.
-
Choose Hexagonal Architecture When:
- The domain core contains intricate, high-value business calculations and invariants.
- Multiple distinct delivery mechanisms (REST, CLI, Kafka, WebSockets) must drive the same business use cases.
- Sub-second, isolated unit test execution is a non-negotiable requirement for CI velocity.
- Third-party infrastructure and external APIs are volatile and prone to frequent vendor changes.
Concrete Transition Triggers: When to Invert Dependencies Teams should not wonder in the abstract whether to adopt hexagonal architecture. Instead, watch for three unambiguous empirical indicators of architectural strain in a layered system:
- 1. Test Execution Wall: The automated test suite slows down to the point where developers bypass local runs before pushing. When unit test duration surpasses thirty seconds due to database container setup, extracting in-memory repository ports instantly restores developer flow.
- 2. Channel Multiplication: The business requests a secondary delivery channel—such as consuming an event stream from Kafka or introducing an interactive CLI tool alongside the existing web controllers. If business rules are trapped inside web controllers, developers duplicate code. Introducing a driving port allows both controllers and event consumers to invoke the same use case.
- 3. Persistent Data Leakage into Domain Logic: When database transactions, session flush methods, and SQL query tuning begin appearing inside core financial rules, the risk of production data corruption increases. Inverting the persistence dependency behind a driven repository port protects domain invariants.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
6 questions · about 5 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.