📜 ⬆️ ⬇️

The tale of backend, ruby ​​and rails

This is another translation of an article about rails, this time my own. The article is entertaining in nature and is intended for people not familiar with the backend and rails applications.

The original article here and the pictures are taken there.

We all know about the wonderful world of the Web. Every day we return there for answers or just to have a good time. However, not everyone knows how the world of one and zero works.
')
Well, this world is very large and not everyone saw its edge. Now it is also as great as ours, fortunately, it has no borders and it is expanding every day. New states appear there, you may have heard of some of them, such as PhP or Python, cities appear in these states (we call them applications), and residents (objects and entities) appear in cities.

Welcome to the world of Ruby


Today I will talk about one of these states, perhaps you heard about it. This state is called Ruby. Also, you may have heard about his glorious dynasty of kings “Rails” quite recently a young and strong king of Rails V ascended to the throne. You heard about this king in other countries and took an example from him, you can say that there is a king in Python Django he is very similar to the kings of the Rails dynasty.

image

Dynasty Rails has created many cities. By the way, you've probably heard of cities like Twitter, Github, or Kickstarter, they were also based in the state of Ruby.

King Rails V gloriously rules his state under the will of his father, and he ruled under the will of his father. Many have heard about this testament, perhaps you too, this testament is also called (MVC programming pattern). A little about this testament.
Each city (application) is designed according to the same architecture and in each city there are 3 main buildings:

  1. Municipality (Model)
  2. Prefecture (Controller)
  3. Area (View)

It's all. This is just a testament. But despite this, it is very important. Let's find out why.

image

We, as guests of the city, want to see all its beauty, therefore we go to the Square (View). That's right, from the square you can see the whole city, and you can also go anywhere, to any institution: a gallery, a contact center, or just meet other guests of the city. However, in order to see the pictures in the gallery or to find out the phone numbers from the contact center or simply to view information about other guests of the city, we need to look into the Prefecture (Controller), where they will tell us whether we have the right to access the requested information, and if there is access, then our request will be sent to the Municipality (Model) - a place where all information about the city, its inhabitants and guests is stored.

As for the Square (View), it is now gaining popularity that the responsibility for its construction is placed on states specializing in the construction of space. Such states have settled on the continent of "Mobile development", you probably heard about them, these are Android and IOS states.

The Prefecture (Controller) is a very useful place. It is the employees of the prefecture who tell us “ 404 - not found ” when we are trying to find an institution in the city that does not exist (for example, a shipping port in a landlocked city).

The municipality (Model) is the stronghold of each city, without it the city will be empty. There may be a square in the city, but without the Municipality you will not meet anyone on it. Here you can also find any information about its inhabitants, establishments, its guests and in general about everything in the city. The municipality is the part responsible for the archives of each city.

City life


image

Today we will visit a very young and developing city with the most famous name in the world - ' MyApp '. This city was created to unite people from all over the world.

Suppose you have already visited the square of the city MyApp and decided that it would be time to get to know someone. Heading to the Prefecture (Controller) and asking for information about all the men who are now in the city.

Let it be “GET https://my_app/men”

The administrator of the prefecture will politely reply that your request has been sent to the Municipality (Model) and successfully completed. It will take a split second and all these men will be waiting for you on the square.

image

What happened in that split second?

Let's go down to the archives of the municipality and find out. Information in archives can be stored in a different form, it can lie on one shelf, and we can be well sorted.

For example: we will put information about all the guests of the city on this shelf, and we will wrap the information about those guests who have already left in the red folder, and those who are in our city for the first time will turn in green, and we will record the information about men on blue paper, and about women on purple ...

If the architecture of our archives was developed by good specialists, then in this split second we very easily and quickly find the people we need, otherwise our split seconds can grow into a terrible few seconds. The development of such an architecture is one of the main tasks of the backend developer.

image

Suppose we entered the archive of photos and having chosen the necessary ones, we want to find out who is depicted in these photos. But what to do? The “users” archive is located at the other end of the municipality. Thanks to the correctly written code, we don’t need to go there, we can just flip the photo and the names of everyone on it will be written on the reverse side. This is how archives work.

Of course, being in the Prefecture, we do not know what is happening in the municipality, the more we do not know it in the square either. However, employees of the municipality are worried about the time of the guests of their city and their requests.

It is the backend part responsible for such things, plus the whole city should be not only convenient for its residents but also for guests. Therefore, each of its building blocks must be tested. And of course, do not forget about security. City security depends on how the prefecture is arranged. There must distinguish the villains from the guests.

Some prefectures ask for a password, some ask for a phone number, and some work with bank cards and money. Such an important part requires considerable knowledge and the same responsibility, which is why the Municipality should be given special attention when founding a city.

Let's give one more example from the life of the city. Suppose you have been in the city for a very long time and you know all its inhabitants, but unfortunately you do not know its guests, because the city is expanding and new guests come every day. Perhaps you would like every new day to know how many guests have appeared today. But you can't go to the prefecture so often and ask about new guests. It will be very tiring ... Do not worry, you do not need to do this. They will worry about the fact that every day you receive mailing pigeons anywhere in the city (and if you want it at any time of the day).

This is all a small part of what the employees of the Prefecture and the Municipality do. The task of the developer's backend is to set up work in these administrative buildings, to predict what the guests of the city might want or what might interfere with them.

The moral of the story ...


image

Summing up our fairy tale about the city MyApp, I want to note that the backend is an integral and the main part of any web application, the data with which you work in it should look good and accurate, moreover, access to them should be fast and secure, and of course the data itself must be hidden from intruders.

Apart from the main task, the developer faces issues of extensibility and flexibility of the application. You wanted to add Facebook registration to your application when there are already 1,000,000 users there or vice versa, delete it, or maybe today you need to enter a new interface language for your application, and you didn’t think about it at the design stage, under all these conditions The application should work just as it did before the drastic changes, and sometimes even better, the backend developers take care of this.

Source: https://habr.com/ru/post/316180/


All Articles