💡 Computer Organization & Database Systems – Full
Guide (Hinglish)
(Based on Week 7 – IIT Madras BSc Degree Program Slides)
🔰 Introduction
Namaste!
Yeh document aapko step-by-step samjhayega backend system ke essential
topics jaise:
Computer Organization
Memory Hierarchy
Data Searching Techniques
SQL & NoSQL Databases
Web Application Security
Har concept ko simple Hinglish mein, examples aur diagrams (imagined) ke
sath explain kiya gaya hai. Ek secure SQL program bhi diya gaya hai for
practical understanding.
📘 1. Computer Organization (Hardware Ki Kahani)
✅ Step-by-Step:
🔹 Step 1: CPU Registers
Chhoti, bohot fast memory: 10s-100s bytes
Temporary data store karta hai CPU ke liye
Fastest access, limited size
🔹 Step 2: Cache Memory (SRAM)
L1, L2, L3 Cache = Static RAM (SRAM)
Thodi slow par zyada capacity than registers
Frequently used data yahan store hota hai
🔹 Step 3: Main Memory (DRAM)
Dynamic RAM: GBs mein hoti hai
Slow compared to cache, par large size
Active programs yahan run karte hain
🔹 Step 4: Storage (SSD, HDD)
SSD = Fast throughput, OS/apps ke liye
HDD = High capacity, videos jaise data ke liye
SSD < HDD in capacity, but > in speed
🔹 Step 5: Cold Storage
Backups ke liye (Amazon Glacier, etc.)
High latency (up to 48 hrs), low cost, high durability
📊 2. Memory Hierarchy
🔹 Step-by-Step:
🔹 Hierarchy Order:
Registers < Cache < DRAM < SSD < HDD < Cold Storage
🔹 Access Time:
Register (1 ns)
HDD (10 ms)
Comparison: Register ➜ 1,000,000x faster than HDD
🔹 Purpose:
Registers: Immediate tasks
Cache: Frequently needed data
DRAM: Running programs
SSD/HDD: File storage
Cold Storage: Rare access
🔎 3. Data Searching
🔹 Linear Search (Unsorted)
Linked list ya unsorted array
Step by step check karo
Time: O(N)
🔹 Linear Search (Sorted)
Thoda optimization possible
Still O(N)
🔹 Binary Search (Sorted Array)
Middle se start karo, half-half cut karo
Time: O(log N)
🔹 Binary Search Tree (BST)
Sorted tree, but can get unbalanced
Use AVL, Red-Black Tree for balance
Time: O(log N)
🔹 Hash Table
Index via hash function
Time: O(1)
Issue: Collisions
📂 4. Databases (SQL vs NoSQL)
🔹 SQL (Relational)
Tables with fixed columns (e.g., MySQL, PostgreSQL)
Use case: Structured data
Example: Users(name, email, password)
Indexes: B-Tree (range), Hash (exact match)
🔹 NoSQL
Document (MongoDB), Key-Value (Redis), Column (Cassandra), Graph
(Neo4J)
Flexible structure, JSON format
Great for unstructured / semi-structured data
🔹 ACID vs BASE
ACID: Reliable transactions (Banking)
BASE: Eventual consistency (Social media)
🔹 Scaling:
Scale-up: Better machine (RAM/CPU)
Scale-out: Multiple servers (Cloud)
In-memory DBs: Fast but hard to scale (Redis)
🔒 5. Web Application Security
🔹 SQL Injection:
User input bina validation = Risk
Example:
SELECT * FROM Users WHERE Name = "" or "";
Use prepared statements (parameterized queries)
🔹 Other Threats:
Buffer overflows (limit inputs)
Outdated server config (patch/update)
HTTPS zaruri hai for secure communication
📃 Simple Secure SQL Program (Python + SQLite)
import sqlite3
conn = [Link]('[Link]')
cursor = [Link]()
[Link]('''
CREATE TABLE IF NOT EXISTS Users (
id INTEGER PRIMARY KEY,
name TEXT,
password TEXT
)
''')
[Link]("INSERT INTO Users (name, password) VALUES (?, ?)",
("Alice", "pass123"))
[Link]("INSERT INTO Users (name, password) VALUES (?, ?)",
("Bob", "secure456"))
[Link]()
def login_user(name, password):
query = "SELECT * FROM Users WHERE name = ? AND password = ?"
[Link](query, (name, password))
result = [Link]()
if result:
print(f"Login successful for {name}!")
else:
print("Invalid credentials!")
login_user("Alice", "pass123") # ✅ Success
login_user("Alice", "wrong") # ❌ Fail
login_user('" or ""', '" or ""') # ❌ SQL injection blocked
[Link]()
✨ Key Points Recap
💻 Computer Organization:
Fastest: Registers, Cache
Largest: HDD, Cold Storage
📊 Memory Hierarchy:
Speed: Register > Cache > DRAM > SSD > HDD > Cold
🔎 Data Search:
Linear: O(N), Binary: O(log N), Hash: O(1)
BSTs = Structured, Hash tables = Fast lookup
📂 Databases:
SQL: Structured tables, ACID
NoSQL: Flexible, BASE
Indexing = Fast queries
🔒 Web Security:
Use prepared statements
HTTPS, updates, validation = critical
Logging and Debugging in Flask – Full Guide (Hinglish)
🔰 Introduction
Jab aap Flask web application banate ho, toh kabhi na kabhi errors aur issues
aate hi hain. In errors ko track karna, fix karna, aur samajhna bohot
important hota hai — isliye debugging aur logging use kiya jata hai.
print() statements se shuru karte hain, lekin professional apps mein
logging module use karna best practice hai.
Debugging se aap app development mein help lete ho.
Logging se aap production level pe errors track kar sakte ho.
Yeh document simple Hinglish mein Flask Logging aur Debugging ko
step-by-step samjhata hai, coding example ke sath.
🔍 Step-by-Step Explanation
✅ Step 1: print() Statement se Debugging
Sabse basic tarika debugging ka: print()
print(user_data)
Yeh directly console mein output deta hai, lekin:
Har file mein print() statements dhoondhna time-consuming hota hai
Kabhi-kabhi accidentally production code mein chhoot jaata hai
Format ya severity level ka koi control nahi hota
✅ Step 2: Flask Debug Mode
Flask ka debug=True mode development ke time pe helpful hota hai:
[Link](debug=True)
Features:
Auto-reload on code change
Error traceback browser mein dikhta hai
Interactive debugger bhi milta hai
Note: Debug mode kabhi bhi production mein use nahi karna chahiye. Risky
hota hai security ke liye, attacker Python shell open kar sakta hai.
✅ Step 3: Python Logging Module
Python ka built-in logging module powerful aur flexible hai:
import logging
[Link]("Debug message") # Dev info
[Link]("Information") # General updates
[Link]("Warning") # Attention needed
[Link]("Error") # Error occurred
[Link]("Critical error") # System down scenario
Har log message ka level hota hai
Log file mein store kar sakte ho ya console/email pe bhej sakte ho
Production monitoring ke liye zaruri hai
✅ Step 4: Flask Built-in Logger
Flask internally Python logging ka hi use karta hai. Aap [Link] directly
use kar sakte ho:
[Link]("Debugging message")
[Link]("Some info")
Flask logger console mein output deta hai (by default)
Automatically app name, timestamp, level show karta hai
✅ Step 5: Logging to File
Logs ko file mein store karne ke fayde:
Debugging easy hota hai (track kar sakte ho kya kab hua)
Dusre developers ko bhejna easy hai (file bhej do)
Production logs backup ke liye useful hain
import logging
[Link](
filename='[Link]',
level=[Link],
format='%(asctime)s:%(levelname)s:%(message)s'
)
filename: log file ka naam
level: minimum severity to log
format: time, level, message etc.
🧪 Simple Full Flask Logging Example
from flask import Flask
import logging
# Logging setup before app creation
[Link](
filename='[Link]',
level=[Link],
format='%(asctime)s:%(levelname)s:%(message)s'
)
app = Flask(__name__)
@[Link]('/')
def home():
[Link]("Home route accessed")
return "Welcome to Flask Logging Demo!"
if __name__ == '__main__':
[Link](debug=True)
🔍 Output:
Console: Agar file config nahi hai, toh output yahin dikhega
File ([Link]) example:
2025-07-18 [Link],001:DEBUG:Home route accessed
⚙️Advanced Logging – dictConfig
dictConfig se aap multiple log outputs set kar sakte ho — jaise:
Console handler
File handler
Email handler
from [Link] import dictConfig
log_config = {
'version': 1,
'formatters': {
'default': {
'format': '[%(asctime)s] %(levelname)s in %(module)s: %
(message)s',
}
},
'handlers': {
'file': {
'class': '[Link]',
'filename': '[Link]',
'formatter': 'default'
},
'stream': {
'class': '[Link]',
'formatter': 'default'
}
},
'root': {
'level': 'DEBUG',
'handlers': ['file', 'stream']
}
}
dictConfig(log_config)
Is config ke baad logs console + file dono jagah dikhenge.