Architectural Design
Open in the Padhaiko app4.1 Introductions and importance
Software Architecture
The software architecture of a program or computing system is the high-level structure of the system, comprising software components, the externally visible properties of those components, and the relationships (connectors) among them.
Architectural design represents the bridge between requirements engineering and detailed component-level design. Before writing code or designing individual algorithms, engineers establish the system's overall blueprint.
Why Software Architecture Is Important
According to Bass, Clements, and Kazman (and Pressman), architectural design is crucial for three primary reasons:
- Mutual Communication Among Stakeholders: Architecture provides a common, high-level abstraction that customers, project managers, security auditors, and developers can all inspect, critique, and negotiate early.
- Early Design Decisions & Quality Attribute Enforcement: Fundamental quality attributes—such as performance, scalability, availability, security, and maintainability—are largely determined by the architecture and are extremely costly to retrofit later.
- Transferable Abstraction (Large-Scale Reuse): A well-documented architecture serves as an intellectual asset that can be reused across a product line of systems sharing similar requirements.
4.2 Architectural design principles
Effective software architectures obey a core set of engineering design principles:
| Principle | Meaning and Practical Benefit |
|---|---|
| 1. Separation of Concerns | Divide complex problems into distinct parts (e.g., presentation, business logic, data persistence) so each concern can be reasoned about and modified independently. |
| 2. Abstraction | Focus on essential external behavior and interfaces while hiding internal implementation details at higher architectural levels. |
| 3. Information Hiding (Parnas) | Encapsulate volatile design decisions (data formats, algorithms, hardware interfaces) behind stable interfaces so internal changes do not ripple outward. |
| 4. Modularity | Partition software into separately named, addressable components (modules) that integrate to satisfy problem requirements. |
| 5. Functional Independence | Design each module to perform one well-defined task with minimal interaction with other modules (high cohesion, low coupling). |
| 6. Refinement & Refactoring | Elaborate top-level architectural abstractions stepwise into detailed structures, continuously simplifying internal structure without changing external behavior. |
| 7. Design for Change & Scalability | Anticipate growth in user load, new integrations, and shifting business rules through loose interfaces and stateless components where possible. |
4.3 Taxonomy of architectural styles
An architectural style is a recurring structural pattern describing a family of systems in terms of component types, connectors, semantic constraints, and topological layout.
(a) Data-Centered (Repository) (b) Pipe-and-Filter (Data Flow)
[ Client ] [ Client ] [Source] -> |Filter A| -> |Filter B| -> [Sink]
\ /
[ Shared Repository ] (c) Layered Architecture
/ \ [ Presentation / UI Layer ]
[ Client ] [ Client ] [ Application / Logic Layer ]
[ Data Access / OS Layer ]| Architectural Style | Components & Connectors | Strengths | Weaknesses / Best Fit |
|---|---|---|---|
| 1. Data-Centered (Repository / Blackboard) | Central data store (DB or shared blackboard) accessed by independent client components | Easy data sharing, centralized backup/security, easy to add new clients | Central repository can become a bottleneck or single point of failure; best for databases, IDEs, compilers |
| 2. Data-Flow (Pipe-and-Filter) | Filters transform input streams into output streams; pipes carry streams sequentially | Reusable filters, intuitive composition, supports concurrent streaming | Poor for interactive UIs; overhead from parsing/serializing streams; best for Unix shells, compilers, ETL pipelines |
| 3. Call-and-Return (Main-Subroutine / OO) | Hierarchical procedures or objects invoking methods via function/RPC calls | Clear control flow, straightforward debugging and decomposition | Tight call dependencies if interfaces change; best for standard desktop and OO business apps |
| 4. Layered (Virtual Machine) | Concentric or stacked layers where layer calls only layer | Clean separation of concerns, layer portability and swap-ability | Latency overhead across layers; strict layering sometimes bypassed; best for OS kernels, TCP/IP, enterprise N-tier web apps |
| 5. Event-Driven (Publish-Subscribe) | Producers emit events to an event bus; subscribers react asynchronously | Very loose coupling, easy to attach new reactions dynamically | Harder to trace end-to-end execution order and debug race conditions; best for GUIs, IoT, real-time notifications |
| 6. Client-Server & N-Tier | Clients request services over a network from specialized servers (Web, App, DB tiers) | Centralized security/data control, independent hardware scaling | Network latency and partial failures; best for web portals, banking systems, multi-user SaaS |
4.4 Modular design, cohesion and coupling
Modular design achieves functional independence—considered the single most important indicator of good software design—by maximizing cohesion within each module and minimizing coupling between modules.
| Aspect | Cohesion | Coupling |
|---|---|---|
| Definition | Degree to which elements inside a single module belong together functionally | Degree of interdependence between two or more separate modules |
| Design Goal | Maximize (High cohesion is desirable) | Minimize (Low / loose coupling is desirable) |
| Effect on Maintenance | High cohesion makes a module focused, readable, and easy to reuse | Low coupling limits ripple effects when one module is modified |
Levels of Cohesion (Worst to Best)
| Rank | Cohesion Type | Description | Quality |
|---|---|---|---|
| 1 (Worst) | Coincidental | Unrelated tasks grouped arbitrarily in one module (e.g., a catch-all miscUtils()) | Avoid |
| 2 | Logical | Logically similar operations placed together, selected by a control flag (e.g., handleAllIO(type)) | Poor |
| 3 | Temporal | Tasks grouped only because they run at the same time (e.g., startupInit() resetting logs, DB, UI) | Fair / Weak |
| 4 | Procedural | Elements grouped because they follow a fixed execution sequence, though acting on different data | Moderate |
| 5 | Communicational | Elements operate on the same input or output data structure (e.g., validate and format a student record) | Good |
| 6 | Sequential | Output data from one element directly serves as input to the next element (pipeline inside module) | Very Good |
| 7 (Best) | Functional | Every element contributes to one single, well-defined task (e.g., computeGPA(grades)) | Ideal |
Levels of Coupling (Worst to Best)
| Rank | Coupling Type | Description | Quality |
|---|---|---|---|
| 1 (Worst) | Content Coupling | One module directly modifies or branches into the internal data or code of another module | Avoid |
| 2 | Common Coupling | Multiple modules read and write the same shared global data area | Poor |
| 3 | External Coupling | Modules share an externally imposed data format, communication protocol, or device interface | Fair |
| 4 | Control Coupling | One module passes a control flag telling another module how to execute internally | Moderate |
| 5 | Stamp Coupling | Modules share a composite data structure (e.g., whole Student object) when only a single field is needed | Good |
| 6 (Best) | Data Coupling | Modules communicate solely by passing only the minimal primitive data parameters required | Ideal |
Structural Metrics: Fan-In and Fan-Out
- Fan-In: Number of higher-level modules that call a given module (high fan-in indicates strong reuse of utility modules).
- Fan-Out: Number of lower-level modules directly invoked by a given module (excessive fan-out signals an overly complex coordinator lacking intermediate abstraction).
Worked Examples
4.1
A web application is designed using a strict Layered Architecture consisting of four layers: Presentation (), Business Logic (), Data Access (), and Database (). A proposed revision introduces an intermediate Security/Policy Proxy Layer that adds of processing per request.
- Compute the single-request end-to-end latency before and after adding the new layer, and find the percentage increase in latency.
- Explain the architectural trade-off between strict layering and performance.
Part 1 — End-to-End Request Latency: Original -layer latency:
Revised -layer latency (with the proxy layer):
Percentage increase in latency:
Part 2 — Architectural Trade-Off:
- Benefit: Adding a dedicated security/policy layer improves separation of concerns, centralizes authentication/authorization checks, and isolates security rules from business logic.
- Cost: Strict layering requires every request to traverse every layer boundary, introducing cumulative serialization, validation, and call latency ( here). Architects mitigate this by caching authorization tokens or allowing controlled read-only fast paths.
- Latency rises from to , a increase.
- Strict layering enhances modularity and maintainability at the expense of inter-layer traversal latency.
4.2
During an architecture review, an engineer inspects a billing module processOrder(orderRecord, modeFlag) that reads a global tax rate variable GLOBAL_TAX, prints an invoice, updates inventory, and emails a receipt depending on modeFlag.
- Identify the cohesion and coupling flaws in the current design.
- Suppose refactoring splits the design into three focused functions (
calculateTotal(subtotal, taxRate),updateStock(itemId, qty),sendReceipt(email, invoiceId)), reducing total cross-module interface arguments/globals from () to (). Compute the percentage reduction in interface surface area and identify the improved cohesion and coupling levels.
Part 1 — Diagnosing Current Cohesion and Coupling Flaws:
- Cohesion Flaw: Mixing invoice calculation, printing, inventory mutation, and email dispatch controlled by
modeFlagyields Logical / Temporal Cohesion rather than single-purpose Functional Cohesion. - Coupling Flaws:
- Reading
GLOBAL_TAXintroduces Common Coupling. - Passing
modeFlagintroduces Control Coupling. - Passing the entire
orderRecordwhen only specific fields are needed introduces Stamp Coupling.
- Reading
Part 2 — Quantitative Interface Reduction and Target Quality: Original interface dependencies items; refactored interface dependencies items:
Each refactored function performs one clear job (Functional Cohesion) and receives only minimal primitive values (Data Coupling).
- The original design suffers from Logical/Temporal Cohesion plus Common (
GLOBAL_TAX), Control (modeFlag), and Stamp (orderRecord) coupling. - Refactoring reduces interface dependencies by (from to ) and achieves Functional Cohesion with Data Coupling.
4.3
How to Answer a Past Exam Question: "Recommend and justify an architectural style for (a) a real-time stock-ticker alert platform and (b) a compiler / log-processing pipeline."
1. Stock-Ticker Alert Platform Event-Driven (Publish-Subscribe) Architecture:
- Structure: Market feed producers publish price-change events to an event broker; portfolio watchers, threshold alert services, and audit loggers subscribe asynchronously.
- Justification: Supports dynamic addition of new subscribers without modifying producers (loose coupling) and scales well under bursty real-time updates.
2. Compiler / Log-Processing Pipeline Pipe-and-Filter (Data-Flow) Architecture:
- Structure: Sequential independent filters (e.g., Lexer Parser Optimizer Code Generator, or Log Collector PII Redactor Aggregator) connected by data streams.
- Justification: Each filter is reusable, testable in isolation, and stages can execute concurrently as streams flow through.
Match system characteristics to style strengths: use Event-Driven (Publish-Subscribe) for asynchronous reactive notifications and Pipe-and-Filter for sequential stream transformations.
Exercises
Practice Exercises — Architectural Design
Define software architecture and explain three reasons why architectural design is vital before detailed coding begins.
Definition: Software architecture defines the high-level structural organization of a system: its components, their externally visible properties, and the connectors/relationships among them.
Three Reasons Architecture Matters:
- Stakeholder Communication: Provides a shared blueprint understandable by clients, managers, and developers.
- Early Quality-Attribute Decisions: Determines performance, security, availability, and modifiability early, when changes are cheapest.
- Large-Scale Reuse: Enables architectural patterns and skeletons to be reused across similar products.
Software architecture is the blueprint of components, interfaces, and connectors. It is vital for stakeholder communication, enforcing early quality attributes, and enabling large-scale architectural reuse.
Explain the architectural design principles of Separation of Concerns, Abstraction, Information Hiding, and Functional Independence.
Four Core Architectural Principles:
- Separation of Concerns: Decompose the system into distinct concerns (e.g., UI, business logic, storage) so each evolves independently.
- Abstraction: Expose essential component behavior while suppressing low-level implementation details.
- Information Hiding: Encapsulate volatile design decisions behind stable module interfaces so changes stay localized.
- Functional Independence: Give each module a single clear responsibility (high cohesion) and minimal inter-module reliance (low coupling).
Separation of concerns isolates distinct responsibilities; abstraction hides unnecessary detail; information hiding shields volatile internals behind stable interfaces; functional independence ensures high cohesion and low coupling.
Compare Data-Centered (Repository), Pipe-and-Filter, Layered, and Event-Driven architectural styles with one practical application for each.
Comparison of Four Architectural Styles:
- Data-Centered: Central repository accessed by multiple clients; easy data sharing, risk of central bottleneck (e.g., IDE metadata repository / banking database).
- Pipe-and-Filter: Independent stream-transforming filters connected by pipes; high filter reuse, weak for interactive UIs (e.g., Unix shell pipelines / compilers).
- Layered: Hierarchical layers where each layer serves the one above; clean separation, potential latency overhead (e.g., OSI/TCP-IP networking stack, enterprise web apps).
- Event-Driven: Components communicate asynchronously via published events; very loose coupling, harder execution tracing (e.g., GUI frameworks, microservice notification systems).
Repository centralizes shared state (databases/IDEs); Pipe-and-Filter chains stream transformations (compilers/Unix tools); Layered separates abstraction levels (OS/network stacks); Event-Driven decouples producers and subscribers asynchronously (GUIs/real-time alerts).
Distinguish between cohesion and coupling. Arrange the seven levels of cohesion and six levels of coupling from worst to best, and identify the ideal level of each.
Cohesion vs. Coupling:
- Cohesion measures intra-module functional relatedness (goal: high).
- Coupling measures inter-module dependence (goal: low).
Ordered Levels (Worst Best):
- Cohesion: Coincidental Logical Temporal Procedural Communicational Sequential Functional (ideal).
- Coupling: Content Common External Control Stamp Data (ideal).
Cohesion measures internal unity (maximize; Functional is ideal) and coupling measures external interdependence (minimize; Data is ideal). Cohesion runs from Coincidental to Functional; coupling runs from Content to Data.
A Pipe-and-Filter log analytics pipeline originally executes four sequential filters with processing times , , , and per batch. By refactoring two tightly coupled legacy helper modules into functionally independent filters and merging redundant parsing steps, the total pipeline latency drops from to .
- Verify the original pipeline latency and calculate the percentage reduction in processing time.
- Explain what fan-in and fan-out mean in modular design, and why minimizing common coupling improves testability.
Part 1 — Pipeline Latency and Percentage Reduction:
Part 2 — Fan-In, Fan-Out, and Common Coupling:
- Fan-In is the number of modules calling a given module (high fan-in signals good reuse).
- Fan-Out is the number of modules called by a given module (very high fan-out indicates excessive orchestration complexity).
- Eliminating Common Coupling (shared mutable global state) ensures modules depend only on explicit parameters, allowing unit tests to run cleanly without hidden global side effects.
- Original latency is , and refactoring achieves a reduction to .
- Fan-in counts incoming callers (reuse) while fan-out counts outgoing calls (complexity); removing common coupling eliminates hidden global state, making modules independently testable.