The world’s leading publication for data science, AI, and ML professionals.

System Design Basics: Client-Server Architecture

How client and server computers communicate?

.

An introduction to the Client-Server model

Photo by Liane Metzler on Unsplash
Photo by Liane Metzler on Unsplash

System design is one of the most important concepts of Software Engineering. Everybody who starts to change into a system designer from a programmer has a hard time understanding how to know about concepts regarding a system design. If you don’t know about the terminologies that are used in system design it is hard to learn about them.

This article explains an important topic of system design, the Client-Server Architecture. You may know about how servers and clients communicate here. Familiarizing yourself with the basic concepts of TCP, IP, HTTP would greatly help in designing a system.


Client-Server architecture

Client/server architecture is an important concept for system design newbies. You may think it like the foundation of how the modern internet works. Nowadays, digital devices like computers, laptops, mobile devices are everywhere. Client-server architecture is the foundation of knowing how these computers talk to one another.

What do client and server mean in the client-server model? For simplification, we may say that a client is a machine that requests some data or service. And the server returns some service or data to the client. Servers listen to the incoming network requests. So, the client-server model is a modern system designed in such a way that clients request data or service from the server, and the servers provide data or service to the client. According to the wiki,

Client–server model is a distributed application structure that partitions tasks or workloads between the providers of a resource or service, called servers, and service requesters, called clients.

In this architecture, all the requests and services are delivered over a network. It is considered as a type of distributed computing system as the components complete their job independently.

Figure: Client-Server model (Image By Author)
Figure: Client-Server model (Image By Author)

Now we may check how this architecture works with an example. For example, what happens when we type www.medium.com in our browser and press the enter button. The client device, our own laptop or computer, does not really know what the medium.com URL means. The browser needs to communicate with the server machine where the medium URL is located.

The users who type a specific URL in this system are clients. The server provides information through the internet. So, these computers can be in different parts of the world.

A specific set of rules are needed for the interaction of two systems. The most popular are the HTTP and HTTPS.

The client computers request the required information from the server. That could be in any structure of formatted data. Mainly implemented and popular formats are in XML and JSON. Server and client request and respond mostly using these formats.

Now, we are going a bit into detail into what happens after the user types a URL in a browser. How does the browser know where the server is located? The browser performs a DNS query.

DNS query:

DNS means Domain Name System. It translates the human-readable name of the domain to a machine-readable IP address. Say, for example, we may use medium.com as the website name. But the machines don’t understand this name. Computers understand IP addresses through which they find each other. For example, an IP address can be 192.0 10. 101. Just imagine how many websites we use every day. And if we have to remember these types of IP address instead of a name like Facebook, Google, Medium, etc. It would have been impossible to use the internet.

Figure: Example DNS query by browser (Image By Author)
Figure: Example DNS query by browser (Image By Author)

To put it simply, the client browser asks the DNS what the server’s IP address is. And DNS provides it to the browser.

IP Address: We may say an IP address is a unique identifier of a digital device. It is an address given to a digital machine that is connected to the public internet. So, all the digital machines have a public IP address. Data from the client reach the server by using that address. We can think of it as a mailbox for humans.

Now, after the DNS query, the client browser gets the IP address of the server. And the client sends requests to the server IP. The server sends the response to that request to the client.

The server listens for requests on specific ports. Every machine with an IP address has more or less 65K(²¹⁶) ports that it listens to. So, while communication between machines need not just IP address but also which port we want to communicate on. So, as clients, we have to specify a port number alongside the IP address to communicate with a server.

The IP address is like the mailbox of an apartment complex. And the ports are like the actual apartment number of a house. If a client uses the HTTP protocol to communicate with a server, the port number is always 80. For HTTPS, the port number is 443.

Now, how do two machine servers and clients communicate?

Network Protocol:

Say for humans if one speaks in English and another person in Spanish, it will be hard for them to understand each other. It is the same for computers; if the computers don’t have a common set of rules, how can they communicate.

Network Protocol is a set rule that both server and client-side agree to maintain while communicating. Servers and clients interact with one another using rules which are named as protocols.

Network protocols consist of various kinds of messages that are sent and received by server and client machines. These messages are sent over the network, the internet. The structure, format, and order of those messages create a network protocol.

There are a lot of protocols in computer science. We need to know about only the popular network protocols. The first one we are going to discuss is IP, which stands for Internet Protocol.

IP Protocol:

The Internet Protocol (IP) is a set of rules for addressing packets of data so that they can travel across networks and land at the correct destination machine. Data traversing through the Internet is divided into smaller units, called packets. This IP information attached to each packet helps network routers send packets to the right place.

The current internet system operates following the internet protocol. A server and client communicate and transfer data between each other using a form of packet system called an IP packet. This IP packet is how machines transfer data from one to another.

It consists of two parts: the IP header and data. The header contains information about the packet. It contains the source IP address, from where the data is sent from, the destination IP address, and where it is sent. So we may understand now that the source and destination of the machines are attached in the IP packet. This is the basic idea of how data is transferred through the internet.

Figure: IP packet transfer (Image By Author)
Figure: IP packet transfer (Image By Author)

The total size of the packet is also added in the header. And also the is versions. IP versions IPv4 and IPv6 are two well-known IP versions. Based on the version, the packet format might change. As these are well-known rules, all the computers know how to interpret them. The rest of the packet is data. The IP packet size is not that big. It is mostly ²¹⁶ bytes(65000 bytes), which is actually 0.065 megabytes. So, we can see it is pretty small in size.

We transfer a lot bigger size of data. So, one IP packet can not contain all the data we want to transfer. IP packets don’t have an order by which we can serialize the data chunks. And some data might get lost over the network. In that case, the original data may not be recoverable.

TCP:

TCP means the transmission control protocol. It is built on top of the internet protocol. It maintains an ordered way to send IP packets. TCP transmission is more reliable. It gives us a way to find if any packet is lost in the way.

If you know that some packets are corrupted while transferring through the network, you can resend those packets. It allows us to send long sized data to other machines.

IP packet has a data portion. In this portion, there will be a TCP header. This header contains information about the TCP packet of the data, like the order of packets.

Photo by Sincerely Media on Unsplash
Photo by Sincerely Media on Unsplash

The first communication using TCP connection is a handshake between server and clients. Handshake is an interaction between two machines, where the source machine sends packets to the destination machine, saying, "I want to connect with you." When the other computer responds, saying, "Ok. We can connect and communicate".

Now the source machine sends packets saying, "We are connected now." Then we have got an open TCP connection. Now that the connection is established, both the computers can send data to each other.

There is a time limit of connection; if a machine does not send data within that time period, that connection will be timed out.

While ending the TCP connection, any of the two machines can send a special message saying, "I am ending the connection." TCP is like a wrapper around IP, and it is more powerful than IP.

But TCP lacks a framework for software developers to easy to use a communication channel for client-server in the system.

HTTP:

Hypertext transfer protocol, which is built on TCP. It provides a higher-level abstraction above TCP and IP. Its main characteristic is the request-response sequence. One machine sends a request, and the other machine needs to return a response. Most modern systems rely on HTTP protocol for communication.

We don’t need to know about the TCP and IP packets while using HTTP. It takes care of the developers of these complicated low-level machine-related things. Put, Get, Post, Delete are some basic HTTP methods. HTTP provides us the opportunity to add business logic than just data transfer.

So, typing the medium.com and pressing enter sends the request of the home page of the Medium. And the medium server sends back the HTML of the home page. Now the client browser gets the HTML and renders the page for the client device.

Conclusion:

In Client-Server architecture, all services and requests are spread over the network. The system components like servers and clients both perform tasks independently from each other. It is a simple but fundamental concept. The client-server architecture is how all the computers communicate with one another. HTTP is the most common protocol for server-client communication. Its main characteristic is the request-response sequence. The client makes a request and the server provide the response. As a system designer, you have to decide which request needs to made when. And what response the server needs to provide.

Reference Link


This article is part of a series of system design for beginners. Some article links are given here:

A step by step guide on designing a system

System Design Basics: Load balancer 101

System Design of Google Auto-Suggestion Service

System Design Analysis of Google Drive

System Design Analysis of TinyURL

Getting started with System Design


Related Articles