"Building Efficient and Reproducible Web Applications: Exploring Architectural Approaches"

tfc

Hatched by tfc

Mar 29, 2024

3 min read

0

"Building Efficient and Reproducible Web Applications: Exploring Architectural Approaches"

Introduction:
Building a functional and high-performing web application requires careful consideration of both the logical and physical architecture. In this article, we will explore different architectural approaches, including the traditional server-centric MVC, the JAMstack architecture, and the emerging concept of Functional Web Apps (FWA). We will delve into their strengths, weaknesses, and how they impact scalability, reproducibility, and overall efficiency.

Logical Architecture vs. Physical Architecture:
The logical architecture of a web application refers to the structure of its source code, while the physical architecture pertains to the cloud infrastructure that runs the code. Ideally, there should be no distinction between the authored code and the code that runs. However, traditional server-centric MVC applications often face challenges in achieving this seamless integration.

In a server-centric MVC application, the logical architecture runs on multiple physical web servers, supported by load balancers and database servers. While this setup ensures high availability and fault tolerance, it can lead to inconsistencies and difficulties in bug resolution if the infrastructure definition lives separately from the code. Incorporating Infrastructure as Code (IaC) helps align the physical and logical architectures but can still sacrifice efficiency for availability.

The Rise of JAMstack Architecture:
To address the complexities of a three-tier architecture, some developers have turned to the JAMstack architecture. This modern twist on the two-tier architecture utilizes pre-rendered markup for the presentation layer and browser JavaScript for business logic. APIs act as the server in this setup.

JAMstack offers advantages such as simplicity and scalability. However, it also comes with trade-offs. Dynamic data and personalization functionalities may be delayed due to the reliance on browser client JavaScript. Another challenge lies in the reproducibility of the physical architecture, as many JAMstack implementations rely on third-party API providers. This can introduce manual errors and complicate deployment and governance processes.

The Promise of Functional Web Apps (FWA):
An alternative approach to address complexity and ensure reproducibility is the Functional Web App (FWA) architecture. FWAs are built using single-responsibility cloud functions that can dynamically render HTML-first while incorporating the full-stack, including managed databases.

In an FWA, both the presentation and application logic are modeled in the backend through cloud functions that communicate with a managed database. To ensure reproducibility, the entire app is deterministically deployed using Infrastructure as Code. This guarantees that any version of the app can be reproduced at any given time. The logical architecture of an FWA mirrors the physical architecture, eliminating many delivery and maintenance challenges.

Importing Requirements with Poetry:
When working with existing projects, importing requirements from a requirements.txt file using Poetry can be a cumbersome task. Poetry, a popular Python dependency management tool, does not support this feature directly. However, there is a workaround for projects with a handmade list of required packages:

  1. Create a requirements.txt file without version numbers and only include the main dependencies.
  2. Use the following command to import the requirements: cat requirements.txt | xargs poetry add.
  3. This command will add the packages listed in requirements.txt to your Poetry project.

Conclusion:
Efficiently building web applications requires thoughtful consideration of architectural choices. While traditional server-centric MVC applications offer high availability, they often face challenges in maintaining reproducibility. JAMstack architecture provides simplicity and scalability but falls short in terms of dynamic functionalities and infrastructure reproducibility. On the other hand, Functional Web Apps (FWAs) present a promising solution by authoring cloud functions and incorporating managed databases. By aligning the logical and physical architectures, FWAs eliminate many delivery and maintenance headaches.

In summary, when exploring architectural approaches for web app development, consider the trade-offs between availability, scalability, and reproducibility. Embracing techniques like Infrastructure as Code and leveraging tools like Poetry for dependency management can greatly enhance your development process. Remember to prioritize the specific needs and goals of your project when choosing an architecture that suits your requirements.

Sources

← Back to Library

Hatch New Ideas with Glasp AI 🐣

Glasp AI allows you to hatch new ideas based on your curated content. Let's curate and create with Glasp AI :)

Start Hatching 🐣