Basics of the Client-Server Model

April 2nd, 2024

ArchitectureBasics

Sometimes new­com­ers to the tech in­dus­try think that every­thing is about writ­ing code. But re­ally, there is so much that can be learned from un­der­stand­ing ba­sic pat­terns that make up soft­ware de­vel­op­ment. This ar­ti­cle is meant to ex­plore one of those: the Client-Server Model.

The truth is that there are few pat­terns that are as wide­spread in our day-to-day lives than the Client-Server Model. Because of this, un­der­stand­ing more about it can lead to a bet­ter un­der­stand­ing of the tech­nol­ogy you use on a daily ba­sis. Learning about what it is, what prin­ci­ples make it up, what are it's fun­da­men­tals, all can help you in nu­mer­ous sit­u­a­tions when work­ing with tech.

You don't have to just be a de­vel­oper to ben­e­fit from un­der­stand­ing the Client-Server Model ei­ther. Managing re­leases, de­bug­ging, bench-mark­ing per­for­mance, and even break­ing down work prop­erly in tick­ets and user sto­ries; these are all things that can im­prove with even just a ba­sic un­der­stand­ing of this build­ing block of mod­ern soft­ware de­vel­op­ment. Let's get started!

What exactly is a Client?

Before we talk about this model, let's first de­scribe what a client is. Simply put, a client is a piece of soft­ware that runs as a requester” of data. This could be a web­site you hit on your com­puter, an app on your phone, even desk­top apps that you run some­times. If you don't write code for a liv­ing, there's a pretty good chance that every piece of soft­ware you ever in­ter­act with (so long as it's con­nected to a net­work) is a client in some ca­pac­ity.

Security of a client

Clients have a few char­ac­ter­is­tics that might not be so ob­vi­ous at first glace. First, there's the fact that the writ­ten soft­ware that runs as a client runs on a com­puter that is ef­fec­tively out of the con­trol of the per­son who wrote the soft­ware. What I mean is that your phone, com­puter, smart-fridge, what­ever, is within the con­trol of the con­sumer.

This leads to the next char­ac­ter­is­tic, which is that clients are in­her­ently less se­cure. For ex­am­ple, a web­site you visit's ac­tual front-end” code (that is, all the code that dic­tates what you see) should not in­clude any­thing sen­si­tive, or pro­vide any ac­cess to any­thing sen­si­tive. The same can be said for other types of clients as well, how­ever var­i­ous ecosys­tems are dif­fer­ing lev­els of se­cure.

Your lo­cal bank's ATM is a client, but there are strict reg­u­la­tions on how its client-server re­la­tion­ship func­tion, and there­fore its more se­cure. Apple and Android phones have stan­dards with which app de­vel­op­ers have to ad­here to be­fore sub­mit­ting apps to down­load on the open mar­ket. And even web browsers have very strict rules about what client code they run can and can­not do. Which in­ci­den­tally is why you should be care­ful about click­ing around on pop­ups or down­loads that you're not sure of; these could be ways for ne­far­i­ous ac­tors to side­step some of these rules through the client.

iNoteSecurity between clients and servers is a deep topic unto itself, with lots of intricacies depending on what type of technology is being used. These examples were meant only to highlight concepts in broad strokes.

The point of these ex­am­ples is not for you to be dis­suaded in the se­cu­rity of rep­utable soft­ware com­pa­nies. Instead, its to point out that these stan­dards and reg­u­la­tions are in place to com­bat the in­her­ent fact of clients: they are by de­fault not se­cure.

So what is a server then?

Now that we know a bit more about clients, lets talk about servers. Servers are soft­ware that han­dle re­quests that the clients ask about. They then is­sue responses” for these re­quests. They are, in this pat­tern any­way, the source-of-truth when it comes to data that pow­ers ap­pli­ca­tions.

Chances are, un­less you write code in some ca­pac­ity, you won't ever in­ter­act with a server's soft­ware di­rectly. But that doesn't mean its not use­ful to un­der­stand how they work!

Security of a Server

Whereas clients are in­her­ently in­se­cure, servers are the op­po­site. They run on en­vi­ron­ments that writ­ers of the soft­ware have much more (if not full) con­trol over. They're de­signed in a way to act as the source of any­thing that might re­quire sen­si­tive logic. Because of this in­her­ent se­cu­rity, servers have ac­cess to things that clients shouldn't. Things like data­base ac­cess, pass­codes to other servers, or user in­for­ma­tion (though there's se­cu­rity con­cerns around this even on servers).

How Clients and Servers talk to each other

Clients is­sue requests”, and servers is­sue responses” to those re­quests. We've al­ready men­tioned these terms a few times, but lets go into a bit more de­tail here. A re­quest usu­ally falls into two cat­e­gories: get­ting data, or chang­ing data. While there are many tech­nolo­gies that are used to man­age re­quests and re­sponses, eas­ily the most com­mon protocol” used nowa­days is called HTTP. In fact, you might even see those four let­ters at the start of web pages you visit.

Managing Getting Data

In HTTP terms, a re­quest where a client asks for some­thing is called a GET re­quest. A GET is made when you load up your fa­vorite so­cial me­dia app, or visit a web­site and see the con­tent load up. Every sin­gle time you type in a URL, or hit a link on any de­vice, a GET re­quest is made first and fore­most. It does ex­actly what you'd think it does; a GET re­quest is sent to the server from a client, with some in­for­ma­tion about what the client is look­ing for (like a url, or other small bit of data).The server takes this re­quest, looks at what the client wants to get, finds it (either in a data­base, or gen­er­ates it some­how) and sends a re­sponse back to the client.

How Data is Updated

These same prin­ci­ples are true if the client wants to up­date some data. We men­tioned how clients are in­se­cure. However of­ten times clients is­sue re­quests around up­dat­ing data. It's up to the server to know how to han­dle those re­quests ap­pro­pri­ately. In HTTP terms, this is called ei­ther a POST or a PUT re­quest. They look fairly sim­i­lar to GET re­quests, ex­cept that the data added to the re­quest is gen­er­ally used to up­date some data in a data­base by the server.

An ex­am­ple of this is some­thing like post­ing some­thing on so­cial me­dia, or up­dat­ing your email ad­dress on a web­site. These are is­sued as re­quests from a client and sent to a server, in or­der to cre­ate or up­date data.

Scale of this relationship

In its most sim­plis­tic form, a client-server model re­la­tion­ship might only have one each of a client and server. However what is far more likely is for there to be many, many clients talk­ing to the same server. The lo­gis­tics of net­work­ing be­hind this be­come com­pli­cated fairly quickly. However it is en­tirely pos­si­ble for thou­sands of clients to have iso­lated re­quests and re­sponses go­ing back and forth to the same server in any given sec­ond. This is how you can have many peo­ple us­ing the same web­site, or lots of play­ers signed on to the same lobby.

Beyond this, there might even be mul­ti­ple copies of the same server work­ing for clients. This is of­ten how com­pa­nies try and han­dle huge peaks of us­age, where what­ever their nor­mal op­er­at­ing ca­pac­ity gets ex­ceeded in a short pe­riod of time.

In re­cent mem­ory, tick­et­ing web­sites have had this very prob­lem where their traf­fic is rel­a­tively low most of the time, and then one night mil­lions of prospec­tive con­cert go­ers log on to try and get a ticket, all within sec­onds of each other.

Wrapping Up

As a con­clu­sion to this ba­sic overview of the Client-Server Model, let's wrap up by re­view­ing what we've cov­ered. A client runs on a con­sumer's de­vice, and re­quests data. It's in­her­ently in­se­cure, as un­less there's some ex­tra se­cu­rity guar­an­teed to be on the client de­vice, the en­vi­ron­ment of the client is ef­fec­tively out of the con­trol of the soft­ware de­vel­oper.

Servers han­dle re­quests from clients, and is­sue re­sponses for the data that has ei­ther been asked for, or asked to be up­dated. And of course, you can have lots and lots of clients talk­ing to the same server, and be­yond that there might even be lots and lots of server han­dling the same task.

Hopefully this gives you some in­sight into this ar­chi­tec­ture pat­tern; one that isn't just fun­da­men­tal to soft­ware de­vel­op­ment, but to so many as­pects of our mod­ern day lives.

All Rights Reserved SelfStartDev | v1.4.0