Software architecture: principles, patterns and the 4+1 view
Clear, exam-focused notes on software architecture principles, common patterns, and the 4+1 view for computer engineering students.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Software architecture is the high-level structure of a software system and guides major design and implementation decisions. Engineers use architecture to ensure non-functional requirements (performance, reliability, modifiability, security) are met, to communicate design choices to teams, and to plan implementation, deployment and maintenance.
Key ideas
Start from first principles: a software system is built from components (units of computation or data) connected by connectors (communication, control links). The arrangement of components and connectors that satisfies functional and non-functional requirements is the software architecture.
Definitions (bold terms are defined):
- Software architecture: the set of principal design decisions about a system’s structure, including major components, their relationships, and the rationale behind these choices. (Use this exact phrase in definitions questions.)
- Component: a unit of software with a defined interface and well‑specified responsibilities. It can be a module, class, service or process.
- Connector: mechanism that allows components to interact (function call, message, event, data stream).
- Architectural pattern: a reusable solution to a commonly occurring architectural problem within a given context (examples: layered, client–server, microservices, MVC, event-driven).
- Quality attribute (also called non-functional requirement): a measurable property like performance, availability, modifiability, security.
- Tactic: a specific low-level technique to achieve a quality attribute (e.g., caching to improve performance).
Principles and laws (state them exactly as exam answers):
- Separation of concerns: design the system so that each concern (responsibility) is addressed by a distinct component or layer. Assumption: concerns are reasonably separable and have well-defined interfaces.
- Modularity: divide the system into modules with high cohesion and low coupling. Definition: cohesion measures relatedness of responsibilities inside a module; coupling measures interdependence between modules.
- Single Responsibility Principle (SRP): a module should have one, and only one, reason to change (define "reason to change" as a distinct responsibility or concern).
- Information hiding: hide internal module details behind interfaces to allow independent changes.
- Abstraction: present only necessary details; hide low-level implementation.
- Principle of Least Privilege: components should run with the minimal privileges they need.
Quality attributes — definitions and trade-offs:
- Performance: how fast the system responds (response time) and how much work it does per time (throughput). Trade-off: caching improves performance but may reduce consistency.
- Availability: fraction of time the system is operational. Trade-off: higher availability often increases cost and complexity.
- Reliability: probability the system performs without failure for a given time interval.
- Scalability: ability to handle growth in workload; measured as throughput growth when resources are added.
- Modifiability: ease to make changes; improved by low coupling and good abstraction.
Architectural patterns — brief exact statements:
- Layered (n-tier): components are arranged in layers; each layer provides services to the layer above and uses services from the layer below. Draw: stacked horizontal boxes labeled Presentation, Application/Business, Domain, Persistence, Infrastructure; arrows point down for service usage.
- Client–server: a small number of servers provide services to many clients. Draw: servers on left, many client boxes on right, arrows from clients to servers.
- Microservices: system decomposed into small independently deployable services, each owning its data. Emphasise independent deployment, lightweight communication (usually HTTP/REST or messaging), and decentralised data.
- MVC (Model–View–Controller): separate domain (Model), user interface (View) and control logic (Controller). Draw: three boxes with arrows: View -> Controller -> Model and Model -> View.
- Event-driven: components communicate via events through an event bus or broker; useful for asynchronous, loosely-coupled systems.
- Pipe-and-filter: processing elements (filters) connected by data streams (pipes); use when data transforms in stages.
- Broker: components register with a broker which mediates communication, used when heterogenous components must interact.
4+1 View Model (Philippe Kruchten) — exact definitions and what to show:
- Logical view: presents the object model or high-level classes and their relationships; used by stakeholders concerned with functionality (users, analysts). Draw a UML class or component diagram showing main logical components and their relations.
- Development view (implementation view): shows software organization in the environment of the development team (modules, layers, subsystems, source code structure). Draw a module diagram or package diagram with team boundaries.
- Process view: shows runtime processes, threads, inter-process communication and concurrency. Used to reason about performance, scalability and reliability. Draw boxes for processes, arrows for communication (RPC, message queues), and annotate threads or tasks.
- Physical view (deployment view): shows mapping of software onto hardware nodes, networks and physical topology. Draw servers, load balancers, DB nodes and map components to machines.
- Scenarios (the +1): use cases or scenarios that illustrate how elements in the other four views work together. Scenarios validate the architecture. For each scenario, list the sequence of interactions and indicate which views are exercised.
How to use the 4+1 model: choose representative scenarios (functional and quality-attribute driven), create the four views focusing on relevant concerns, then use scenarios to check consistency across views and refine tactics.
Diagrams to draw in exams (describe exactly):
- 4+1 diagram: draw four boxes arranged in a square labelled Logical, Development, Process, Physical. Draw an extra box labelled Scenarios connected to the centre of the square. Inside each view box sketch the relevant diagram (e.g., for Physical: servers and network; for Process: processes and message queues).
- Layered architecture: stacked boxes for layers, arrows showing allowed direction of calls (usually downwards only).
Formulas
Availability = MTTF / (MTTF + MTTR) — MTTF = mean time to failure (mean uptime between failures), MTTR = mean time to repair (downtime). Many texts use MTBF to mean MTTF; if MTBF is defined as mean uptime between failures, the equivalent form is Availability = MTBF / (MTBF + MTTR). Applies to systems with measurable repair cycles when failures and repairs are distinct.
Reliability R(t) = e^{-λ t} — λ = failure rate (failures per unit time), t = time (seconds, hours), R(t) is unitless (probability). Assumes exponential failure distribution (memoryless).
Service capacity (service rate) μ = 1 / S where S = average service time per request — the maximum throughput of a saturated single-server is μ requests/sec; for m identical parallel servers, capacity ≈ m / S. Actual throughput equals the arrival rate λ as long as λ < capacity; otherwise queues grow and response time explodes.
Utilization U = arrival rate (λ) × service time (S) — unitless fraction; arrival rate in requests/sec, S in seconds. Applies in queuing context (e.g., M/M/1 approximations).
(When giving these in an exam, state the assumptions: exponential arrivals, memoryless service, independent failures as needed.)
Worked examples
Example 1 — Availability calculation (numerical): Given: MTTF (mean uptime between failures) = 180 days, MTTR = 4 hours. Convert units to hours. Step 1: MTTF = 180 days × 24 hours/day = 4320 hours. Step 2: MTTR = 4 hours. Formula: Availability = MTTF / (MTTF + MTTR) = 4320 / (4320 + 4) = 4320 / 4324 = 0.999074. Final answer: Availability = 99.9074%.
Example 2 — Use the 4+1 to design a simple online bookstore (theory/model answer): Question: Sketch the architecture and explain views. Answer outline to write in exam:
- Logical view: components: Catalog, ShoppingCart, OrderProcessor, PaymentService, UserAccount. Show associations: User -> ShoppingCart; ShoppingCart -> Catalog; OrderProcessor -> PaymentService.
- Development view: map components to modules/packages: com.bookstore.catalog, com.bookstore.order, com.bookstore.payment. Show repository layout and testing modules.
- Process view: processes: web front-end process, order-processing worker (background), payment gateway adapter process, database process. Show asynchronous queue between web front-end and order worker.
- Physical view: web servers behind a load balancer, application servers, payment adapter server, database cluster. Map modules to server nodes.
- Scenarios: place order scenario: user selects book (logical + physical), checkout posts order (process: enqueue), order worker dequeues and calls payment (logical + process), DB updates (physical). Use this to test reliability (what if payment fails?) and add tactics (retry, compensation transactions). A full-marks answer draws the diagrams, names components/modules/processes, and links scenario steps to views.
Example 3 — Applying a pattern (short algorithmic trace): Question: Explain event flow in an event-driven architecture for stock price updates. Answer: Producer (market feed) publishes event to event bus (broker). Broker forwards to subscribers (trader UI, analytics service). If analytics service is slow, broker buffers events. Show sequence: MarketFeed -> Broker (publish) -> Broker -> TraderUI (notify) and Broker -> Analytics (enqueue). Describe failure handling: durable queue, replay.
Common mistakes
- Omitting assumptions for formulas (e.g., MTBF/MTTR availability formula assumes separate failure and repair cycles).
- Drawing views but not explaining which stakeholders use them or which scenarios validate them.
- Mixing process and physical view: process view shows runtime processes and threads; physical view shows hardware nodes and deployment mapping.
- Claiming microservices always improve performance or availability; they trade increased operational complexity and network overhead.
For your exam
Typical question types: definitions, short notes (explain a principle), compare and contrast (patterns), draw and label diagrams, derive and apply formulas (availability, reliability), scenario-based architecture design (use 4+1), and critique an architecture for quality attributes. What to include for full marks:
- For definitions: concise formal definition and one-line example.
- For principles: state the principle, give rationale, and one example tactic.
- For patterns: draw a simple diagram and list trade-offs (pros and cons).
- For 4+1 questions: provide all four views plus at least one scenario; draw clear diagrams and map components across views.
- For numericals: show unit conversions, formula used, step-by-step calculation and final percentage or numeric value with units.
Quick check
- What is the main purpose of the 4+1 view model?
- Write the availability formula in terms of MTBF and MTTR.
- Name two architectural tactics to improve reliability. Answers: 1) To describe an architecture with four complementary views (logical, development, process, physical) plus scenarios to validate design. 2) Availability = MTBF / (MTBF + MTTR). 3) Redundancy (replication) and checkpointing/rollback (and also retry with backoff).
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?