Backend Building Blocks: Understanding Server Architecture
InterviewPro Team
Senior Technical Interviewers
🎯 Build Your Backend Knowledge
This blog explains the core components that power every backend system. We'll use Instagram as a running example to make concepts easy to understand.
Backend Building Blocks: Understanding Server Architecture
What Are Backend Building Blocks? 🏗️
Backend building blocks are the core components that make a server work.
Think of building a house:
- 🏠 You need a foundation
- 🧱 You need walls
- 🚿 You need plumbing
- ⚡ You need electricity
- 🏠 You need a roof
In backend systems, we need:
- 🌐 Web servers
- ⚙️ Application servers
- 🗄️ Databases
- 💾 Caches
- 📁 File storage
- 🔐 Authentication systems
Each component has a specific job, and they work together to make your app work.
Web Server 🌐
What is a Web Server?
A web server is software that handles HTTP requests from clients.
Examples:
- 🟢 Nginx
- 🦅 Apache
- 🪟 Microsoft IIS
Why Do We Need It?
💡Web Server Purpose
❌ Without Web Server:
- 🚫 No way to handle web requests
- 👥 Users cannot access your website
- 🔒 No HTTP/HTTPS communication
✅ With Web Server:
- 📥 Handles incoming web requests
- 📄 Serves static files (HTML, CSS, images)
- 🔒 Manages SSL/HTTPS
- ⚖️ Load balances traffic
What Problem Does It Solve?
Web servers solve the problem of:
- 📥 Receiving requests from users
- 📤 Sending responses back to users
- 👥 Managing multiple users at the same time
- 🔒 Handling secure connections (HTTPS)
Real-World Example 📸
When you visit instagram.com:
- 📱 Your browser sends a request to Instagram's web server
- 🖥️ The web server receives the request
- 📤 The web server sends back the Instagram homepage
- 📱 Your browser shows you the page
sequenceDiagram
participant User as You
participant WebServer as Web Server
User->>WebServer: Request instagram.com
WebServer->>WebServer: Process request
WebServer->>User: Response (Instagram homepage)
Application Server ⚙️
What is an Application Server?
An application server runs business logic and processes data.
Examples:
- 💚 Node.js
- 🐍 Python (Django, Flask)
- ☕ Java (Spring Boot)
- 🐹 Go
- 💎 Ruby on Rails
Why Do We Need It?
💡Application Server vs Web Server
🏨 Web Server = Receptionist at a hotel
👨💼 Application Server = Hotel staff who do the actual work
The receptionist (web server) greets guests and directs them. The staff (application server) check you in, clean your room, and provide service.
What Problem Does It Solve?
Application servers solve:
- 📊 Processing user data
- 🧠 Running business logic
- 🗄️ Talking to databases
- 📧 Sending emails
- 💳 Processing payments
Real-World Example: Instagram Login 🔐
When you log into Instagram:
- 🌐 Web Server receives your login request
- ⚙️ Application Server checks if your email exists
- 🔐 Application Server verifies your password
- 🎫 Application Server creates a session for you
- ✅ Application Server sends back "Login successful"
flowchart LR
A[You enter email/password] --> B[Web Server receives request]
B --> C[Application Server checks email]
C --> D[Application Server verifies password]
D --> E[Application Server creates session]
E --> F[Response: Login successful]
Database 🗄️
What is a Database?
A database is where we store data permanently.
Examples:
- 🐬 MySQL
- 🐘 PostgreSQL
- 🍃 MongoDB
- 🔴 Redis
Why Do We Need It?
💡Why Databases Matter
❌ Without Database:
- 💾 Data is lost when server restarts
- 👤 No way to save user information
- 📸 No way to store posts, photos, comments
✅ With Database:
- 💾 Data persists even if server restarts
- 👤 User accounts are saved permanently
- 📸 Posts, photos, comments are stored safely
SQL vs NoSQL 📊
SQL Databases 📋
SQL databases store data in tables with rows and columns.
Examples: MySQL, PostgreSQL, Oracle
Best for:
- 📊 Structured data
- 🔗 Relationships between data
- 💰 Financial transactions
- 👤 User accounts
Example Table:
| id | username | email | created_at | |----|----------|-------|------------| | 1 | john_doe | john@email.com | 2024-01-15 | | 2 | jane_smith | jane@email.com | 2024-01-16 |
NoSQL Databases 📄
NoSQL databases store data in flexible formats (documents, key-value pairs).
Examples: MongoDB, Redis, Cassandra
Best for:
- 📊 Unstructured data
- ⚡ Fast reads/writes
- 📦 Large amounts of data
- 🔄 Flexible schema
Example Document:
{
"username": "john_doe",
"email": "john@email.com",
"posts": [
{"id": 1, "content": "Hello world"},
{"id": 2, "content": "My second post"}
],
"followers": ["jane_smith", "bob_wilson"]
}
💡Choosing Between SQL and NoSQL
📋 Choose SQL if:
- 📊 Your data has a fixed structure
- 🔗 You need relationships between data
- ✅ Data consistency is critical
📄 Choose NoSQL if:
- 🔄 Your data structure changes often
- ⚡ You need very fast performance
- 📦 You have huge amounts of data
Cache 💾
What is Cache?
Cache is temporary storage for frequently accessed data.
Examples:
- 🔴 Redis
- 💾 Memcached
- 🌐 Browser cache
- 🌍 CDN cache
Why Do We Need It?
💡Cache Analogy
Imagine you're studying for an exam 📚
❌ Without Cache: You look up every answer in the textbook every time.
✅ With Cache: You memorize (cache) the answers you use most often.
🧠 Memorizing is much faster than looking up every time!
What Problem Does It Solve?
Cache solves:
- 🐌 Slow database queries
- 📊 High database load
- 💻 Expensive computations
- 🌐 Slow API calls
Real-World Example: Instagram Profile 📸
When you visit someone's Instagram profile:
- 📱 First visit: Check database → Get profile data → Show profile (slow)
- 💾 Cache it: Save profile data in cache
- ⚡ Next visit: Check cache → Get profile data instantly (fast)
flowchart LR
A[User visits profile] --> B{Is data in cache?}
B -->|Yes| C[Return from cache]
B -->|No| D[Get from database]
D --> E[Save to cache]
E --> F[Return data]
C --> G[Show profile]
F --> G
CDN (Content Delivery Network) 🌍
What is a CDN?
A CDN is a network of servers around the world that store copies of your content.
Examples:
- ☁️ Cloudflare
- 📦 AWS CloudFront
- 🌐 Akamai
Why Do We Need It?
💡CDN Analogy
Imagine you have a pizza restaurant in New York 🍕
❌ Without CDN: Someone in California has to wait days for pizza delivery.
✅ With CDN: You have pizza restaurants in every city. Everyone gets pizza quickly!
What Problem Does It Solve?
CDN solves:
- 🐌 Slow content delivery
- 📊 High server load
- 😞 Poor user experience
- 🌍 Geographic distance issues
Real-World Example: Netflix 🎬
Netflix uses CDNs to stream movies:
- 📦 Netflix stores movie files on CDN servers worldwide
- 🎬 When you watch a movie, it loads from the nearest CDN server
- ⚡ This makes streaming fast for everyone, everywhere
File Storage 📁
What is File Storage?
File storage is where we keep files like images, videos, and documents.
Examples:
- 📦 AWS S3
- ☁️ Google Cloud Storage
- 🔵 Azure Blob Storage
- 💻 Local file system
Why Do We Need It?
💡File Storage Purpose
❌ Without File Storage:
- 📸 No place to store user photos
- 🎥 No place to store videos
- 💥 Files lost if server crashes
✅ With File Storage:
- 📸 Photos stored safely
- 🎥 Videos stored reliably
- 🌍 Files accessible from anywhere
Real-World Example: Instagram Photos 📸
When you upload a photo to Instagram:
- 📤 Your photo goes to file storage (AWS S3)
- 💾 Instagram saves the file URL in the database
- 👁️ When you view the photo, it loads from file storage
- 🖼️ Multiple copies are created (thumbnail, medium, full size)
Authentication 🔐
What is Authentication?
Authentication is verifying who a user is.
Examples:
- 📧 Login with email/password
- 🔑 Login with Google/Facebook
- 📱 Login with phone number
Why Do We Need It?
💡Authentication Analogy
🔐 Authentication = Showing your ID card at a bank
The bank checks your ID to make sure you are who you say you are before letting you access your account.
What Problem Does It Solve?
Authentication solves:
- 🚫 Unauthorized access
- 🛡️ Security breaches
- 👤 Identity theft
- 🔒 Data protection
Sessions 🎫
What is a Session?
A session is a way to remember a user is logged in.
How it works:
- 👤 User logs in
- 🖥️ Server creates a session
- 🎫 Server gives user a session ID
- 📤 User sends session ID with every request
- ✅ Server checks session ID to verify user
Why Do We Need It?
💡Session Purpose
Without sessions, you would have to log in every time you click a button! 😱
Sessions keep you logged in while you use the app. ✅
JWT (JSON Web Token) 🔑
What is JWT?
JWT is a token that contains user information.
Structure:
- 📋 Header: Token type and signing algorithm
- 📦 Payload: User data (user ID, email, etc.)
- 🔏 Signature: Cryptographic signature
Why Do We Need It?
💡JWT vs Sessions
🎫 Sessions: Server stores session data
🔑 JWT: Client stores token data
JWT is stateless - the server doesn't need to store session data.
Real-World Example 🔐
When you log in with JWT:
- 📧 You send email/password
- ✅ Server verifies credentials
- 🔑 Server creates JWT with your user ID
- 📤 Server sends JWT back to you
- 💾 You store JWT (in localStorage or cookie)
- 📤 You send JWT with every request
- ✅ Server verifies JWT and knows who you are
sequenceDiagram
participant User as You
participant Server as Server
User->>Server: Login with email/password
Server->>Server: Verify credentials
Server->>User: Send JWT token
User->>User: Store JWT
User->>Server: Request with JWT
Server->>Server: Verify JWT
Server->>User: Response (authenticated)
Cookies 🍪
What are Cookies?
Cookies are small pieces of data stored in your browser.
Types:
- 🎫 Session cookies: Deleted when browser closes
- 💾 Persistent cookies: Stay until expiration date
- 🔒 Secure cookies: Only sent over HTTPS
- 🛡️ HttpOnly cookies: Cannot be accessed by JavaScript
Why Do We Need It?
Cookies are used for:
- 🎫 Storing session IDs
- ⚙️ Remembering user preferences
- 📊 Tracking user behavior
- 🔐 Authentication tokens
💡Cookie Security
Always use 🔒 secure and 🛡️ HttpOnly cookies for authentication to prevent XSS attacks.
Real-World Example: Instagram Login Flow 📸
Let's put everything together with Instagram login:
Step 1: User Opens Instagram 📱
- 🌐 Web server serves the Instagram app
- 👤 User sees login screen
Step 2: User Enters Credentials 📧
- 👤 User enters email and password
- 📤 Frontend sends POST request to backend
- 🌐 Request goes through web server
Step 4: Application Server Processes ⚙️
- ⚙️ Application server receives request
- 💾 Application server checks cache for user data
- 🚫 If not in cache, application server queries database
- 🗄️ Database returns user information
- 🔐 Application server verifies password hash
- 🔑 Application server creates JWT token
- 💾 Application server saves session in cache
Step 5: Response 📤
- 🍪 Application server sends JWT token in HttpOnly cookie
- 📱 Frontend receives response
- ✅ User is logged in
Step 6: Subsequent Requests 🔄
- 👤 User browses Instagram
- 📤 Each request includes the JWT cookie
- ✅ Application server verifies JWT
- 👤 Application server knows who the user is
- 📱 User sees personalized content
flowchart TD
A[User opens Instagram] --> B[Web server serves app]
B --> C[User enters credentials]
C --> D[POST request to backend]
D --> E[Application server receives request]
E --> F{User in cache?}
F -->|Yes| G[Get from cache]
F -->|No| H[Query database]
H --> I[Database returns user data]
I --> J[Verify password]
G --> J
J --> K[Create JWT token]
K --> L[Save session in cache]
L --> M[Send JWT in cookie]
M --> N[User logged in]
N --> O[User browses app]
O --> P[Each request includes JWT]
P --> Q[Verify JWT]
Q --> R[Show personalized content]
Architecture Diagram 🏗️
Here's how all backend building blocks work together:
👤 User
↓
🌐 Web Browser
↓
🌐 Web Server (Nginx)
↓
⚙️ Application Server (Node.js/Python/Java)
↓
├─ 💾 Cache (Redis)
├─ 🗄️ Database (MySQL/PostgreSQL/MongoDB)
├─ 📁 File Storage (AWS S3)
└─ 🌍 CDN (Cloudflare)
Summary 📚
💡Backend Building Blocks Recap
- 🌐 Web Server = Handles HTTP requests (Nginx, Apache)
- ⚙️ Application Server = Runs business logic (Node.js, Python, Java)
- 🗄️ Database = Stores data permanently (SQL vs NoSQL)
- 💾 Cache = Temporary fast storage (Redis, Memcached)
- 🌍 CDN = Delivers content globally (Cloudflare, AWS CloudFront)
- 📁 File Storage = Stores files (AWS S3, Google Cloud Storage)
- 🔐 Authentication = Verifies user identity
- 🎫 Sessions = Keeps user logged in
- 🔑 JWT = Token-based authentication
- 🍪 Cookies = Stores data in browser
Common Interview Questions 📝
📝 Practice Questions
- What is the difference between a web server and application server?
- When would you use SQL vs NoSQL?
- Why do we need caching?
- What is a CDN and why is it important?
- Explain the difference between sessions and JWT.
- What are secure cookies and why are they important?
- How does authentication work in a web application?
- What happens when you upload a file to Instagram?
What's Next? 🚀
Now that you understand backend building blocks, the next blog will cover:
- Scalability
- Load balancing
- Horizontal vs vertical scaling
- Replication and sharding
- And more!
✅ You're Building Strong Foundations!
You now understand the core components of backend systems. Continue to the next blog to learn about scaling and handling millions of users.
