2024-12-1514 min read

Backend Building Blocks: Understanding Server Architecture

IT

InterviewPro Team

Senior Technical Interviewers

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:

  1. 📱 Your browser sends a request to Instagram's web server
  2. 🖥️ The web server receives the request
  3. 📤 The web server sends back the Instagram homepage
  4. 📱 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:

  1. 🌐 Web Server receives your login request
  2. ⚙️ Application Server checks if your email exists
  3. 🔐 Application Server verifies your password
  4. 🎫 Application Server creates a session for you
  5. 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:

  1. 📱 First visit: Check database → Get profile data → Show profile (slow)
  2. 💾 Cache it: Save profile data in cache
  3. 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:

  1. 📦 Netflix stores movie files on CDN servers worldwide
  2. 🎬 When you watch a movie, it loads from the nearest CDN server
  3. ⚡ 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:

  1. 📤 Your photo goes to file storage (AWS S3)
  2. 💾 Instagram saves the file URL in the database
  3. 👁️ When you view the photo, it loads from file storage
  4. 🖼️ 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:

  1. 👤 User logs in
  2. 🖥️ Server creates a session
  3. 🎫 Server gives user a session ID
  4. 📤 User sends session ID with every request
  5. ✅ 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:

  1. 📧 You send email/password
  2. ✅ Server verifies credentials
  3. 🔑 Server creates JWT with your user ID
  4. 📤 Server sends JWT back to you
  5. 💾 You store JWT (in localStorage or cookie)
  6. 📤 You send JWT with every request
  7. ✅ 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 📱

  1. 🌐 Web server serves the Instagram app
  2. 👤 User sees login screen

Step 2: User Enters Credentials 📧

  1. 👤 User enters email and password
  2. 📤 Frontend sends POST request to backend
  3. 🌐 Request goes through web server

Step 4: Application Server Processes ⚙️

  1. ⚙️ Application server receives request
  2. 💾 Application server checks cache for user data
  3. 🚫 If not in cache, application server queries database
  4. 🗄️ Database returns user information
  5. 🔐 Application server verifies password hash
  6. 🔑 Application server creates JWT token
  7. 💾 Application server saves session in cache

Step 5: Response 📤

  1. 🍪 Application server sends JWT token in HttpOnly cookie
  2. 📱 Frontend receives response
  3. ✅ User is logged in

Step 6: Subsequent Requests 🔄

  1. 👤 User browses Instagram
  2. 📤 Each request includes the JWT cookie
  3. ✅ Application server verifies JWT
  4. 👤 Application server knows who the user is
  5. 📱 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 📝

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!

🏷️ Topics

BackendSystem DesignInterview PrepArchitecture