Software Engineering Principles and Practices / Software Architecture

Architectural Patterns

While Architectural Styles provide the high-level philosophy (the "language" of the system), Architectural Patterns are concrete, proven solutions to recurring design problems. Think of a style as "Classical Architecture" and a pattern as "Building a specific type of Arch."

In a professional setting, patterns help engineers ensure the system is scalable, reliable, and easy to maintain.


🔄 Model-View-Controller (MVC)

The most famous pattern for interactive applications. It separates the internal representation of information from the ways that information is presented to and accepted from the user.

  • Model: The data and business logic (e.g., the User database).

  • View: The visual interface (e.g., the Login screen).

  • Controller: The "brain" that handles user input and updates the Model and View accordingly.

  • Best for: Web applications (Django, Ruby on Rails, ASP.NET).


🌐 Client-Server Pattern

This pattern consists of two parties: multiple Clients and a central Server. The server provides services to the clients upon request.

  • Characteristics: The server is often "stateless" (doesn't remember the client between requests) or manages a shared database.

  • Best for: Online banking, Email, and most internet-based services.


🤝 Peer-to-Peer (P2P) Pattern

Unlike Client-Server, every node (computer) in a P2P network acts as both a client and a server. There is no central authority.

  • Best for: File sharing (BitTorrent) and Blockchain/Cryptocurrency.


🏗️ Microservices Pattern

A modern pattern where an application is built as a suite of small, independent services. Each service runs its own process and communicates with others via lightweight mechanisms (usually HTTP APIs).

  • Advantage: You can update the "Payment Service" without touching the "Search Service."

  • Best for: Large-scale enterprise systems like Netflix or Amazon.


理 Broker Pattern

Used to structure distributed systems with decoupled components. A Broker component coordinates communication, such as forwarding requests and transmitting results.

  • Best for: Message queues (like RabbitMQ) or distributed object systems.


👑 Master-Slave Pattern

A "Master" component distributes work among identical "Slave" components and computes a final result from the results the slaves return.

  • Best for: Parallel processing and database replication (one Master handles writes, multiple Slaves handle reads).


📊 Comparison Table: Selecting a Pattern

Pattern

Problem it Solves

Major Trade-off

MVC

UI and Logic are messy and tangled.

Can be overkill for simple apps.

Microservices

Large apps are too slow to update.

High operational complexity and network lag.

Client-Server

Need for central data/security control.

Server can become a bottleneck/single point of failure.

Broker

Distributed components don't know where each other are.

The Broker itself adds latency to every call.


💡 Pro-Tip: Pattern vs. Style

You will often hear these used interchangeably, but remember: A Style is the organizational principle (like "Layering"), while a Pattern is a reusable solution for a specific context (like "MVC").