<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rahat Naqvi</title>
    <description>The latest articles on DEV Community by Rahat Naqvi (@rahatnaqvi).</description>
    <link>https://dev.to/rahatnaqvi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3114972%2Fbc0c62c3-5d91-4c3a-8e39-2e560a4d2a68.jpeg</url>
      <title>DEV Community: Rahat Naqvi</title>
      <link>https://dev.to/rahatnaqvi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rahatnaqvi"/>
    <language>en</language>
    <item>
      <title>Building a Multi-Tier Flask App with Gunicorn, Nginx, PostgreSQL, and Systemd Using Ansible</title>
      <dc:creator>Rahat Naqvi</dc:creator>
      <pubDate>Sun, 04 May 2025 03:11:31 +0000</pubDate>
      <link>https://dev.to/rahatnaqvi/building-a-multi-tier-flask-app-with-gunicorn-nginx-postgresql-and-systemd-using-ansible-5579</link>
      <guid>https://dev.to/rahatnaqvi/building-a-multi-tier-flask-app-with-gunicorn-nginx-postgresql-and-systemd-using-ansible-5579</guid>
      <description>&lt;p&gt;In this blog, we’ll walk through how to automate the deployment of a production-grade, multi-tier Flask application using &lt;strong&gt;Ansible&lt;/strong&gt;. This deployment stack uses &lt;strong&gt;Gunicorn&lt;/strong&gt; to serve the Flask app, &lt;strong&gt;Nginx&lt;/strong&gt; as a reverse proxy, &lt;strong&gt;PostgreSQL&lt;/strong&gt; as the backend database, and &lt;strong&gt;Systemd&lt;/strong&gt; to manage services — all orchestrated through Ansible playbooks for repeatability and automation.&lt;/p&gt;

&lt;p&gt;Project Overview&lt;/p&gt;

&lt;p&gt;The core idea behind this project is to take a typical Flask app and elevate it into a real-world, scalable deployment using industry-standard components. By automating every step using Ansible, we eliminate manual setup, reduce configuration drift, and create a consistent deployment pipeline — all from scratch on a local or remote Ubuntu machine.&lt;/p&gt;

&lt;p&gt;Stack Components&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Ansible&lt;/strong&gt;: Handles orchestration and automation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flask&lt;/strong&gt;: Lightweight Python web framework&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gunicorn&lt;/strong&gt;: WSGI HTTP server for running Flask&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Nginx&lt;/strong&gt;: Acts as a reverse proxy and static file server&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PostgreSQL&lt;/strong&gt;: Relational database for application storage&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Systemd&lt;/strong&gt;: Ensures services like Gunicorn and PostgreSQL are managed and restarted if needed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Objectives&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Automate the full-stack deployment of a Flask application&lt;/li&gt;
&lt;li&gt;Use Ansible to manage packages, copy files, create users, and configure services&lt;/li&gt;
&lt;li&gt;Set up a proper separation between the app layer (Flask/Gunicorn), proxy layer (Nginx), and database (PostgreSQL)&lt;/li&gt;
&lt;li&gt;Configure &lt;code&gt;Systemd&lt;/code&gt; services to ensure auto-start and reliability&lt;/li&gt;
&lt;li&gt;Learn practical Ansible skills for infrastructure as code (IaC)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Workflow&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Clone the repository&lt;/strong&gt; and enter the &lt;code&gt;ansible&lt;/code&gt; directory.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Set up the inventory file&lt;/strong&gt; to target your localhost or remote machine.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Customize application and database settings&lt;/strong&gt; in the Ansible playbook if needed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run the playbook&lt;/strong&gt; using &lt;code&gt;ansible-playbook&lt;/code&gt;, which installs dependencies, configures Nginx, sets up the database, and deploys the app.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Access the app&lt;/strong&gt; in your browser and validate that all services are running using &lt;code&gt;systemctl&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Project Structure&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;multi-tier-flask-app/
├── app/                   &lt;span class="c"&gt;# Flask app code&lt;/span&gt;
├── ansible/
│   ├── inventory.ini      &lt;span class="c"&gt;# Target host(s)&lt;/span&gt;
│   ├── playbook.yml       &lt;span class="c"&gt;# Main Ansible automation&lt;/span&gt;
│   └── templates/         &lt;span class="c"&gt;# Jinja2 templates for configs&lt;/span&gt;
└── README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Requirements in my case&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ubuntu system with Python 3.8+ and Ansible installed&lt;/li&gt;
&lt;li&gt;Sudo access to install and manage system services&lt;/li&gt;
&lt;li&gt;Internet access for package installation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This hands-on project is perfect for DevOps beginners and intermediate users who want to solidify their understanding of Ansible, Linux services, and full-stack deployment patterns. It bridges the gap between development and operations by combining automation with real-world application deployment.&lt;/p&gt;

</description>
      <category>ansible</category>
      <category>flask</category>
      <category>nginx</category>
      <category>sqlserver</category>
    </item>
    <item>
      <title>How I Built a Flask-Celery-Redis Stack with Docker</title>
      <dc:creator>Rahat Naqvi</dc:creator>
      <pubDate>Fri, 02 May 2025 03:33:44 +0000</pubDate>
      <link>https://dev.to/rahatnaqvi/how-i-built-a-flask-celery-redis-stack-with-docker-4l97</link>
      <guid>https://dev.to/rahatnaqvi/how-i-built-a-flask-celery-redis-stack-with-docker-4l97</guid>
      <description>&lt;p&gt;I recently built a complete Flask-Celery-Redis stack using Docker and Docker Compose. This setup is widely used in real-world web applications where background task processing is essential — for example, sending emails, processing uploads, or long-running API calls.&lt;/p&gt;

&lt;p&gt;Stack Overview&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Flask&lt;/strong&gt;: Python web framework for handling HTTP requests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Celery&lt;/strong&gt;: A distributed task queue to run background jobs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Redis&lt;/strong&gt;: An in-memory data store used by Celery as a message broker.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Docker&lt;/strong&gt;: Containerized all services and orchestrated them using Docker Compose.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What I Built&lt;br&gt;
I created a small Flask app with a route that triggers a background task — a simple &lt;code&gt;sleep&lt;/code&gt; function to simulate long processing. Celery picks up the task and processes it asynchronously, and Redis handles the message queue.&lt;/p&gt;

&lt;p&gt;Folder Structure&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flask-celery-redis/
├── app/
│   ├── __init__.py
│   ├── tasks.py
│   └── views.py
├── requirements.txt
├── docker-compose.yml
├── Dockerfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What I Learned&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to decouple long-running tasks from the main app flow using Celery.&lt;/li&gt;
&lt;li&gt;How to define and connect multi-container environments using Docker Compose.&lt;/li&gt;
&lt;li&gt;How Redis serves as a reliable and fast broker for Celery.&lt;/li&gt;
&lt;li&gt;Importance of defining persistent volumes and networking in Docker Compose.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Challenges I Faced&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Task not executing?&lt;/strong&gt; I learned the hard way that Celery must run in a separate container and explicitly point to Redis in the correct Docker network format (e.g., &lt;code&gt;redis://redis:6379/0&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flask not communicating with Celery?&lt;/strong&gt; Fixed it by ensuring both services were on the same Docker Compose network.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Code &amp;amp; Demo&lt;br&gt;
I founf the full source code on GitHub:&lt;br&gt;
👉 &lt;a href="https://github.com/yourusername/docker-projects#flask-celery-redis" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Final Thoughts&lt;br&gt;
This project gave me real-world insight into scalable architecture and asynchronous processing. It’s a foundation I now use in other Dockerized applications like Django, monitoring stacks, and even DevSecOps pipelines.&lt;/p&gt;

&lt;p&gt;If you found this helpful or want to collaborate, connect with me on LinkedIn or check out more projects on my &lt;a href="https://github.com/RahatNaqvi" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
