Tldr
Software architecture describes the important structures and constraints of a system. Design patterns describe reusable approaches to recurring design problems within those structures. Neither supplies a finished solution: the team still has to connect each choice to requirements, understand its trade-offs, and verify the result.
An application can contain well-written classes and still be difficult to change. The problem may sit above any individual class: user-interface code talks directly to storage, several components compete to own the same data, or a critical dependency has no failure strategy.
Software architecture addresses these larger relationships and decisions. It identifies significant components, their responsibilities, allowed dependencies, communication paths, and deployment boundaries. It also explains why the structure can meet the system’s important quality requirements.
A design pattern works at a more focused level. It names a recurring design problem, describes a proven arrangement of responsibilities, and records the consequences of using it. A pattern is reusable design knowledge, not a library to import or code to copy unchanged.
Architecture starts with the qualities that matter
A diagram of boxes and arrows is only part of an architecture. The design should respond to the system’s goals and operating conditions.
Common quality attributes include:
| Attribute | Useful questions |
|---|---|
| Performance | Which operations have latency or throughput targets, and under what load? |
| Availability | How much downtime is acceptable, and which failures must the system survive? |
| Modifiability | Which changes are expected, and how quickly should the team be able to make them? |
| Testability | Can important behaviour and integrations be exercised in controlled conditions? |
| Usability | Which users and tasks does the interaction design need to support? |
| Security | What must be protected, from whom, and across which trust boundaries? |
These words become useful when they are made concrete. “The system must be fast” is difficult to design or test. “The device list should respond within 500 ms for at least 95% of requests while 2,000 users are active” gives the team a workload, a measure, and a target.
Quality attributes also pull the design in different directions. Caching may improve response time while making invalidation and data freshness harder. Replication may improve availability while adding consistency and operational concerns. Extra security checks may add latency. The architect’s work includes making these tensions visible and recording why a compromise was chosen.
Record decisions, not just diagrams
A short architecture decision record can state the problem, the options considered, the chosen approach, its consequences, and the evidence that would cause the team to revisit it.
Architecture styles shape the whole system
An architecture style constrains the kinds of components in a system and the relationships allowed between them. Layered, event-driven, microservices, and web-queue-worker are examples. Each favours certain qualities and introduces its own difficulties; none is the default answer for every application. Microsoft: Architecture styles
Styles can also coexist. A microservice may organise its internal code in layers. Its web interface may use Model–View–Controller (MVC). It may publish events to other services. These labels describe different parts or views of the design rather than mutually exclusive product choices.
| Style | Organising idea | Typical pressure it addresses | Cost to examine |
|---|---|---|---|
| Layered | Separate responsibilities by technical role | Understandable dependency boundaries | Changes that cut through several layers |
| Event-driven | Producers publish events for consumers | Asynchronous processing and independent consumers | Ordering, duplicates, tracing, and eventual consistency |
| Microservices | Independently deployable services own business capabilities | Team autonomy and independent deployment or scaling | Network failure, data consistency, observability, and operations |
| MVC | Separate model, view, and input/controller concerns | User-interface organisation | Boundaries can blur as screens and workflows grow |
The best choice follows the business drivers, change patterns, team capabilities, and operational environment. Adopting microservices does not automatically make a system scalable or loosely coupled. A well-structured monolith can scale and evolve successfully; a distributed system can remain tightly coupled through synchronous calls, shared databases, or coordinated releases.
Layered architecture
Layered architecture groups code by responsibility and controls how those groups depend on one another. A common arrangement contains presentation, application or business, persistence, and database concerns.
flowchart TD UI["Presentation<br/>HTTP and user interface"] --> APP["Application and business<br/>use cases and rules"] APP --> DATA["Persistence<br/>repositories and mapping"] DATA --> DB[("Database<br/>storage engine")]
The arrows show permitted calls in a simple closed-layer design. Responses travel back to the caller. They are not a deployment diagram and do not mean each box needs its own server.
What each layer owns
Presentation translates between the outside interaction and an application operation. In a web application, it may validate the shape of an HTTP request and format the response. Business decisions do not belong in a page template or route handler.
Application and business coordinates use cases and protects business rules. For a device-backup tool, it may decide whether a user can request a backup and which policy applies. It should not build SQL or depend on a particular web framework merely to express that rule.
Persistence translates between the application’s data needs and a storage mechanism. Repositories, database queries, and object-to-row mapping often sit here.
Database means the storage technology and its physical data concerns: tables, indexes, constraints, replication, and durability. Some teams call this a data tier rather than a code layer.
Layers and tiers are not the same
A layer is a logical separation of responsibilities in the design. A tier is a physically separate deployment group, such as web servers, application servers, or a database service. Several layers can run together in one tier. Conversely, one logical responsibility may use several deployed components.
Calling an application “three-tier” should therefore describe deployment boundaries, not merely the presence of three folders. Microsoft likewise distinguishes logical layers from physical tiers in its N-tier guidance. Microsoft: N-tier architecture style
Closed and open layers
In a closed arrangement, a layer calls only the layer immediately below it. This makes dependencies predictable and prevents presentation code from quietly depending on database details.
An open arrangement permits a layer to skip one or more layers. A read-only screen might use a specialised query component instead of passing a simple query through business services that add no value. The shortcut saves work, but it also creates another dependency that the team must maintain.
Neither rule guarantees isolation. A database schema change can still affect persistence code and the business concepts it reconstructs. Well-defined contracts reduce unnecessary ripples; they do not make related changes disappear.
Strengths and limits
Layering is familiar, makes responsibility boundaries visible, and can support focused tests. It often suits business applications whose operations naturally pass through user interaction, rules, and data access.
It can also encourage ceremonial pass-through code. A small change may touch a controller, service, repository, mapping object, and database even when each file adds little meaning. Organising everything by technical layer can scatter one business capability across the codebase.
Layered architecture does not imply a monolith, and a monolith does not imply poor scalability. Deployment and scaling depend on runtime boundaries, workload shape, state management, and infrastructure. Physical tiers can be scaled independently, though every network boundary adds latency and new failure modes.
Design patterns solve recurring local problems
Architecture styles shape broad system structure. Design patterns usually focus on relationships among a smaller set of classes or objects. The boundary is not perfectly sharp, but the distinction helps a team discuss the scale and consequences of a decision.
| Level | Example question | Example response |
|---|---|---|
| Architecture style | How will major parts of the workload be separated and deployed? | Layered architecture or microservices |
| Design pattern | How can callers work with incompatible interfaces? | Adapter |
| Language idiom | How should a Python resource be cleaned up? | A context manager used with with |
Patterns are commonly grouped into three families:
| Family | Main concern | Examples |
|---|---|---|
| Creational | How objects are created and supplied | Factory Method, Abstract Factory, Builder, Prototype, Singleton |
| Structural | How objects or classes are assembled | Adapter, Decorator, Facade, Proxy, Composite |
| Behavioural | How responsibilities and messages move between objects | Observer, Strategy, State, Command, Mediator |
A useful pattern description includes more than a name:
- Context: the situation in which the problem appears
- Problem and forces: the competing needs or constraints
- Structure: the responsibilities and relationships in the proposed arrangement
- Consequences: what improves, what becomes more complex, and which new risks appear
- Applicability: signals that the pattern fits, and signals that it does not
Start with the problem. Choosing “a pattern to use” before identifying the pressure it resolves often produces extra indirection without a benefit. Pattern names are most valuable when they give the team a precise shorthand for a design already justified by its context.
Singleton: one instance with global access
The Singleton pattern restricts a class to one instance and supplies a widely available way to retrieve it. Configuration registries, process-wide coordinators, and access to a genuinely unique resource are common motivations.
The two parts of the definition matter. A dependency-injection container may create one instance for an application’s lifetime without giving the class a global access method. That is shared lifetime management, but it does not give every caller an implicit global dependency.
Singleton has significant costs:
- callers can depend on shared state without declaring that dependency
- tests can affect one another unless the state is reset safely
- initialization order and configuration can become hidden
- concurrency makes lazy creation and mutable state harder to protect
- “one” usually means one per process or interpreter, not one across a cluster
A database connection is rarely a good Singleton example. Concurrent server applications commonly use a bounded connection pool, which reuses connections and limits how many can be used at once. The pool may have an application-wide lifetime, managed by startup code and passed to the components that need it. SQLAlchemy: Connection pooling
class BackupService:
def __init__(self, connection_pool, audit_log):
self._connection_pool = connection_pool
self._audit_log = audit_log
def build_backup_service(settings, pool_type, audit_type):
pool = pool_type(settings.database_url, max_size=10)
audit = audit_type(settings.audit_path)
return BackupService(pool, audit)pool_type and audit_type are application-specific constructors supplied by startup code. The startup path creates one of each for this service and makes the dependencies visible. Tests can supply controlled replacements without reaching into global state.
Python also makes a simple module-level object easy to share: import machinery normally reuses an already loaded module from sys.modules. That can be practical for immutable constants or deliberately process-wide services, but it still creates global access and does not coordinate separate processes. Python language reference: The import system
Python has no Java-style private constructor. A class that raises from __init__() after the first construction is easy to misuse, can run into races, and may behave unexpectedly with subclasses, serialization, or reloads. If a single lifetime is truly required, define its scope, creation point, concurrency rules, reset behaviour, and failure handling rather than relying on the pattern name.
UML communicates selected views of a design
The Unified Modeling Language (UML) is a standard notation for visualising, specifying, and documenting software and other systems. It includes structural diagrams, such as class and component diagrams, and behavioural diagrams, such as sequence and activity diagrams. Object Management Group: UML
This class sketch shows inheritance and composition in a small network model. It assumes that a device owns its interface objects, with each interface belonging to at most one device at a time:
flowchart LR ROUTER["Router<br/>+ routing_protocol<br/>+ get_neighbors()"] -->|inherits from| DEVICE["Device<br/>+ hostname<br/>+ show()<br/>- write_audit(message)"] DEVICE -->|contains 0..*| INTERFACE["Interface<br/>+ name<br/>+ address"]
The relationship names are written out to keep the sketch readable. In standard UML class notation:
+marks a public member,-a private member, and#a protected member- a solid line with a hollow triangular arrow points from the specialised class to its base class
- a filled diamond at the whole’s end marks composition: a part belongs to at most one whole at a time, and deleting the whole deletes the parts still attached to it in the model
- multiplicities such as
1and0..*describe how many objects may participate
The visibility symbols express the model’s intended interface. They do not change Python’s runtime access rules, which rely heavily on convention. Likewise, a Python reference alone does not enforce composition’s ownership and lifetime rules. The sketch omits constructors, storage, and other details that are not needed for this view. For the full notation, see the OMG UML specification.
UML is useful for sketching a proposed design, explaining a difficult relationship, or reconstructing part of an existing system. It becomes expensive when the team tries to reproduce every line of source code in diagrams. Draw the view that answers a real question and keep it at the level that its audience needs.
A practical selection process
Architecture and patterns should follow evidence rather than fashion:
- Describe the workload, users, data, trust boundaries, and expected changes.
- Make the critical quality requirements measurable.
- Identify the decisions that will be costly to reverse.
- Compare options and their failure modes, not only their success paths.
- Prototype or test uncertain qualities such as throughput, recovery, or integration behaviour.
- Record the decision and the conditions that would justify revisiting it.
Use a design pattern when its context and trade-offs match a local problem. Use an architecture style when its constraints support the system’s larger goals. In both cases, the name begins the discussion; it does not finish the design.