|
| 1 | +--- |
| 2 | +title: 3 solutions to the 3 layer problem |
| 3 | +date: '2023-08-10' |
| 4 | +icon: adjustments-question |
| 5 | +summary: What is the 3 layer problem, and how SQLPage solves it? |
| 6 | +--- |
| 7 | + |
| 8 | +# 3 solutions to the 3 layer problem |
| 9 | + |
| 10 | +> Some interesting questions emerged from the article [Repeating yourself thrice doesn't turn you into a 3X developer](https://yrashk.medium.com/repeating-yourself-thrice-doesnt-turn-you-into-a-3x-developer-a778495229c0). |
| 11 | +> This short follow-up article aims to answer them and clarify some points. |
| 12 | +
|
| 13 | +Hello all, |
| 14 | + |
| 15 | +I am Ophir Lojkine, the main contributor of the open-source application server **SQLPage**. |
| 16 | + |
| 17 | +The previous article focused on the conventional model of splitting applications into three distinct tiers: |
| 18 | + |
| 19 | +1. a graphical interface (_front-end_), |
| 20 | +2. an application server (_back-end_), |
| 21 | +3. and a database. |
| 22 | + |
| 23 | +In many projects, this results in three distinct implementations of the application’s data model: |
| 24 | + |
| 25 | +1. First, in SQL, in the form of tables, views, and relationships in the database, |
| 26 | +2. Then, in _server side_ languages such as Java, Python, or PHP, to create an API managing access to the data, and to implement the business logic of the application, |
| 27 | +3. Finally, in JavaScript or TypeScript to implement data manipulation in the user interface. |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +--- |
| 32 | + |
| 33 | +The topic of interest here is the duplication of the data model between the different layers, |
| 34 | +and the communication overhead between them. |
| 35 | +We are not talking about how the code is structured within each layer. |
| 36 | +It can follow a Model-View-Controller pattern or not, it doesn't matter. |
| 37 | + |
| 38 | +This three-layer model has several advantages: |
| 39 | +specialization of the programmers, |
| 40 | +parallelization of work, |
| 41 | +scalability, |
| 42 | +separation of concerns, |
| 43 | +and an optimal exploitation of the capacities of the infrastructure on which each layer is deployed: |
| 44 | +web browser, server application and database. |
| 45 | + |
| 46 | +Nevertheless, in large-scale projects, |
| 47 | +there is often a certain redundancy of the code between the different layers, |
| 48 | +as well as a non-negligible share of code dedicated to communication between them. |
| 49 | +For small teams and solo developers, this becomes a major drawback. |
| 50 | + |
| 51 | +## 3 solutions |
| 52 | + |
| 53 | +Fortunately, there are several approaches to solving this problem: |
| 54 | + |
| 55 | +1. For **UI-centric applications** without complicated data processing needs, |
| 56 | +you can almost completely abandon server-side development and **directly expose the data to the frontend**. |
| 57 | +Open-source tools available in this space include Supabase, PocketBase or Hasura. |
| 58 | +2. For **applications with a predominant business logic**, traditional _web frameworks_ |
| 59 | +solve this problem by centralizing frontend and database control in the backend code. |
| 60 | +A common solution involves using an ORM and templating system instead of a dedicated javascript application. |
| 61 | +Popular solutions include Django, Ruby on Rails, or Symphony. |
| 62 | +3. For simpler applications, it is possible to **avoid both backend and frontend development** |
| 63 | +by adopting a _database-first_ approach. |
| 64 | +This alternative, although less widespread, allows taking advantage of under-exploited modern capacities of relational databases. |
| 65 | +The purpose of the original article was to introduce this lesser known approach. |
| 66 | + * **SQLPage** is representative of this last category, |
| 67 | + which allows designing a complete web application _in SQL_. |
| 68 | + This leads to a loss of control over the precise visual appearance of the application, |
| 69 | + which will get a “standardized” look and feel. |
| 70 | + On the other hand, this translates into significant gains in terms of development speed, |
| 71 | + simplicity and performance. |
| 72 | + This solution is not intended to compete with traditional _frameworks_, |
| 73 | + but rather integrate earlier in the life cycle of a project. |
| 74 | + It thus makes it possible to quickly develop a data structure adapted to the application, |
| 75 | + and to iterate over it while benefiting from continuous visual feedback on the final result. |
| 76 | + Then, when the application grows, it’s easy to add a classic frontend and backend on top of the existing database, |
| 77 | + without having to start from scratch. |
| 78 | + |
| 79 | +Whichever approach is chosen in the end, |
| 80 | +a solid understanding of the conventional three-tier architecture, |
| 81 | +as well as a clear perspective on the challenges it creates and the possible solutions, |
| 82 | +facilitates decision-making and the evolution of the project with the best suited technologies. |
0 commit comments