2024-12-1516 min read

Putting Everything Together: Complete System Architecture

IT

InterviewPro Team

Senior Technical Interviewers

Putting Everything Together: Complete System Architecture

How a Real Application Works: End-to-End 🌐

Let's trace what happens when you open a website, from start to finish.

Step 1: User Opens Website 👤

You type netflix.com in your browser and press Enter.

Step 2: DNS Lookup 📖

Your browser needs to find the IP address of netflix.com.

sequenceDiagram
    participant Browser as 🌐 Your Browser
    participant DNS as 📖 DNS Server
    participant Server as 🖥️ Netflix Server
    
    Browser->>DNS: What is IP of netflix.com?
    DNS->>DNS: Look up netflix.com
    DNS->>Browser: IP is 54.230.129.145
    Browser->>Server: Connect to 54.230.129.145

What happens:

  1. 🌐 Your browser checks if it knows the IP (browser cache)
  2. 💻 If not, it asks your computer's DNS resolver
  3. 🌐 If not there, it asks your ISP's DNS server
  4. 🌍 If not there, it asks the root DNS server
  5. 🎯 Eventually, it finds Netflix's IP address

Step 3: TCP Connection 🔗

Your browser establishes a TCP connection with Netflix's server.

What happens:

  1. 📤 Your browser sends SYN (synchronize) packet
  2. 📥 Server sends SYN-ACK (synchronize-acknowledge) packet
  3. 📤 Your browser sends ACK (acknowledge) packet
  4. ✅ Connection is established

Step 4: TLS Handshake (HTTPS) 🔐

Your browser and server establish a secure connection.

What happens:

  1. 📜 Your browser asks for server's SSL certificate
  2. 📜 Server sends certificate
  3. ✅ Your browser verifies certificate
  4. 🔑 Browser and server agree on encryption keys
  5. 🔒 Secure connection established

Step 5: HTTP Request 📤

Your browser sends an HTTP request to Netflix.

Request includes:

  • 📋 Method: GET
  • 🌐 URL: /
  • 📋 Headers: User agent, cookies, etc.
  • 📦 Body: (empty for GET request)

Step 6: Load Balancer ⚖️

The request hits Netflix's load balancer.

flowchart LR
    A[📤 Your Request] --> B[⚖️ Load Balancer]
    B --> C{Which server?}
    C --> D[🖥️ Server 1]
    C --> E[🖥️ Server 2]
    C --> F[🖥️ Server 3]
    C --> G[🖥️ Server 4]
    
    style A fill:#e1f5ff
    style B fill:#ffe1e1
    style C fill:#fff4e1
    style D fill:#e1ffe1
    style E fill:#e1ffe1
    style F fill:#e1ffe1
    style G fill:#e1ffe1

What happens:

  1. ⚖️ Load balancer receives your request
  2. 📊 Load balancer checks which server is least busy
  3. 🧭 Load balancer forwards request to that server
  4. 🔧 If server is down, load balancer tries another

Step 7: CDN Check 🌍

If you're requesting static content (images, CSS, JavaScript):

flowchart LR
    A[📤 Request for image] --> B{In CDN cache?}
    B -->|Yes| C[⚡ Return from CDN]
    B -->|No| D[🖥️ Get from origin]
    D --> E[💾 Store in CDN]
    E --> F[📤 Return to user]
    C --> G[🖼️ Show image]
    F --> G

What happens:

  1. 🌍 CDN checks if content is cached near you
  2. ✅ If yes, returns immediately (fast)
  3. 🖥️ If no, fetches from origin server
  4. 💾 Stores in CDN for future requests

Step 8: Backend Server ⚙️

The request reaches Netflix's application server.

What happens:

  1. 📥 Server receives request
  2. 🔐 Server checks if you're authenticated (cookies/JWT)
  3. ⚙️ Server processes your request
  4. 📤 Server generates response

Step 9: Cache Check 💾

Server checks if data is in cache.

flowchart LR
    A[📤 Request data] --> B{In Redis cache?}
    B -->|Yes| C[⚡ Return from cache]
    B -->|No| D[🗄️ Query database]
    D --> E[💾 Store in cache]
    E --> F[📤 Return data]
    C --> G[📤 Send response]
    F --> G

What happens:

  1. 🔍 Server checks Redis cache
  2. ✅ If data is in cache, returns immediately (fast)
  3. 🗄️ If not in cache, queries database
  4. 💾 Stores result in cache for future requests

Step 10: Database Query 🗄️

If data is not in cache, server queries database.

sequenceDiagram
    participant Server as ⚙️ App Server
    participant Cache as 💾 Redis Cache
    participant DB as 🗄️ Database
    
    Server->>Cache: Check cache
    Cache-->>Server: Cache miss
    Server->>DB: Query database
    DB-->>Server: Return data
    Server->>Cache: Store in cache
    Server->>Server: Process data

What happens:

  1. 🔗 Server connects to database
  2. 📋 Server sends SQL query
  3. ⚙️ Database processes query
  4. 📤 Database returns results
  5. 💾 Server stores results in cache

Step 11: File Storage 📁

If you're requesting a video or image:

flowchart LR
    A[📤 Request video] --> B{In CDN?}
    B -->|Yes| C[⚡ Return from CDN]
    B -->|No| D[💾 Check local cache]
    D -->|Yes| E[⚡ Return from cache]
    D -->|No| F[📁 Get from S3]
    F --> G[💾 Store in cache]
    G --> H[📤 Return video]
    C --> I[▶️ Play video]
    E --> I
    H --> I

What happens:

  1. 🌍 Server checks if file is in CDN
  2. 💾 If not, checks local cache
  3. 📁 If not, fetches from AWS S3
  4. 📡 Streams file to your browser

Step 12: Authentication 🔐

If you're logged in:

sequenceDiagram
    participant Browser as 🌐 Your Browser
    participant Server as ⚙️ App Server
    participant DB as 🗄️ Database
    participant Cache as 💾 Redis
    
    Browser->>Server: Request with JWT
    Server->>Server: Verify JWT signature
    Server->>Cache: Check session
    Cache-->>Server: Session valid
    Server->>Server: User is authenticated
    Server->>Browser: Response with user data

What happens:

  1. 🔑 Server verifies JWT token signature
  2. 💾 Server checks if session is valid in Redis
  3. 👤 Server knows who you are
  4. 📤 Server returns personalized content

Step 13: Response Generation 📝

Server generates HTML response.

What happens:

  1. 👤 Server fetches your profile data
  2. 📺 Server fetches your watchlist
  3. 🎬 Server fetches recommended content
  4. 📝 Server generates HTML
  5. 📤 Server sends response

Step 14: Response Delivery 📤

Response travels back to your browser.

sequenceDiagram
    participant Server as ⚙️ App Server
    participant LB as ⚖️ Load Balancer
    participant CDN as 🌍 CDN
    participant Browser as 🌐 Your Browser
    
    Server->>LB: Send response
    LB->>CDN: Cache if static
    CDN->>Browser: Send response
    Browser->>Browser: Render page

Step 15: Browser Rendering 🖥️

Your browser renders the page.

What happens:

  1. 📄 Browser parses HTML
  2. 🎨 Browser downloads CSS and JavaScript
  3. ⚙️ Browser executes JavaScript
  4. 🖥️ Browser renders the page
  5. 👁️ You see Netflix homepage

Complete Architecture Diagram 🏗️

Here's the complete architecture of a modern application:

flowchart TD
    A[👤 User] --> B[🌐 Browser]
    B --> C[📖 DNS]
    C --> D[⚖️ Load Balancer]
    D --> E[🌍 CDN]
    D --> F[🖥️ Web Servers]
    F --> G[🚪 API Gateway]
    G --> H[🔐 Auth Service]
    G --> I[User Service]
    G --> J[Content Service]
    G --> K[Recommendation Service]
    
    H --> L[Redis Cache]
    I --> L
    J --> L
    K --> L
    
    L --> M[🗄️ Database Cluster]
    
    J --> N[📁 File Storage]
    
    K --> O[📬 Message Queue]
    O --> P[📊 Analytics Service]
    O --> Q[🔔 Notification Service]
    
    style A fill:#e1f5ff
    style B fill:#e1f5ff
    style C fill:#ffe1e1
    style D fill:#ffe1e1
    style E fill:#e1ffe1
    style F fill:#e1ffe1
    style G fill:#fff4e1
    style L fill:#ffe1e1
    style M fill:#ffe1e1
    style N fill:#e1ffe1
    style O fill:#fff4e1

Authentication Flow 🔐

Let's look at authentication in detail:

User Registration 👤

sequenceDiagram
    participant User as 👤 You
    participant API as 🚪 API Gateway
    participant Auth as 🔐 Auth Service
    participant DB as 🗄️ Database
    participant Email as 📧 Email Service
    participant Queue as 📬 Message Queue
    
    User->>API: Register email/password
    API->>Auth: Create account
    Auth->>DB: Save user
    Auth->>Queue: Send welcome email
    Queue->>Email: Send email
    Auth->>API: Return success
    API->>User: Registration successful

User Login 🔑

sequenceDiagram
    participant User as 👤 You
    participant API as 🚪 API Gateway
    participant Auth as 🔐 Auth Service
    participant Cache as 💾 Redis
    participant DB as 🗄️ Database
    
    User->>API: Login email/password
    API->>Auth: Verify credentials
    Auth->>DB: Get user
    DB-->>Auth: User data
    Auth->>Auth: Verify password hash
    Auth->>Auth: Generate JWT
    Auth->>Cache: Store session
    Auth->>API: Return JWT
    API->>User: Set JWT cookie

Logging and Monitoring 📊

Why Do We Need Logging? 🤔

💡Logging Purpose

❌ Without Logging:

  • 🚫 No way to know what's happening
  • 🐛 Can't debug issues
  • 👤 Can't track user behavior

✅ With Logging:

  • 📊 Know exactly what's happening
  • 🔧 Debug issues quickly
  • 👤 Track user behavior

Types of Logs 📋

Application Logs:

  • 👤 User actions
  • 🐛 Errors and exceptions
  • ⚡ Performance metrics

Access Logs:

  • 📡 HTTP requests
  • ⏱️ Response times
  • 📋 Status codes

Security Logs:

  • 🔐 Login attempts
  • 🚫 Failed authentications
  • ⚠️ Suspicious activity

Monitoring 📊

Monitoring means tracking the health of your system.

What to Monitor:

  • 🖥️ Server CPU, memory, disk usage
  • ⏱️ Response times
  • 📊 Error rates
  • 📈 Traffic patterns
  • 🗄️ Database performance

Tools:

  • 📈 Prometheus (metrics)
  • 📊 Grafana (visualization)
  • 📋 ELK Stack (logs)
  • 🎯 Datadog (all-in-one)

Deployment 🚀

What is Deployment?

Deployment is the process of releasing your application to production.

Deployment Strategies 🎯

Blue-Green Deployment:

  • 🔵🟢 Have two identical environments
  • 🔵 Blue = current production
  • 🟢 Green = new version
  • 🔄 Switch traffic from blue to green
  • 🔙 If issues, switch back to blue

Canary Deployment:

  • 🐦 Release to small percentage of users first
  • 👀 Monitor for issues
  • 📈 Gradually increase to all users
  • 🔙 If issues, rollback quickly

Rolling Deployment:

  • 🔄 Update servers one at a time
  • ✅ Always have some servers running
  • ⏱️ No downtime

Docker 🐳

What is Docker?

Docker is a tool to package applications with all their dependencies.

Key Concept:

  • 📦 Container = Application + Dependencies
  • 🌍 Runs the same everywhere
  • 💻 Like a lightweight virtual machine

Why Do We Need It?

💡Docker Analogy

❌ Without Docker: Like cooking in different kitchens - ingredients are in different places, ovens work differently.

✅ With Docker: Like a food truck - everything you need is in the truck, works the same everywhere.

Dockerfile Example 📝

# Base image
FROM node:18

# Set working directory
WORKDIR /app

# Copy package files
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy application code
COPY . .

# Expose port
EXPOSE 3000

# Start application
CMD ["npm", "start"]

Docker Compose 🐙

Docker Compose runs multiple containers together.

version: '3'
services:
  app:
    build: .
    ports:
      - "3000:3000"
    depends_on:
      - database
      - redis
  
  database:
    image: postgres:14
    environment:
      POSTGRES_PASSWORD: password
  
  redis:
    image: redis:7

Kubernetes (Basics) ☸️

What is Kubernetes?

Kubernetes is a system to manage containerized applications.

Key Features:

  • 📈 Automatic scaling
  • 🛡️ Self-healing
  • ⚖️ Load balancing
  • 🔄 Rollouts and rollbacks

Why Do We Need It?

💡Kubernetes Purpose

❌ Without Kubernetes: You manually manage servers, containers, scaling, and failures.

✅ With Kubernetes: Kubernetes manages everything automatically. You just tell it what you want.

Key Concepts 📚

Pod:

  • 📦 Smallest deployable unit
  • 🐳 Contains one or more containers
  • 🔗 Shares storage and network

Deployment:

  • 🎯 Manages pods
  • 🔢 Ensures desired number of pods running
  • 🔄 Handles updates and rollbacks

Service:

  • 🌐 Stable network endpoint for pods
  • ⚖️ Load balances between pods
  • 💬 Enables communication

Namespace:

  • 🏷️ Virtual cluster within a cluster
  • 📦 Separates resources
  • 🌐 Multiple environments in one cluster

Kubernetes Example ☸️

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web-app
  template:
    metadata:
      labels:
        app: web-app
    spec:
      containers:
      - name: web-app
        image: my-app:1.0
        ports:
        - containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
  name: web-app-service
spec:
  selector:
    app: web-app
  ports:
  - port: 80
    targetPort: 3000
  type: LoadBalancer

Cloud Basics (AWS) ☁️

What is Cloud Computing?

Cloud computing is renting computing resources over the internet.

Benefits:

  • 💰 No upfront hardware costs
  • 📈 Scale up or down as needed
  • 💵 Pay only for what you use
  • 🌍 Global infrastructure

AWS Services 🛠️

Compute:

  • 🖥️ EC2: Virtual servers
  • ⚡ Lambda: Serverless functions
  • 🐳 ECS: Container orchestration
  • ☸️ EKS: Kubernetes service

Storage:

  • 📁 S3: Object storage
  • 💾 EBS: Block storage
  • 📂 EFS: File storage

Database:

  • 🗄️ RDS: Managed SQL databases
  • 📊 DynamoDB: NoSQL database
  • 💾 ElastiCache: Redis/Memcached

Networking:

  • 🌐 VPC: Virtual private cloud
  • 📖 Route 53: DNS service
  • 🌍 CloudFront: CDN
  • ⚖️ Load Balancer: Load balancing

Security:

  • 🔐 IAM: Identity and access management
  • 👤 Cognito: User authentication
  • 🛡️ Shield: DDoS protection

Real-World Example: Netflix on AWS 🎬

Netflix uses AWS for:

Compute:

  • 🖥️ EC2 for application servers
  • ⚡ Lambda for serverless functions
  • 🐳 ECS for containerized services

Storage:

  • 📁 S3 for video storage
  • 💾 EBS for database storage

Database:

  • 📊 DynamoDB for user data
  • 💾 ElastiCache for caching

Networking:

  • 🌍 CloudFront for CDN
  • 📖 Route 53 for DNS
  • ⚖️ Global load balancers

Complete End-to-End Example: User Watches Netflix 🎬

Let's trace the complete journey:

sequenceDiagram
    participant User as 👤 You
    participant Browser as 🌐 Browser
    participant DNS as 📖 DNS
    participant LB as ⚖️ Load Balancer
    participant CDN as 🌍 CDN
    participant Server as ⚙️ App Server
    participant Cache as 💾 Redis
    participant DB as 🗄️ Database
    participant S3 as 📁 S3 Storage
    
    User->>Browser: Open netflix.com
    Browser->>DNS: DNS lookup
    DNS-->>Browser: IP address
    Browser->>LB: HTTPS request
    LB->>CDN: Check for static content
    CDN-->>LB: Return static files
    LB->>Server: Forward request
    Server->>Cache: Check cache
    Cache-->>Server: Cache miss
    Server->>DB: Query database
    DB-->>Server: User data
    Server->>Cache: Store in cache
    Server->>S3: Get video URL
    S3-->>Server: Video URL
    Server->>Browser: Return HTML + video URL
    Browser->>CDN: Stream video
    CDN-->>Browser: Video chunks
    Browser->>User: Play video

Interview Tips 💡

Common System Design Interview Questions 📝

How to Approach System Design Interviews 🎯

Step 1: Clarify Requirements ❓

  • 📋 Ask about functional requirements
  • ⚡ Ask about non-functional requirements
  • ⚠️ Ask about constraints
  • 📈 Ask about scale

Step 2: High-Level Design 🏗️

  • ✏️ Draw the architecture
  • 📝 Explain major components
  • 💡 Justify your choices

Step 3: Deep Dive 🔍

  • 📖 Explain each component in detail
  • 🗄️ Discuss data models
  • 📈 Discuss scaling strategies

Step 4: Bottlenecks 🚧

  • 🔍 Identify potential bottlenecks
  • 💡 Propose solutions
  • ⚖️ Discuss trade-offs

Step 5: Follow-up Questions 🔄

  • 📝 Be ready for follow-ups
  • 💬 Discuss alternatives
  • 🧠 Explain your reasoning

Key Points to Remember 🎓

💡Interview Success Tips

  • 🗣️ Communicate clearly - Explain your thought process
  • ❓ Ask questions - Don't make assumptions
  • 🎯 Start simple - Begin with basic design, then scale
  • 💡 Justify choices - Explain why you chose each technology
  • ⚖️ Discuss trade-offs - No solution is perfect
  • 🤝 Be honest - If you don't know something, say so
  • 📚 Practice - Practice with common problems
  • 😌 Stay calm - Take time to think

Summary 📚

💡Complete System Recap

  • 📖 DNS = Translates domain names to IP addresses
  • ⚖️ Load Balancer = Distributes traffic across servers
  • 🌍 CDN = Delivers content globally
  • 💾 Cache = Fast temporary storage
  • 🗄️ Database = Permanent data storage
  • 🔐 Authentication = Verifies user identity
  • 📋 Logging = Tracks system events
  • 📊 Monitoring = Tracks system health
  • 🐳 Docker = Packages applications with dependencies
  • ☸️ Kubernetes = Manages containerized applications
  • ☁️ Cloud = Provides computing resources over internet

Complete Architecture Checklist ✅

When designing a system, consider:

Functional Requirements:

  • 📋 What should the system do?
  • ✨ What features are needed?

Non-Functional Requirements:

  • 📈 Scalability
  • 🟢 Availability
  • 🛡️ Reliability
  • ⚡ Performance
  • 🔒 Security

Components:

  • ⚖️ Load balancer
  • 🖥️ Web servers
  • ⚙️ Application servers
  • 🗄️ Database
  • 💾 Cache
  • 🌍 CDN
  • 📁 File storage
  • 📬 Message queue

Deployment:

  • 🐳 Docker containers
  • ☸️ Kubernetes orchestration
  • ☁️ Cloud provider (AWS, GCP, Azure)
  • 🔄 CI/CD pipeline

Monitoring:

  • 📋 Logging
  • 📊 Metrics
  • 🔔 Alerting
  • 🏥 Health checks

Final Words 🎉

💡You're Now Ready! 🚀

You've learned:

  • 📚 System design basics
  • 🏗️ Backend building blocks
  • 📈 Scaling strategies
  • 💬 Service communication
  • 🌐 Complete architecture

You now have a solid foundation in System Design. Keep practicing with real-world problems and you'll ace your interviews!

🏷️ Topics

System DesignInterview PrepArchitectureComplete Guide