Client-Server Architecture, simply explained
Introduction:
Last night, as I lay in bed, waiting to fall asleep, a random thought struck me. Earlier that day, I had worked on an assignment that required me to build a client/server architecture from the ground up. Although it’s relatively simple to understand, I wanted to paint a vivid picture of it through an analogy. Then, late at night, the idea occurred to me: why not write an article to help others who are interested as well? This article can be valuable and informative, even to those who aren’t deeply versed in the field of Computer Science. With the motivation for the article in mind, let’s delve into the tasty content of the topic at hand — Server/Client Architecture.
What is it?
Let’s dive right into an example. Suppose you’re curious about the famous South Korean music group, BTS, and you want to know what “BTS” stands for. You conduct an internet search, and it provides you with the answer you were seeking: BTS stands for “Bangtan Sonyeondan.” From the end user’s perspective, the entire process seems effortless. However, behind the scenes, an entire lifecycle is at play just for one of your queries.
This lifecycle is nothing other than the Client-Server Architecture. You, as the client, are requesting “data” or a “service” (in this case, the meaning of “BTS”) from service providers such as Google or Bing. You might wonder, where does Google exist? Is it intangible, like an Ouija board where you pose a question and receive an answer? If you haven’t thought about this before, now you are. These services are, in fact, hosted on servers! These servers have access to vast sources of data from all over the world, which helps them provide answers to users. Let’s say answers, without delving too much into the “valid” part.
The next question that might cross your mind is, how does this so-called “service” or “data” make its way to your mobile phone or laptop from a server? If this question hasn’t occurred to you, I recommend making a cup of coffee, taking a 5-minute stroll around the house, and activating that marvelous curiosity you carry in your mind. After all, curiosity is the catalyst for all inventions and discoveries. Getting to the point, the data or service is transmitted through a network. In this case, the internet is a vast network that connects a multitude of clients and servers around the globe, 24 hours a day.
To sum it up, the textbook definition states that the Client-Server model is a system that hosts, delivers, and manages most of the resources and services that the client requests.
At this point, you have a superficial understanding of what the Client-Server architecture is. But we won’t stop here; we must keep moving forward, as the British once said.
Why is it used?
Let’s address an essential question and return to the realm of dreams. In this dreamland, there’s no concept of clients and servers; it’s just you and your computer. You manage to gather all the data about BTS and store it on your hard drive. This consumes a significant amount of hard drive space, but now you can find answers to any BTS-related queries. Then, one day, you come across a newspaper article proclaiming Lionel Messi as the GOAT (Greatest of All Time). Living under a rock, you have no idea who this individual is. So, where do you obtain this information? You might say the internet, but remember, in dreamland, there’s no concept of a server. The internet is merely a network or a “conduit” for services and data. Your best friend may have data about Messi stored on their drive, and with a little persuasion, you acquire that data and store it on a larger hard drive because you already have data on BTS.
I hope you see where this is heading. If you wish to search or learn anything, you have to acquire and store it for the future. This is a nightmare and utterly unscalable. How many hard drives will you buy, and how many best friends do you even have? Even if you were the popular kid in class who also happens to be affluent, there is an upper limit.
Now, let’s step out of dreamland and consider a real-life scenario. You’ve just started a new company that specializes in designer shoes. Initially, you can provide paper catalogs to showcase your products and contact information to consumers. However, as your business gains traction and expands globally, the catalog-style promotion and consumption become cumbersome and impractical. You’ll likely create an e-commerce website that offers seamless transactions and scalability. This website is hosted on a SERVER, and your consumers are now CLIENTS who order products displayed on your website.
With the examples mentioned above, it becomes clear why such an architecture exists and why it’s essential. As the world progresses into the digital era, the need for such models only becomes more crucial.
How does it work?
This question was actually the main motivation behind my article. By now we all have a general understanding of what clients and servers are, but to make their workings more concrete, I’d like to introduce an analogy that helps us relate to the concept. Let’s consider the human body as an analogy. In our body, the brain controls all the organs and processes sensory information. For example, when you touch a cup of boiling water, your immediate reaction is to move your hand away. In this scenario, your hand sends a message or request to the brain, explaining the sensation and awaiting a response. The brain processes the data it receives and formulates a solution. It then sends the appropriate action back to the hand, instructing it to move away from the cup. The high-speed network in this analogy is akin to the nervous system. In the client-server model, the server functions as the ‘think tank’ of the system, much like the human brain. It uses databases and logic to process requests from the client and respond with the necessary data or services. The client can then make use of this response by displaying it to the consumers or further process the received data in any way it sees fit.
Practically, there are numerous clients for every server. For example, there are millions of Gmail users, but not a million Gmail servers. Consequently, situations may arise where multiple clients simultaneously request data or services from a particular server. The server employs various methods to handle such scenarios, such as multi-threading, multi-processing, and more, which can be somewhat more intricate.
To add to this complexity, multiple clients might wish to access the same file through the server and modify its contents at the same time. To address this, the server can utilize semaphores and file-locking mechanisms. In summary, while not all, most situations have solutions that can be implemented within the architecture to ensure a smooth flow of control.
Conclusion:
The client-server architecture is a concept that can be easily understood. Alternatives to this model, such as the Peer-to-Peer architecture, exist. Each paradigm has its advantages and disadvantages, which should be carefully considered before adoption. That’ll be all!!