Back-end Engineering Articles

I write and talk about backend stuff like Ruby, Ruby On Rails, Databases, Testing, Architecture / Infrastructure / System Design, Cloud, DevOps, Backgroud Jobs, some JS stuff and more...

Github:
/danielmoralesp
Twitter:
@danielmpbp

2025-02-25

Understanding The Communication Between Clients and Servers

Now that we know the basics about Ruby, Object-oriented programming, Text Editors, Git, Github, Consoles, AWS instances and much more, it’s time to explain how to connect all of these concepts. Probably this is one of the worst explained things in programming, but I’ll try to guide you through this complexities. 

The right questions to ask right now are
  • - How can I show on the Internet to my friends the code I wrote in Ruby?
  • - Where in the hell is my code going to live?
  • - What is a client and what is a server?
  • - Do I need to buy a physical server?
  • - What is a host?
  • - What happens if I don’t want to show my code 

Let me start with a story to explain all of these concepts. You are a Ruby developer, and you want to use Ruby On Rails to create an e-commerce site that sells cool t-shirts about Marvel. Of course you want to have a cool domain, like: https://www.marvel-tshirts.com to show to your friends, and promote through social media, but you don’t know how to do that. 

Let’s suppose that you have the application code ready, everything is working as a charm, but what's the next step?

Clients and Servers

First we have to understand what is a Client and what is a Server. Client is not the person who will buy your t-shirt, I mean obviously that’s your client, but in terms of computer science a Client is a web or mobile browser. When you start to navigate the internet, the first thing you do is to open Google Chrome, Firefox, Microsoft Edge or any other web browser. So, the browser is what we call the Client. 

Then when you type a search term like: “What is Ruby?” and you find a good result in this link: Ruby Programming Language (ruby-lang.org) and you hit enter, your browser is acting as a Client and www.ruby-lang.org is acting like a Server. Ruby-lang is serving and responding with a web page. Then the web browser receives the response and it can show you colors, buttons, links, text, images and so on. 




So, if you want to show the world your cool e-commerce in the link: https://www.marvel-tshirts.com you’ve to have a server that is able to respond to a request made by a web browser. But what about the domain?

Domain Names Vs IPs
In the early internet instead of hitting https://www.marvel-tshirts.com you had to share an IP address like: 192.345.678.1. When you shared that IP address people could type it in the web browser an access the given page. For instance you can use your command line to find the Facebook IP address, open your terminal an type

$ ping www.facebook.com


You can see that the IP on my case is 157.240.6.35 and if I hit that number in the browser I’ll be redirected to www.facebook.com and I can see my Facebook timeline. 

With this we can say that a Domain is a mask for the IP addresses. The domains were created to be easy to read and easy to remember by humans, but behind the scenes we are hitting a given IP address. 

As you may already know there are tons of domains and extensions you can buy, like

And so on… there are tons of providers where you can buy this domains. There are free or even cheap domains from $12 to high value domains where the asking price is even in million dollars. Just imagine how it can cost www.facebook.com or www.google.com It’s simple they are not for sale. Later we’ll be talking about domains, for now let’s suppose that we just want https://www.marvel-tshirts.com and is available to buy and we do the investment. 

Once we have the domain we can start thinking about the server

Server
This is also a confusing term, because your laptop or desktop computer can be set up as a server itself, so you already have the resources to host a server. However to configure everything right and start serving on the web is not an easy task, for that reason cloud providers like AWS, Azure, Google Cloud and others offer these kinds of services. What we have to do is to register there and reserve a space from a server, and then you need to “deploy” your Ruby/Rails code to that server. 

These providers offer a lot of different resources, but what we are interested in now is just about instances. An instance is a space on the server. This server is always running, with low downtimes, and sometimes uses it for free or for low pricings. This is a modern and convenient way to approach today’s solutions on the server side. 

Once you create and set up the server correctly, you’ll receive an IP address. Do you remember about the IP addresses we show above. Here is where you can receive one of them. Let’s assume that the IP address given to you was: 172.83.53.9

It’s fair to say that the server also needs to host your database, so you have to install PostgreSQL, MySQL or any other database Management system to keep your database there. 

How can we connect Domains and Servers?
This is a setup that will need another blog post entry, however we’ve to understand that we have to connect both of them: Domain with Server. Basically from the domain provider (where you bought the domain) you have to enter the Domain that it was given to you in the last step. Let’s assume that you bough the domain https://www.marvel-tshirts.com and you enter to NameCheap (domain provider) and you connect it with the IP 172.83.53.9

That’s all, it will need a couple of minutes to propagate over the network, but once everything is ready you can share the domain name with your friends and they will see you fancy e-commerce, and even to buy something there!

Request/Response
Each time you hit enter on a link, URL or route you will be doing something called “request”. There are many types of different requests. For instance, if you are displaying all the items in your ecommerce we say that we are doing a GET request, because we’re just reading the info hosted into the server through our database management system (where we have all our products saved), and seconds later you’ll receive a response with a success or a failure. 

Or if you are in the admin section and you want to create a new product for sale, you go through a form and fill out the right data and then save or submit the values. Here we are doing three requests: 
  • First: GET the form rendered with the field you need to fill out. Seconds later you’ll receive a response with a success or a failure.
  • Second: Once you hit save, we do a POST request, and that data is saved on the database hosted on the server. Seconds later you’ll receive a response with a success or a failure.
  • Third: You’ll be redirected to a confirmation page, which is a GET request, because we’re just reading info. Seconds later you’ll receive a response with a success or a failure.

Later you may want to update or delete a product’s info, so you can go again to a GET request to display current info, then update the data and hit enter, right there you’re doing a PATCH or PUT request. Finally suppose that you want to destroy the record, so you hit the delete button, so then you are doing a DELETE request.  

Each request send data to the server, this data can be something like this

Request
Method: GET
URL: https://www.marvel-tshirts.com
Endpoint: /all_products

Response
200 OK

Other can be:

Request:
Method: POST
URL: https://www.marvel-tshirts.com
Endpoint: /admin/products/create
Data:
  • Name: SpiderMan t-shirt
  • Size: XL
  • Price: 39.99
  • Description: Lorem ipsum… 

Response 1:
Error 401 (authentication error)
This error is because we’re not logged in as admin

We login and then we resend the same info


Response 2:
200 OK

As you can see there are a lot of things happening under the hood each time you navigate through a webpage. 


HTTP and HTTPS
What is really happening behind the scenes in each request? In the middle of the communication between the Clients (web browsers) and Servers (IP address) we have each request and each request contains data, and one of the important data is the protocol http or https

Do you remember how to access our main page? Just hitting:  https://www.marvel-tshirts.com and we’re there

Let’s inspect URLs


The HTTP protocol is just the way data is sent through the network. Is not necessary to go deeper in technical aspects, because it is not relevant at this point. Remember is just the protocol used to send data from Clients to Servers. 

The difference between HTTP and HTTPS is the security of the last one. “S” stands for “Secure” so each communication between the Clients and Server are encrypted. These encryptions are made in a secure and standard manner using an SSL issued by a Certificate Authority, so we don’t have to go deeper on that either. The right message here is: if you’re are going to be serious about the webpage you have to get an SSL certificate from a certificate authority. An easy way to do this is using Let’s encrypt. Later we’ll be writing something about it and doing this on our server. 

A port is something used by the server to understand the type of protocol. This number tends to be static. For instance, for HTTP protocolos the port used by default is 80, and for HTTPs protocols the default port is 443. 

Finally in Rails we’ll be seeing the resource path and the queries in detail. 

What does back-end mean?
At this point it is important to be clear about these terms, because here is where beginners tend to confuse. All the technologies that involve the Client (web browsers) are called front-end tools and technologies. While all the technologies that involve the Server are called back-end tools and technologies. 

For this reason front-end engineers pay more attention to design stuff, like colors, fonts, grids, usability, user experience, user interface and so on. While back-end engineers are more interested in Server stuff like: cloud services, deploy code to production, save data in databases, execute actions like Create, Read, Update or Delete resources, and so on. What’s your preference here? Honestly it depends on you! And here we’re to help you understand a bit better the back-end tools and technologies. 

I think we have enough terms to study and remember, so let’s keep this post simple, because the only thing you need at this point is a high level visual about the technologies and processes involved in the web page creation and usage. 

I hope you learned a lot

Thanks for reading!
Daniel Morales