Web application design: Software Architecture 101

Tram Ho

So you’ve started the web application development journey. You have an idea, but building the right architecture is also extremely important.

In this article we will discuss the following:

  • What is software architecture?
  • Why is it important?
  • Difference between software architecture and software design
  • Software architecture patterns
  • How to determine the number of layers of an application (n-tiers)
  • Horizontal and vertical scaling … Which is suitable for the application?
  • Monolith or Microservice?
  • When to use SQL or NoSQL
  • Choose the right technology
  • How to become a software architect
  • What to do next?

The objective of this article is to present the background of web architecture and associated concepts, and how to choose the right architecture and technology when designing applications. After this article, you will no longer dream when designing applications from the beginning.

I. What is software architecture?

The software architecture of the system describes the main components, their relationships, and how they interact with each other.

It is seen as a detailed blueprint, providing a model for system management and setting and coordinating communication between components.

Here are a few key points:

  • Architecture defines a solution to meet technical and operational requirements. With the overall goal of performance and security.
  • Architectural design is a combination of the needs of the organization as well as the needs of the development team. Each decision should be considered to affect the quality and performance.

One of my favorite definitions of software architecture is from Ralph Johnson, author of Design Patterns: Elements of Reusable Object-Oriented Software. He said:

It is a decision that you want to make right from the start of the project.

II. Why is software architecture important?

The key to success in building anything is doing the right thing. Whether it’s building a house or making a pizza, if the original part doesn’t work, then we have to start over, there’s no other way.

So does building a web application. Architecture is fundamental and must be thought carefully to avoid major design changes and refactor code later. Many engineers will say that you don’t want to have to redesign. It will erode time like a black hole, slow down realease days to a month, even wasting manpower and finance.

Depending on the stage in the development process, we get stuck due to decisions in the initial design phase. Therefore, before embarking on the code, it is best to do the right base.

Although software development is an iterative and improved process, it is not always necessary to make everything perfect from the start. However, that is not the reason for the problematic architectural design.

III. Difference between software architecture and software design

People often confuse software design and architecture so we will clarify.

Software architecture is used to determine the framework and high-level components of the system, and how they work together. For example, do you need a serverless architecture that splits the application into two components: BaaS (backend-as-a-service) and FaaS (functions-as-a-service), or you need a microservice architecture that functions divided into separate modules.

Choosing an architecture will determine how you handle performance, fault tolerance, and scalability.

Software design is responsible at the level of code design, how the module is coded, the class scope, and the purpose of the function. When used correctly, developers will work more effectively, avoiding reinventing the wheel. They also provide a common language to conceptualize repetitive problems and solutions when encountered.

IV. Software architecture patterns

Client-server

The architecture works based on the request-response model . The client sends the request to the server to retrieve information and the server to return data.

Every website you visit, like blogs, Facebook, and Twitter, is built on a client-server architecture.

Peer-to-peer

A P2P network is a network where each computer is viewed as a node that communicates with each other without a centralized server. The absence of a centralized server eliminates the single point of failure problem . All computers in the network have equal rights. Each node plays the seeder role and leecher at the same time, so even if some computers ( nodes ) do not work, the system will continue running.

P2P is the foundation of blockchain technology.

Model-View-Controller (MVC)

The MVC architecture is a software architectural pattern in which the application’s logic is divided into 3 components based on functionality. The components are called: Models – represent how data is stored in the database, Views – display information for users, Controllers – components act as an interface between the model and the view.

MVC architecture is used in desktop software as well as web and mobile.

Microservices

In microservices architecture, the different functions are divided into separate modules, linked together to form a large service .

This unique architecture makes it easier to maintain, develop features, test and deploy than monolithic architectures.

Event driven

Event-driven architecture (event-driven) is quite popular in application development today.

They are capable of handling a large number of concurrent connections with minimal resource consumption. Modern applications need a completely asynchronous model for scaling.

Layered

This pattern is used to structure programs that can be separated into small groups, each with a different level of abstraction. Each layer provides a higher level of service to the layer.

Here are some common layers:

  • Presentation layer
  • Application layer
  • Business logic layer
  • Data access layer

Hexagonal

This architecture consists of 3 components:

  • Ports
  • Adapters
  • Domain

The focus of this architecture is to make the various components of the application independent, loose & testable.

This pattern takes the domain as the core, which is the business logic. The outer layers are Ports and Adapters . Ports act as an API, as well as an interface. All inputs will have to go through the interface.

V. How to determine the tier number of the application

Single-layer application

Pros:

  • There is no lag
  • Data transfer is fast
  • Data does not need to be transmitted over the network, ensuring safety

Cons:

  • Difficult to design new functions
  • Testing must be extremely thorough
  • Easy to reverse engineered

2-layer application

Pros:

  • The database server and the business logic are close together (physically), so the performance will be high

Cons:

  • Because the client holds most of the application’s logic, the problem arises when it is necessary to control the version of the application and distribute new applications.
  • Lack of extensibility because it only supports a small number of users, performance decreases when there are many user requests
  • Hard to reuse

3-layer application

Pros:

  • Place the business logic on a centralized server so data is secure
  • Scalable system is there

Cons:

  • It takes more effort when making a 3-layer application because the number of contacts increases

N class application

Pros:

  • All advantages of 3-layer model
  • Perfomance increases

Cons:

  • Due to the composition of the layers, the more layers, the more difficult to install and maintain

summary

  • You should choose a 1-layer model if you do not want the network to have latency
  • Choose a 2-layer model when you need to minimize network latency and need more application control
  • Choose a 3-layer model when you need to control application code / logic and want it to be more secure
  • Select the N-class model when scaling and processing lots of data

BECAUSE. Horizontal or vertical scaling …

If the application is just a utility or a tool with a stable amount of expected traffic, this is not a problem, such as an organization’s internal tool. Why must be stored in a distributed environment? As a server is enough to manage traffic, you should scale vertical when you know the traffic will not spike.

If your app is an app like social networking, fitness, etc., the traffic may increase exponentially in the near future. In this case, the availability as well as the ability to scale horizontally are very important.

It is best to build and deploy to the cloud and always have a mindset of horizontal scaling from the beginning.

VII. Monolith or Microservice?

When to use monolithic architecture

The monolithic application is suitable for simple requirements, the application only handles a limited amount of traffic such as the organization’s internal tax calculation tool.

These are cases where business is determined that traffic will not grow exponentially

There are also cases in which the development team decides to start with monolithic architecture and then extend to a distributed microservice architecture. This helps them handle the complexity of the application step by step.

When to use microservice architecture

The microservice architecture is suitable for complex applications with heavy traffic.

Social networking applications have many different components such as messaging, real-time chat, LIVE video streaming, image upload, like, share …

In this case, I suggest developing each component separately, each of which is a separate codebase.

We have 3 approaches:

  • Select monolithic architecture
  • Select the microservice architecture
  • Start with monolithic and change to microserver later

When to use NoSQL or SQL?

When to use SQL database?

If you are writing a stock trading, banking or financial application or need to store a lot of relationships, such as social networking applications like Facebook, then you should choose a relational database, the reason:

Transactions and Data Consistency

If the software needs to work with money and numbers, it needs transactions , ACID, data consistency. And relational databases are good for that.

Storing Relationships If a data has many relationships, nothing is better than a relational database.

Common relational database

  • MySQL
  • Microsoft SQL Server
  • PostgreSQL
  • MariaDB

When to choose NoSQL

Here are a few reasons

Handling read / write a lot

No need to scale quickly, should use NoSQL, such as when there is a large amount of read / write behavior on the website and need to process large data, NoSQL will perfectly respond to such scenarios.

Data analysis

NoSQL databases are also suitable for data analysis.

Popular NoSQL databases:

  • MongoDB
  • Redis
  • Cassandra
  • HBASE

VIII. Choose the right technology

Real-time data interaction

If the application needs:

  • Real-time interaction with backend, such as mesasging, audio-video streamming
  • persistent connection between client and server, and a non-blocking technology in the back-end.

Peer-to-peer application

If you intend to build a P2P web application, a P2P distributed search engine, or a P2P Live TV radio service, similar to Microsoft’s LiveStation, then you will want to consider JavaScript, protocols like DAT, IPFS. Learn FreedomJS, a framwork for building P2P web applications that work on modern web browsers.

CRUD-based application

If it’s simply CRUD, then some of the following technologies are sufficient: Spring MVC, Python Django, Ruby on Rails, PHP Laravel, ASP .NET MVC.

Simple application

If you intend to write a simple application such as a blog, online form, integrated with social media embedded with IFrame, then you can choose PHP.

You can also consider other framwork like Spring boot, Ruby on Rails. But hosting PHP will cost much less than hosting of other technologies.

Application uses more CPU and memory

Do you need to run heavy computing applications that consume CPU and memory such as large data processing and parallel processing?

Technology The technology commonly used to write scalable, distributed systems is C ++. It has features that support low-level memory manipulation, providing more memory control for developers when writing distributed systems. The majority of cryptocurrencies are written in this language.

Rust is a programming language similar to C ++. Java, Scala and Erlang are also a good choice. Most large scale systems are written in Java.

Go is Google’s programming language for writing applications for multi-core machines and processing large amounts of data.

Julia is a dynamic programming language built for high performance numerical analysis and analysis.

IX. Become a software architect?

If things look interesting here, then you seem to want to become a software architect. But where to start? Most software engineers work for a few years before undertaking architectural design.

One of the ways to get used to software architecture is to design your own web application, which will force you to think about every aspect of the application, from load balacing, messge queue, streaming processing, caching, etc. You start to understand which part of these concepts are in the application, then you are on your way to becoming a software architect.

You also need to constantly learn and absorb the latest technology trends, starting with learning a few more programming languages.

X. Summary

Although talking a lot in the article, but we have not gone into detail, has not covered REST APIs.t to explore REST APIs, high availability, and CAP theorem.

You can learn about different architectural styles such as client-server, peer-to-peer decentralized architecture, microservice, the basic principles of data flow in a web application, and various related classes. how, concepts like scalability, high availability and more.

In addition, you will have to experience techniques that select the right architecture and technology stack to use, and understand how the trade-off technology interrelates.

Reference: https://hackernoon.com/how-to-design-a-web-application-software-architecture-101-eecy36o5

Share the news now

Source : Viblo