Software Architecture
Overview of Software Architecture
- Definition: Software architecture is fundamental to business survival, reliability, scalability, and maintainability. It guides the long-term evolution of a system.
- Levels of Abstraction:
- Small-level: The architecture of individual programs.
- Large-level: The architecture of complex enterprise systems.
- Advantages of Design and Documentation:
- Facilitates stakeholder communication.
- Enables effective system analysis.
- Supports large-scale reuse of components and patterns.
- Modelling Techniques: Architectures are often modelled using simple block diagrams, UML, or other detailed diagram representations.
Case Study: The Transformation of Netflix (2008)
- Initial Monolithic Architecture: In 2008, Netflix utilized a monolithic system where all components (Authentication, Movie Catalog, Billing, etc.) were tightly coupled and relied on a single large database.
- The Major Failure: A major database corruption and the failure of backup systems led to a three-day platform outage, affecting millions of users.
- Weaknesses Identified: The monolith suffered from single points of failure, no fault isolation, and was extremely hard to scale or recover.
- Strategic Transformation: Netflix shifted to a microservices architecture deployed on cloud infrastructure (AWS).
- Microservices: Independent services (Login, Billing, etc.) provide failure isolation.
- Results: Improved scalability (handling millions of concurrent users), faster feature deployment, and high availability (99.99% uptime).
Architectural Patterns
Architectural patterns are high-level, reusable solutions to recurring design problems, defining the structure, components and interactions of a software system.
1. Model-View-Controller (MVC)
- Description: Separates presentation and interaction from the system data.
- Components:
- Model: Manages system data and business logic,.
- View: Manages how data is presented to the user (UI),.
- Controller: Manages user interactions (e.g., clicks) and coordinates between the Model and View,.
Simplification
Model = Data + Business Logic
Controller = Flow manager View = Presentation only
- When to Use: When there are multiple ways to interact with data or when future presentation requirements are unknown.
- Advantages: Allows data to change independently of its representation.
- Disadvantages: Can add unnecessary complexity to simple systems.
2. Layered Architecture
- Description: Organizes a system into a hierarchy of layers, where each layer provides services to the one immediately above it.
- When to Use: Building new facilities on existing systems, when teams are responsible for specific functional layers, or when multi-level security is required.
- Advantages: Entire layers can be replaced as long as the interface is maintained; supports redundant facilities for higher dependability.
- Disadvantages: Clean separation is often difficult to achieve in practice; performance may suffer due to multiple levels of service request interpretation.

3. Repository Architecture
- Description: All data is managed in a central repository accessible to all components. Components only interact through this repository.
- When to Use: For data-driven systems or when large volumes of information must be stored for long periods.
- Advantages: Components can be independent; changes made by one component are easily propagated to others; consistent data management (e.g., centralized backups).
- Disadvantages: The repository is a single point of failure; communicating solely through a repository can be inefficient.

4. Client-Server Architecture
- Description: Functionality is organised into services, each delivered from a separate server, which clients access over a network.
- When to Use: When data in a shared database must be accessed from multiple locations.
- Advantages: Servers can be distributed across a network; general functionality (like printing) can be shared by all clients.
- Disadvantages: Each service is a single point of failure; performance is unpredictable as it depends on network health. The servers can be owned by different organisations.

5. Pipe and Filter Architecture
- Description: Discrete processing components (filters) carry out one type of data transformation; data flows through "pipes" from one component to another.
- When to Use: Common in batch- or transaction-based data processing applications.
- Advantages: Easy to understand and supports transformation reuse; straightforward to evolve by adding new transformations. Sequential or Concurrent systems.
- Disadvantages: Requires a common data transfer format; each filter must parse and unparse data, increasing system overhead,.

cat names.txt | grep "John" | sort | uniq
| Pattern | Best For... | Avoid if... |
|---|---|---|
| Layered | General Enterprise Apps | You need ultra-low latency (layers add overhead). |
| Repository | Data abstraction/Testing | The app is very simple (it adds unnecessary files). |
| MVC | Dynamic User Interfaces | There is no UI (e.g., a background service). |
| Client-Server | Network-based sharing | You have no network or need offline-first logic. |
| Pipe-Filter | Data transformation / Compilers | The steps need a lot of back-and-forth interaction. |