Tale of the 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 is here and the pictures are taken there.

    We all know about the beautiful world of the web. Every day we return there for answers or just to have a good time. However, not everyone knows how this world of unity and zero is arranged.

    Well, this world is very large and not everyone has seen its edge. Now it is as great as ours, fortunately, there are no boundaries in it and every day it expands. New states appear there, maybe you heard about some of them, for example 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 have heard about it. This state is called Ruby. Also, perhaps you heard about his glorious dynasty of kings “Rails” recently in the state the young and strong king Rails V ascended to the throne. They heard about this king in other countries and took an example from him. Django, he is very similar to the kings of the Rails dynasty.

    image

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

    King Rails V gloriously rules his state according to the will of his father, and he ruled on the will of his father. Many have heard of this will, perhaps you too, this will is also called (MVC programming pattern). A bit about this will.
    Each city (application) is developed 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. Such a will. 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, so we go to the Square (View). That's right, from the square you can see the whole city, and also you can get anywhere, to any institution: a gallery, a contact center or just get to know other guests of the city. However, to look at the pictures in the gallery or to find out phone numbers from the contact center or just to view information about other guests of the city, we need to look into the Prefecture (Controller), there they will tell us if 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), now it is gaining popularity responsibility for its construction to lay on the state specializing in the construction of squares. Such states have settled on the "Mobile Development" continent, you've probably heard about them, these are Android and IOS states.

    Prefecture (Controller) is a very useful place. It is the prefecture’s employees who tell us “ 404 - not found ” when we try to find an institution in the city that does not exist (for example, a shipping port in a city that does not have access to the sea).

    The municipality (Model) is the stronghold of each city, without it the city will be empty. There may be a square in a city, but without the Municipality you will not meet anyone. Here you can also find any information about its residents, institutions, about its guests and in general about everything that is 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 MyApp Square and decided that it’s time to get to know someone. Head to the Prefecture (Controller) and request information about all the men who are now in the city.

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

    Administrator of the Prefecture, politely answer you that your request was sent to the Municipality (Model) and successfully completed. A split second will pass and all these men will be waiting for you in the square.

    image

    What happened in this split second?

    Let's go down to the municipality archives 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 that are the first time in our city, we will wrap it in green, and we will write down information about men on blue paper, but on women on purple ...

    If the architecture of our archives was developed by good specialists, then in this split second we will very quickly and easily find the people we need, otherwise our split second 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 went into the archive of photographs and having chosen the ones we want to know who is depicted in these photographs. 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 who is depicted on it will be written on the back. This is how archives work.

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

    It is the backend that is responsible for such things, plus the whole city should be not only convenient for its residents but also for guests. Therefore, each of its bricks should be tested. And of course, do not forget about security. The security of the city depends on how the prefecture works. They should distinguish villains from guests.

    Some prefectures ask for a password, some have 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 establishing the city.

    We give one more example from the life of the city. Suppose you have been in the city for a very long time and 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 to know how many guests appeared today every new day. But you cannot go to the prefecture so often and ask about the arrival of new guests. It will be very tiring ... Do not worry, you do not need to do this. They will make sure that every day you receive carrier pigeons anywhere in the city (and if you want, at any time of the day).

    This is all a small part of what the employees of the Prefecture and the Municipality are doing. The task of the developer’s backend is to set up work in these administrative buildings, to predict what city guests may want or what might hinder them.

    The moral of this story ...


    image

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

    Apart from the main task, the developer is faced with the 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, or vice versa, delete it, or maybe today you need to introduce a new interface language for your application, and you did not think about it at the design stage, under all these conditions the application should work the same way it worked before the drastic changes, and sometimes even better, that's what the backend developers take care of.

    Only registered users can participate in the survey. Please come in.

    Still write in this style?

    • 38.6% + 95
    • 61.3% - 151

    Also popular now: