From "Fundamentals of Software Architecture"
🎧 Listen to Summary
Free 10-min PreviewInteracting Layers, Anti-patterns, and Performance Characteristics
Key Insight
The interaction between layers in a layered architecture is defined by whether layers are 'open' or 'closed,' directly impacting the concept of 'layers of isolation.' A closed layer dictates that requests must pass sequentially through each immediate layer below it, for example, from the presentation layer through the business and persistence layers before reaching the database. Conversely, an open layer permits requests to bypass intermediate layers, a concept sometimes referred to as the 'fast-lane reader pattern' in the early 2000s, where the presentation layer might directly access the database for simple retrievals. Crucially, closed layers uphold 'layers of isolation,' ensuring that changes in one layer (e.g., persistence) do not tightly couple and impact other layers (e.g., business, presentation), thereby preventing a brittle and costly-to-change application. This isolation also facilitates replacing entire layers, such as swapping a JavaServer Faces (JSF) presentation layer for React.js, provided well-defined contracts and the business delegate pattern are utilized. The strategic use of open and closed layers, coupled with clear documentation, is essential to avoid tightly coupled, brittle architectures that are difficult to test, maintain, and deploy.
The 'architecture sinkhole' anti-pattern represents a significant concern where requests pass through multiple layers with minimal or no business logic processing, for instance, a simple customer data retrieval traversing presentation, business, rules, and persistence layers without aggregation or transformation. This inefficient pass-through processing results in unnecessary object instantiation and resource consumption, negatively affecting memory and performance. While some sinkholes are unavoidable, the 80-20 rule serves as a guideline: if 80 percent of requests are sinkholes, the layered architecture may be ill-suited for the problem domain, though making all layers open is a potential mitigation at the cost of increased change management complexity. Despite these challenges, the layered architecture is a sound starting point when the definitive architectural style is yet to be determined, such as during microservices evaluation, provided reuse is minimized and object hierarchies are shallow to ease future transitions. It is also an excellent choice for small, simple applications or websites, as well as projects with stringent budget and time constraints, being one of the lowest-cost architecture styles due to its simplicity and developer familiarity.
Analyzing the architecture's characteristics using a star rating system (one star for poor support, five stars for strong features) reveals its strengths and weaknesses. 'Overall cost' and 'simplicity' are primary strengths, benefiting from its monolithic nature, which avoids complexities of distributed systems, though these advantages diminish as layered architectures grow in size and complexity. However, 'deployability' and 'testability' rate very low (one star for deployability, two for testability) due to the 'ceremony of deployment' where even minor code changes require redeploying the entire application, increasing risk and bundling numerous unrelated changes. 'Elasticity' and 'scalability' are also rated very low (one star) due to monolithic deployments and lack of architectural modularity; achieving scalable functions within a monolith demands complex techniques like multithreading, and the single system quantum inherently limits overall scaling capacity. 'Performance' receives a two-star rating, as the style does not naturally lend itself to high-performance systems due to factors like limited parallel processing, closed layering, and the architecture sinkhole anti-pattern, requiring significant extra effort like caching to enhance it. 'Fault tolerance' is not supported, as a failure in any small part of the monolithic application can lead to a complete crash, resulting in high mean-time-to-recovery (MTTR) and impacted availability, with startup times ranging from 2 minutes for smaller applications to over 15 minutes for large ones. 'Reliability' rates medium (three stars), primarily benefiting from less network traffic compared to distributed architectures, but tempered by the monolithic deployment model, low testability, and inherent deployment risks. As applications built on this style expand, their maintainability, agility, testability, and deployability are adversely affected, suggesting that more modular architecture styles are better suited for large-scale systems.
📚 Continue Your Learning Journey — No Payment Required
Access the complete Fundamentals of Software Architecture summary with audio narration, key takeaways, and actionable insights from Mark Richards, Neal Ford.