Server Types
Servers are the backend systems that process requests and serve responses.
Server Ecosystem
Servers
├── Web Servers
│ ├── Static file servers (Nginx, Apache)
│ ├── Application servers (Node.js, Tomcat)
│ └── API servers (Express, Spring Boot)
├── Database Servers
│ ├── SQL (PostgreSQL, MySQL)
│ ├── NoSQL (MongoDB, Redis)
│ └── Data warehouses (Redshift, BigQuery)
├── Cache Servers
│ ├── Redis
│ ├── Memcached
│ └── Application-level cache
├── Message Servers
│ ├── Kafka
│ ├── RabbitMQ
│ └── SQS
└── Proxy Servers
├── Reverse proxy (Nginx)
├── Load balancer (HAProxy)
└── API gateway (Kong)
Server Comparison
| Server Type | Purpose | Example |
|---|---|---|
| Web Server | Serve static files, route requests | Nginx, Apache |
| Application Server | Execute business logic | Node.js, Django |
| Database Server | Store and query data | PostgreSQL, MongoDB |
| Cache Server | Store temporary data | Redis, Memcached |
| Message Server | Async communication | Kafka, RabbitMQ |
Server Selection
Web Framework Selection:
Language Framework Use Case
─────────────────────────────────────
JavaScript Express APIs, microservices
Python Django Full-stack, ML
Java Spring Boot Enterprise, microservices
Go Gin High-performance
Rust Actix Maximum performance
Ruby Rails Rapid development
Request Handling
Understanding how servers handle requests is fundamental to system design.
Request Lifecycle
1. Accept Connection
- TCP handshake
- TLS negotiation (if HTTPS)
2. Parse Request
- HTTP method (GET, POST, etc.)
- URL path
- Headers
- Body (if POST/PUT)
3. Route Request
- Match URL to handler
- Extract path parameters
4. Process Request
- Authentication/Authorization
- Input validation
- Business logic
- Database operations
5. Generate Response
- Status code
- Headers
- Body (JSON, HTML, etc.)
6. Send Response
- Serialize response
- Send over connection
- Close or keep-alive
Request Handling Patterns
1. Synchronous (Thread-per-Request)
Request → Thread → Process → Response
+ Simple
- Thread exhaustion under load
2. Asynchronous (Event-Driven)
Request → Event Loop → Process → Response
+ High concurrency
- Complex programming model
3. Worker Pool
Request → Queue → Worker → Response
+ Controlled concurrency
- Added latency from queue
Server Response Codes
2xx Success:
200 OK - Request succeeded
201 Created - Resource created
204 No Content - Success, no body
3xx Redirection:
301 Moved Permanently
304 Not Modified (cached)
4xx Client Error:
400 Bad Request - Invalid input
401 Unauthorized - Not authenticated
403 Forbidden - Not authorized
404 Not Found - Resource doesn't exist
429 Too Many Requests - Rate limited
5xx Server Error:
500 Internal Server Error
502 Bad Gateway
503 Service Unavailable
Server Architecture
Server architecture determines how your backend is organized and scaled.
Monolith vs Microservices
Monolith:
┌─────────────────────────────────┐
│ Monolith │
│ ┌─────┐ ┌─────┐ ┌─────┐ │
│ │ User│ │Order│ │Pay │ │
│ └──┬──┘ └──┬──┘ └──┬──┘ │
│ └───────┴───────┘ │
│ Database │
└─────────────────────────────────┘
Microservices:
┌─────┐ ┌─────┐ ┌─────┐
│User │ │Order│ │Pay │
│Svc │ │Svc │ │Svc │
└──┬──┘ └──┬──┘ └──┬──┘
│ │ │
┌──▼──┐ ┌──▼──┐ ┌──▼──┐
│ DB1 │ │ DB2 │ │ DB3 │
└─────┘ └─────┘ └─────┘
Server Architecture Patterns
| Pattern | Description | Use Case |
|---|---|---|
| Monolith | Single deployable unit | Small teams, simple domains |
| Microservices | Independent services | Large teams, complex domains |
| Serverless | Function-as-a-Service | Event-driven, variable load |
| Event-driven | Async message-based | Real-time, decoupled systems |
Server Deployment
Deployment Options:
1. On-Premises
+ Full control
- High upfront cost
2. Cloud (IaaS)
+ Flexible
- Management overhead
3. Cloud (PaaS)
+ Less management
- Less control
4. Serverless
+ No server management
- Vendor lock-in
5. Containers (Docker/K8s)
+ Consistent environments
- Complexity
Practice Problems
Design a scalable Server system. Cover high-level architecture, data model, and API design.
Solution
// Complete system design:
// - Functional + Non-functional requirements
// - Capacity estimation
// - Data model (SQL/NoSQL choice)
// - API endpoints
// - Component architecture
// - Scaling strategy
// - Monitoring & reliabilityHow would you scale Server to handle 10x the current load? Identify bottlenecks and solutions.
Solution
// Scaling approach:
// 1. Load balancing
// 2. Database sharding/replication
// 3. Cache layer (Redis)
// 4. CDN for static assets
// 5. Async processing (queues)
// 6. Microservices decompositionAnalyze potential failure modes for Server and design mitigation strategies.
Solution
// Failure mitigation:
// 1. Redundancy (multi-AZ)
// 2. Circuit breakers
// 3. Retry with backoff
// 4. Dead letter queues
// 5. Health checks
// 6. Graceful degradationQuiz
1. What is the difference between a web server and an application server?
2. What HTTP status code indicates a rate limit has been exceeded?
3. What is the advantage of asynchronous request handling?
4. When would you choose a monolith over microservices?
Flashcards
Question
What are the main server types?
Click to reveal answer
Answer
Web servers (static files), Application servers (business logic), Database servers (data storage), Cache servers (temporary data), Message servers (async communication).
Question
What are the 6 steps of request handling?
Click to reveal answer
Answer
1) Accept connection, 2) Parse request, 3) Route request, 4) Process request, 5) Generate response, 6) Send response.
Question
What is the difference between monolith and microservices?
Click to reveal answer
Answer
Monolith: Single deployable unit, simpler but harder to scale independently. Microservices: Independent services, scalable but more complex.
Question
What are common HTTP error codes?
Click to reveal answer
Answer
400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 429 Rate Limited, 500 Server Error, 502 Bad Gateway, 503 Unavailable.
Question
What is Server?
Click to reveal answer
Answer
Server is a key concept in system design.
Revision Notes
Key Takeaways
- 1.Choose server type based on what you need to do
- 2.Request handling pattern affects concurrency and complexity
- 3.Monolith is simpler but microservices scale better
- 4.HTTP status codes communicate request results
- 5.Server architecture depends on team size and domain complexity
Interview Tips
- •Start with the simplest architecture that meets requirements
- •Justify monolith vs microservices based on team and domain
- •Discuss request handling pattern for performance requirements
- •Mention deployment options (cloud, containers, serverless)
Cheat Sheet
Server - Cheat Sheet
Server Types:
| Type | Purpose | Example |
|---|---|---|
| Web | Static files | Nginx, Apache |
| Application | Business logic | Node.js, Django |
| Database | Data storage | PostgreSQL, MongoDB |
| Cache | Temporary data | Redis, Memcached |
| Message | Async comm | Kafka, RabbitMQ |
Request Lifecycle:
- Accept connection
- Parse request
- Route request
- Process request
- Generate response
- Send response
Architecture Patterns:
- Monolith: Simple, small teams
- Microservices: Scalable, large teams
- Serverless: Event-driven
- Event-driven: Async, real-time