In the past, I had a point in which I started working with a friend of mine on a personal project.
The project involved developing a Frontend app which talks with a Backend app and does database operations, calculations, communication between clients and etc…

At that time it was pretty much in my junior years and I had no single clue where to start, without even considering the manner of how to talk to it from the Frontend.

We’re going to say a lot “Frontend application” and “Backend application” so we are going to treat them as FA(Frontend application) & BA(Backend application).

So from what we can see, I didn’t knew the following:

  • What is a BA and how to write it?
  • What available frameworks are out there to build a BA that we can use? And why do we actually need it or them in the first place.
  • How does my FA talks to my BA?
  • What are servers and why we need them? Also, where do we store our BA?

In this article we’re going to dive deeply into concepts that might be overwhelming if we don’t know the basic concepts of networking.
If you think that you need a refresher or new to this world, I suggest to read another article of mine, which talks about networking and even about how to use the network stack of our PC for our personal use 🙂

Zero to Hero — How the Internet works & network programming in C/C++
Photo by Alexander Dummer: https://www.pexels.com/photo/person-using-appliance-132700/

Well after a short intro, we’re going to have a wide overview of the modern world of backend development.

For my hardworking Frontend developers who are professionals in Mobile/Web development you can skip the first chapter, because it only talks about how a FA should talk to the backend.

Hello my name is Frontend

Today in web development we have Javascript and it’s popular frameworks or libraries — Angular, React, Vue , Svelte. In mobile we have Android, iOS.
I didn’t mentioned the entire list of frameworks/platforms but I think you got the point 🙂

Each platform supports adding or has built-in libraries that allow the use of a variety of protocols to communicate with other endpoints on the web.
The most popular protocol is HTTP and we’re mostly going to talk about him.

When a FA wants any kind of resource which is located inside the BA database or any other data, it issues an HTTP request for that resource for the BA to handle.
While our request is routed along the web, we could suffer from communication problems along the way or have delays of some sort.
Because of that, we a asynchronous handling of the networking operations/requests, so when the data arrives it will give us a callback to handle the response.
The response could be an err or the data received from the BA.

It’s Worth to mention that it’s the developer job to handle networking errors and write mechanisms or fallbacks so the application could still be ongoing or at least notify about network errors.

Inside the FA, the developer has to have a URL which could be:

  • IP — A static IP address which tells the FA where the HTTP server is residing.
    This is a bad approach because IP’s often change if the server is using DHCP to allocate it’s IP or just because the IT guy might change it’s IP once in a while.
    Example: http://192.168.1.16:my-port-number/resource1/resource2?p1-name=p1-value&p2-name=p2-value&..
  • Domain URL — The popular approach which is used by many hosting services like Amazon(AWS), Google(GCP), Heroku , etc…
    Example: http://my.awesome.domain.name:my-port-number/resource1/resource2?p1-name=p1-value&p2-name=p2-value&..

Note: The “my-port-number” is needed when the port is not 80/8080 which are HTTP default port number. When the server is listening on a different port, you do need to specify it.

Inside our FA, the developer on different requests, manipulates the base URL which is from the “http” until “my-port-number/”.
He adds ‘resources’ or other strings separated by ‘/’ like in the example above.
By doing so, we know how to guide the BA what resource we need/want to do some kind of operation with it.

This pretty much sums the idea about the FA so let’s get inside the Mariana Trench.
If you don’t know what it is, it’s the deepest trench in the world 🙂

BA.. BA.. what exactly BA does?

In simple terms, because we are talking about HTTP, it has a server socket which is listening to a specified port, which is in our case the default HTTP port 80 or 8080. Off course you can override it if you want.

If you are working in C you have to handle the socket, read the data by your self, parse the data by HTTP format, handle threading for the request itself so you could also listen to new incoming requests and so on…

Because of that, it’s more popular to use frameworks or higher level/scripting languages such as Java, C#, Node.js(Javascript), Python and etc..
What they actually gives us is an abstract way of handling the incoming requests in terms of parsing, connection handling, threading, asynchronous events and more.

Let’s see some of the popular frameworks of today:

  • Java — Spring, Play, Akka.
  • Scala — Akka, Play.
  • Python — Django, Flask.
  • Node.js — Express, NestJs.
  • C# — Asp.NET, WebAPI.

Each one of these frameworks uses his own runtime libraries or any other built in add-ons which gives us a tool box that allows to maintain and handle HTTP requests in our server.

On any request, multiple things can happen from reading data inside a database, send an HTTP request to another server, long calculation(usually needs a polling mechanism which is not in scope of the article) and more..
Once the server is done handling that request, using his framework he sends a response to the client.

But how do I connect my PC to the Web?!

You don’t.
Well… if technically speaking, yes your computer is connected to the Internet, but you should not allow access to it from any BA you run on it because it’s bad practice in many ways.

Remember we talked about the IP address part?
Usually in your home computer you have a IP which came from a DHCP server, and the address could change over time.
This is why, it is preferred that we will deploy our server to the cloud.

Wait… what?! What is deploy and what is the cloud?!

Well, you can refer the internet as the cloud.
The internet as of today has communication protocols and wiring all around the world, so it could connect anyone to any wished place we want.

Today we have many companies that giving hosting services for web application and more for free and has plans which cost money, but provide better service in terms of space, computation power and more.
The popular ones are — Amazon(AWS), Google(GCP) and Microsoft(Azure).

Deploying means, we bundle up our application to an executable files instead of code, and we instruct the provider how to execute it.
In Heroku for example, you can create a file named Procfile which can describe what command to execute on the machine when it receives the bundled BA or any other event that needs to start the BA.

Example of a Procfile could be one line telling to execute a java application using a jar file which were pre-packaged.

web: java -jar target/myapp-1.0.0.jar

After deploying our BA, the provider gives us a domain URL which is manged by him, and allows us to send HTTP requests to.
Off course in every provider there are set of policies that allows to configure who can access our BA and many other features.

The huge benefit using this service, is we don’t need to worry about the machine itself in terms of hardware and also networking.
It is all being taken care of for us, so we can simply focus on the BA itself.

What kind of providers are there?

Well instead of babbling about tech companies and who has what, I would like to explain technical terms which describes cases of providers.

Usually today providers, develop services that designed differently but provided “as a Service” with a post-fix aaS to each kind.

  • IaaS (Infrastructure) — Is the case of having a provider which taking care of the machine for us and gives variety of tools to manage our BA.
    The application itself, is our own application in terms of how to handle each HTTP request, and it could be also other protocols like SMTP, SNMP and more…
  • PaaS(Platform) — Sometimes we don’t want to develop something special in our BA, and simply have someone that has access to some shared memory(database) and gives a SDK to the Web/Mobile applications, so they could talk with the PaaS and get the data for use.
    Simply, we don’t write a BA but use an SDK that connects all the clients of the app with the servers which is completely controlled by the provider SDK implementations.
    Examples: Parse(Facebook), Firebase(Google).

They are many more like these as-a-Service platforms but those are the basic ones, and I don’t want to confuse you any more 🙂

Conclusion

In today backend development we have to many frameworks, languages, scripting languages, libraries and so on… so it might be confusing to understand how everything works and especially how to connect them all together.

The goal was to give a simple and short explanation of the entire route of FA and BA communication and I hope it has been provided.

I hope you had a great time reading this piece, and if you have any more further questions I would be delighted to answer them.
Also, if you have any opinions or suggestions for improving this piece, I would like to hear 🙂

Thank you and have a great journey on your journey for knowledge! 🙂

Author

I simply love learning and improving by what I do, and by doing so strive to achieve my goals which is also help others to achieve theirs.

Write A Comment