Have you ever thought about how big an enterprise-scale system you want to design?
Before major software development can begin, we must choose a suitable architecture that will provide us with the required functionality and quality attributes. Therefore, we should understand the different architectures before applying them to our designs.
What are architectural patterns?
According to the wikipedia definition:
An architectural pattern is a generic, reusable solution to a common problem that occurs in a software architecture in a given context. Architectural patterns are similar to software design patterns, but have a much broader scope.
In this article, I’ll briefly explain the following 10 common architectural patterns, along with their usage, strengths and weaknesses.
-
Layered model
-
Client-server mode
-
Master/slave mode
-
Pipe-filter mode
-
The proxy pattern
-
Point-to-point mode
-
Event bus mode
-
Model-view-controller mode
-
The blackboard model
-
Interpreter mode
I. Hierarchical mode
This pattern is also known as the multi-tier architecture pattern. It can be used to construct programs that can be decomposed into groups of subtasks, each at a specific level of abstraction. Each layer provides a higher level of service to the next.
The most common in general information systems are the four layers listed below.
- Presentation Layer (also known as UI layer)
- Application layer (also known as service layer)
- Business logic Layer (also known as domain layer)
- Data Access Layer (also known as persistence layer)
Usage scenario:
- Generic desktop applications
- E-commerce Web applications
Ii. Client-server mode
This pattern consists of two parts: a server and multiple clients. A server component will serve multiple client components. Clients request services from servers, and servers provide related services for these clients. In addition, the server is constantly listening for customer requests.
Usage scenario:
- Email, file sharing, banking and other online applications
3. Master/slave mode
There are two sides to this model; Master and slave devices. The master device component assigns work in the same slave device component and calculates the final results, which are returned by the slave device.
Usage scenario:
- In database replication, the master database is considered the authoritative source and is synchronized with it
- Peripheral devices (master and slave drivers) connected to the bus in a computer system
Iv. Pipe-filter mode
This pattern can be used to construct systems that generate and process data flows. Each processing step is encapsulated in a filter component. The data to be processed is piped. These pipes can be used for buffering or for synchronization.
Usage scenario:
- The compiler. Sequential filters perform lexical analysis, parsing, semantic analysis, and code generation
- Workflow in bioinformatics
5. Agent mode
This pattern is used to construct distributed systems with decoupled components. These components can interact with each other through remote service invocations. Proxy components are responsible for coordinating communication between components.
The server publishes its capabilities (services and characteristics) to the broker. The client requests a service from the broker, which then redirects the client to the appropriate service in its registry.
Usage scenario:
- Message broker software such as Apache ActiveMQ, Apache Kafka, RabbitMQ and JBoss Messaging
Point-to-point mode
In this pattern, a single component is called a peer. A peer can serve as a client, request services from other peers, and serve as a server, providing services to other peers. Peers can act as clients or servers or both, and can change their roles dynamically over time.
Usage scenario:
- File sharing networks like Gnutella and G2
- Multimedia protocols such as P2PTV and PDTP
- Proprietary multimedia apps like Spotify
Event bus mode
This pattern mainly handles events and consists of four main components: an event source, an event listener, a channel, and an event bus. A message source publishes messages to a specific channel on the event bus. Listeners subscribe to specific channels. Listeners are notified of messages that are published to a channel to which they previously subscribed.
Usage scenario:
- Android development
- Notification service
Model-view-controller mode
This pattern, also known as the MVC pattern, divides an interactive application into three parts,
- Model: Contains core functionality and data
- Views: Display information to the user (multiple views can be defined)
- Controller: processes information entered by users
This is done to separate the internal presentation of the information from how it is presented and to accept the user’s request. It separates components and allows for effective code reuse.
Usage scenario:
- The architecture of Internet applications in major programming languages
- Web frameworks like Django and Rails
Blackboard mode
This pattern is useful for problems where there is no defined solution strategy. The blackboard pattern consists of three main components.
- Blackboard — structured global memory that contains objects from the solution space
- Knowledge sources – specialized modules and their own representations
- Control components – select, configure, and execute modules
All components have access to the blackboard. Components can generate new data objects that are added to the blackboard. Components look for specific types of data on the blackboard and find that data by matching patterns with existing knowledge sources.
Usage scenario:
- Speech recognition
- Vehicle identification and tracking
- Protein structure recognition
- Interpretation of sonar signals
X. Interpreter mode
This pattern is used to design a component that interprets a program written in a specific language. It mainly specifies how to evaluate the number of lines in a program, that is, sentences or expressions written in a particular language. The basic idea is that there is a classification for the signs of each language.
Usage scenario:
- Database query language, such as SQL
- A language used to describe communication protocols
Comparison of architectural patterns
The table below summarizes the advantages and disadvantages of each architectural pattern.
The name of the
advantages
disadvantages
Layered model
A lower layer can be used by different layers. Layers make standardization easier because we can clearly define levels. Changes can be made within a layer without affecting the other layers.
It’s not universally applicable. In some cases, certain layers may be skipped.
Client-server mode
It’s a good idea to set up a set of services that users can request.
Requests are typically processed in a separate thread on the server. Because different clients have different representations, interprocess communication can cause additional overhead.
Master/slave mode
Accuracy – delegating the execution of a service to different slave devices with different implementations.
The slave device is isolated: there is no shared state. Latency in master-slave communication can be a problem, such as in real-time systems. This pattern applies only to problems that can be decomposed.
Pipe-filter mode
Show concurrent processing. When the input and output consist of streams, the filter begins to compute when the data is received. Easily add filters and the system can be easily extended. Filters are reusable. Different pipes can be constructed by recombining a given set of filters.
Efficiency is limited by the slowest filtration process. Data transformation overhead when moving from one filter to another.
The proxy pattern
Allowing objects to be dynamically changed, added, deleted, and relocated makes developer publishing transparent.
Standardization of service descriptions is required.
Point-to-point mode
Support distributed computing. Failure handling for any given node is robust. It is highly scalable in terms of resources and computing power.
Quality of service is not guaranteed because the nodes collaborate voluntarily. Security is hard to secure. Performance depends on the number of nodes.
Event bus mode
New publishers, subscribers, and links can be added easily. Works for highly distributed applications.
Scalability can be an issue because all messages are routed through the same event bus.
Model-view-controller mode
You can easily have multiple views of the same model that can be connected and disconnected at run time.
Add complexity. This can lead to many unnecessary user action updates.
The blackboard model
It’s easy to add new applications. The structure of the extended data space is simple.
Changing the structure of the data space is very difficult because all applications are affected. Synchronization and access control may be required.
Interpreter mode
Highly dynamic behavior is possible. Provides programmatic benefits to end users. Increased flexibility because it is easy to replace an interpreter.
Since interpreted languages are generally slower than compiled languages, performance can be an issue.
Author: Vijini Mallawaarachchi
10 Common Software Architectural Patterns in a nutshell
– END –
Author: architecture improvement road, focus on software architecture research, technical learning and personal growth, pay attention and private message I reply “01”, send you a programmer growth advancement gift package, welcome to contact.
Thanks for reading!