How the Backend Works – The client/server, 4-tier architecture

*This article is a repost, and the content dates back to November 13, 2022.

This article concerns how the Web Backend works, in particular in the client/server, 4-tier architecture.

Before we dive into the topic, let me touch on a couple of things :

1. What is frontend? What is backend?

The frontend is a part of the website that gets in direct contact with users. It is called “the client side” of the website, and it runs software that processes client-side scripting languages: HTML, CSS, and JavaScript.

Each of them has a unique role in constructing the display of websites: HTML for providing a basic structure of sites, CSS for formatting the layout, and JavaScript for displaying dynamic interactions on the sites.

On the other hand, the Backend is the other part of the website that does not interact directly with the users. It is called “the server side”, and it consists of server, application, and database. Compared to Frontend, this side runs software that processes server-side scripting languages: JavaScript, PHP, C++, Java, Python, SQL, etc.

2. What is the client/server model?

There are other ways to architect components and processes of the network over a distributed infrastructure. the client/server model, which is the focus of this article, refers to unidirectional communication from a client to a server, where the client issues a request to the server, and after processing the request the server returns a response.

Another model which draws a good comparison with the client/server model is the peer-to-peer model. In this model, each component (called “peer”) acts as a server when it processes requests from other peers and as a client when it issues requests to other peers.

Both have pros and cons, and one is chosen over the other depending on the priorities of the business.

3. What is the 4-tier architecture?

The client/server model consists of presentation, application logic, and data storage, and “tiers” refer to these conceptual layers. The most basic is 2-tier, where one is the client component and the other is on the server. In this case, the server side handles application logic, and data storage while the client side handles the presentation component.

In many cases, the application logic and the data storage are designed as separate tiers because having these in a single tier imposes scalability issues — as the number of users increases the performance of the server might dramatically decrease.

It is called 3-tier if the presentation, application logic, and data storage are all managed in a single tier, N-tier if the application logic and storage tiers are divided further into stages. This article assumes the 4-tier case, where the application logic is composed of 2 stages — the presentation logic and the application logic.

Now, let’s talk about our main subject.

Below is the basic illustration of the 4-tier architecture.

Let’s take a closer look at what’s happening in each of the steps.

① the client sends an HTTP request to the web server via the Internet

  • DNS translates domain to IP address — key point 2

② the web server receives the HTTP request via the Internet

  • Is the requested content static or dynamic? — key point 3
  • if static content, the web server processes the request, generates the response in the form of HTTP, and sends it back to the client. -> ⑦
  • if dynamic content, the web server passes the request to the app server -> ③

③ the app server receives the request

④ the app server queries the database server

  • Is the requested data found in the cache? — key point 5
  • If yes, the caching system returns the data to the database server without accessing the database
  • If no, the database server queries the database, which returns the data

⑤ the database server responds to the app server with the data

⑥ the app server receives the response and passes it back to the web server

⑦ the web server receives the response and sends it in HTTP format to the client via the Internet

⑧ the client receives the HTTP response via the Internet and displays it on the screen via the Internet

Key Points :

1. APIs to define rules about communications among software

API stands for Application Programming Interface.

An application is software with a defined function. An interface is a service contract between two applications, which defines how two applications communicate with each other using requests and responses.

REST API has become a popular approach these days.

REST API offers 4 basic methods (GET/POST/PUT/DELETE), which are also referred to as CRUD operations. Each of them is responsible for the action below:

  • POST: Create a record.
  • GET: Read a record.
  • PUT: Update a record.
  • DELETE: Delete a record.

2. DNS to translate a domain to IP address

DNS is the phonebook of the Internet.

When users type domain names such as ‘google.com’ into web browsers, DNS is responsible for finding the correct IP address for the site. Browsers then use those addresses to communicate with web servers to access website information. The term DNS stands for Domain Name System.

3. Web server to handle static content, and app server to handle dynamic content

When the page is requested to display the same content regardless of users (static), it only necessitates a web server to handle HTTP requests and responses.

However, when the page asks further, meaning the content is pulled on-the-fly and varies from user to user (dynamic), the app server is responsible for determining how the data changes for which user.

It is mostly the case that app servers have a web server as an integral part of them (diagram). This article treats these as separate tiers for illustrative purposes.

diagram :

4. Docker containers to abstract the OS on Linux

Both Virtual Machines (VMs) and docker containers are a way to enable several applications to run on the shared physical hardware.

The difference is that a docker container, unlike a VM, does not necessitate a separate OS (a VM necessitates a guest OS for each application and a hypervisor to manage virtual hardware). Instead, a docker container relies on the Linux kernel’s functionality and uses resource isolation — in other words, docker containers abstract the OS while VMs abstract the hardware.

Docker therefore should be higher in speed and efficiency, which makes Docker the preferable choice.

5. Cache allows data retrieval without access to the database

A cache is a fast data storage layer in which a subset of data is stored only temporarily. This allows subsequent requests for the same data to be faster than accessing the data’s primary storage location.

Caching can be applied to different layers of technology such as OSes, DNS, web applications, and databases.