The Art of System Design: A Journey with Jinja, Flask, and More!

The Art of System Design: A Journey with Jinja, Flask, and More!

How do you truly master system design?

The answer lies in getting your hands dirty. While someone can introduce you to various architectures and technologies, the real learning happens when you dive in, try things out, encounter problems, and figure out how to debug them.

Last week, I embarked on a new learning adventure with the Jinja framework. This powerful tool allows the creation of reusable HTML templates and supports conditional elements and values.Similarly like adding library in C++, it allow to add HTML into another HTML file. Think of it as the Python counterpart to what EJS does for JavaScript if you already working on front-end with Javascript. What's more, it seamlessly integrates with Flask, a fantastic Python web framework for backend development.

So, what did I create with this newfound knowledge?

Introducing a Highly Available Business Articles website

This website dynamically showcases business articles from the last 24 hours, sourced from different media houses and aggregated in a database (in this case used newsdata.ai's database through REST API). Let's delve into the technological marvels that power this system:

Technologies Explored:

  1. Jinja Framework: Crafting reusable and condition-based HTML templates.

Jinja allow to use different element such as navigation bar to reuse into different webpages and also allow to have conditional element in HTML

<!DOCTYPE html>
<html lang="en">
    <!-- Header-->
    {% include 'header.html' %}
    <body>
        <!-- Navigation-->
        {% include 'navbar.html' %}        

  • Flask: Seamlessly integrating the backend to create a robust web application.

Flask architecture to handle multiple request

Flask's architecture is inherently designed to handle multiple requests on a single server efficiently. The WSGI standard, which Flask adheres to, allows for concurrent handling of requests. Flask itself doesn't handle concurrency but relies on the underlying server or a reverse proxy (such as Nginx or Apache) to manage multiple simultaneous connections.

When deployed in a production environment, it's common to use a production-ready WSGI server like Gunicorn or uWSGI, which can handle multiple requests concurrently. These servers manage the execution of Flask application instances in separate processes or threads, ensuring efficient handling of multiple requests simultaneously.

Flask's simplicity, combined with its ability to integrate seamlessly with other components and libraries, makes it a popular choice for building web applications that can handle a substantial number of concurrent requests.

  • Caching Mechanism: Utilizing a cache to store parsed articles, reducing database read operations.
  • Dedicated Service (micro-service ): Updating the cache and invalidating articles older than a day, scheduled every hour.

This application is read heavy, and not necessary that article always latest but should be present always. Considering this thing in mind cache design to fetch articles every hour through dedicated micro-srvice and elimination policy is base on time.

Users can also query articles based on specific words, enhancing the overall user experience.

Checkout short video ob website here.

The learning doesn't stop here; consider extending this project by incorporating Kafka for event logging, creating statistics, and storing logs for an extended period. These logs can prove invaluable for debugging, especially if stored in another database for an extended time frame (e.g., six months).

The journey into system design is not just about mastering specific technologies but understanding how they interplay in creating a seamless and efficient system.

Curious to explore the code and details? Check out the GitHub repository for an in-depth look into the project.

要查看或添加评论,请登录

Manish Joshi的更多文章

社区洞察

其他会员也浏览了