Skip to main content

Command Palette

Search for a command to run...

πŸš€ DevSecOps Journey β€” Day 17

Published
β€’4 min read
πŸš€ DevSecOps Journey β€” Day 17

Building Real 3-Tier Applications with Databases (Hands-on)

Yesterday, I explored project architecture and build systems.
Today, I moved one step closer to real production systems by working on 3-Tier applications.

This learning focused on how applications connect to databases, how credentials are handled, and what a DevOps engineer must know beyond just running code.


🧱 2-Tier vs 3-Tier Architecture (Simple Explanation)

πŸ”Ή 2-Tier Architecture

  • Application layer

  • Database layer

πŸ‘‰ Suitable for small or simple systems.

πŸ”Ή 3-Tier Architecture

  • πŸ–₯ Presentation Layer – UI / Client

  • βš™οΈ Business Layer – Application logic

  • πŸ—„ Database Layer – Data storage

πŸ‘‰ Used in production environments for:

  • Better security

  • Scalability

  • Maintainability

As a DevOps engineer, understanding database setup, users, passwords, tables, and connectivity is essential.


β˜• Project #6: 3-Tier Java + MySQL Application

πŸ”§ System Preparation

sudo apt update
sudo apt upgrade -y

Ensures latest packages and security patches.


πŸ—„ Installing MySQL

sudo apt install mysql-server -y
  • Database connection details live in application.properties

  • Best practice:

    • Store DB user, password, and URL in:

      • Environment variables

      • Secret managers (Vault, AWS Secrets Manager)


▢️ MySQL Service Management

systemctl status mysql
sudo systemctl start mysql
sudo systemctl enable mysql

πŸ” Securing MySQL (Optional for Local)

sudo mysql_secure_installation

This helps with:

  • Removing anonymous users

  • Disabling remote root login

  • Removing test databases


πŸ§‘β€πŸ’» Database & User Setup

CREATE DATABASE bankappdb;

CREATE USER 'adi'@'localhost' IDENTIFIED BY 'Test@123';
ALTER USER 'adi'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Test@123';
GRANT ALL PRIVILEGES ON bankappdb.* TO 'adi'@'localhost';
FLUSH PRIVILEGES;

πŸ’‘ Switching to mysql_native_password avoids the common JDBC error:
β€œPublic Key Retrieval is not allowed”

πŸ”— GitHub – Project #6 (Java + MySQL):
πŸ‘‰ https://github.com/Jysh06/3-Tier-Java-MySQL-Database


🌐 Project #7: 3-Tier Node.js + MySQL Application

πŸ—„ Database Setup

  • MySQL installation & configuration

  • Database and table creation (users)

  • Credentials stored in db.js

CREATE DATABASE test_db;

CREATE TABLE users (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(255),
  email VARCHAR(255) UNIQUE,
  role ENUM('Admin','User')
);


πŸ–₯ Client Setup

cd client
npm install
npm run build

βš™οΈ Server Setup

cd server
npm install
npm start

πŸ“ App runs on: http://localhost:5000

This project clearly showed how backend services depend on database readiness.

πŸ”— GitHub – Project #7 (Node.js + MySQL):
πŸ‘‰ https://github.com/Jysh06/3-Tier-NodeJS-MySQL-Database


πŸ”· Project #8: 3-Tier .NET + MongoDB Application

This project introduced NoSQL databases.


βš™οΈ Installing .NET

sudo apt install dotnet-sdk-8.0 aspnetcore-runtime-8.0 -y

πŸ—„ Installing MongoDB

sudo apt install mongodb-org -y
sudo systemctl enable mongod
sudo systemctl start mongod

πŸ“‚ MongoDB Shell Usage

mongosh
show dbs
use db_name
show collections
db.Products.find().pretty()
  • DB credentials stored in appsettings.json


▢️ Running the App

dotnet restore
dotnet build
dotnet run

πŸ”— GitHub – Project #8 (.NET + MongoDB):
πŸ‘‰ https://github.com/Jysh06/3-Tier-DotNet-MongoDB


🐍 Project #9: 3-Tier Python + PostgreSQL Application


πŸ§ͺ Python Virtual Environment

sudo apt install python3.12-venv -y
python3 -m venv myenv
source myenv/bin/activate
pip install -r requirements.txt

πŸ—„ PostgreSQL Setup

sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql
sudo systemctl enable postgresql
CREATE USER root WITH PASSWORD 'root';
CREATE DATABASE my_database;
GRANT ALL PRIVILEGES ON DATABASE my_database TO root;

  • DB details stored in config.py

▢️ Running the Application

source myenv/bin/activate
python run.py

πŸ”— GitHub – Project #9 (Python + PostgreSQL):
πŸ‘‰ https://github.com/your-username/python-postgres-3tier


πŸ” DevSecOps Perspective: Credential Management

Across all projects:

  • ❌ Avoid hardcoding credentials

  • βœ… Use:

    • Environment variables

    • Secrets managers

This is a core DevSecOps principle.


βœ… Day 17 Summary

Today I worked with:

  • β˜• Java + MySQL

  • 🌐 Node.js + MySQL

  • πŸ”· .NET + MongoDB

  • 🐍 Python + PostgreSQL

And learned:

  • 2-Tier vs 3-Tier architecture

  • SQL vs NoSQL basics

  • Database installation & security

  • User, password & permission handling

  • Application–database integration

This hands-on experience strengthened my understanding of how real production systems are built and operated.