Measuring Throughput
Throughput measures how many operations a system can handle per unit time.
Throughput Metrics
Common Metrics:
RPS = Requests Per Second
TPS = Transactions Per Second
QPS = Queries Per Second
MPS = Messages Per Second
FPS = Frames Per Second
Conversion:
1000 RPS = 60,000 RPM (requests per minute)
= 3,600,000 RPH (requests per hour)
Throughput by System Type
| System | Typical Throughput |
|---|---|
| Web Server | 1,000-50,000 RPS |
| API Gateway | 10,000-100,000 RPS |
| Database | 1,000-50,000 QPS |
| Message Queue | 10,000-500,000 MPS |
| Load Balancer | 100,000-1,000,000 RPS |
Measuring Throughput
Load Testing Setup:
Clients ──── Load Generator ──── System Under Test
│ │
└── Send N requests/sec └── Process requests
│
Measure: RPS, latency
Tools:
- Apache Bench (ab)
- wrk
- JMeter
- Locust
- k6
Throughput Calculation
Example: E-commerce System
Target: 10,000 orders/day
Average order time: Business hours (8 hours)
Peak factor: 3x average
Average RPS = 10,000 / (8 × 3600) = 0.35 RPS
Peak RPS = 0.35 × 3 = 1.05 RPS
With safety margin (10x):
Required capacity = 10.5 RPS
Throughput vs Request Size
Small requests (1KB):
- Higher RPS
- Limited by CPU
- Example: API responses
Large requests (1MB):
- Lower RPS
- Limited by network
- Example: File uploads
Throughput (data) = RPS × Average Request Size
1000 RPS × 1KB = 1 MB/s
100 RPS × 1MB = 100 MB/s
Bottlenecks
A bottleneck is the component that limits overall system throughput.
Common Bottlenecks
System Bottlenecks:
1. CPU Bound
- High CPU utilization (>80%)
- Complex computations
- Solution: Optimize code, add CPUs
2. Memory Bound
- Low available memory
- Frequent garbage collection
- Solution: Add memory, optimize usage
3. Network Bound
- High network utilization
- Large payloads
- Solution: Compression, CDN, optimize payloads
4. Disk Bound
- High disk I/O
- Slow storage
- Solution: SSD, caching, batch I/O
5. Database Bound
- Slow queries
- Connection limits
- Solution: Indexing, connection pooling, read replicas
Identifying Bottlenecks
Monitoring Dashboard:
CPU: [████████░░] 80% ← Potential bottleneck
Memory: [████░░░░░░] 40% ← OK
Network: [██░░░░░░░░] 20% ← OK
Disk: [██████░░░░] 60% ← OK
DB: [██████████] 95% ← Bottleneck!
Action: Optimize database queries first
Bottleneck Analysis
| Symptom | Likely Bottleneck | Solution |
|---|---|---|
| High CPU | CPU-bound processing | Optimize code, add CPUs |
| High memory | Memory leak or large datasets | Fix leak, add memory |
| High network | Large payloads or many requests | Compress, cache, batch |
| High disk | Frequent I/O operations | Cache, batch writes |
| High DB latency | Slow queries or connection limits | Index, pool connections |
Little's Law
L = λ × W
L = Average number of requests in system
λ = Average arrival rate (throughput)
W = Average time in system (latency)
Example:
λ = 100 RPS
W = 0.5 seconds
L = 100 × 0.5 = 50 requests in system
Implication: To increase throughput, either:
- Reduce latency (W)
- Accept more concurrent requests (L)
Improving Throughput
Throughput improvement strategies target bottlenecks and optimize resource usage.
Strategy Overview
Improve Throughput
├── Horizontal Scaling
│ ├── Add more servers
│ ├── Load balancing
│ └── Auto-scaling
├── Vertical Scaling
│ ├── More CPU/RAM
│ ├── Faster disks
│ └── Better network
├── Optimization
│ ├── Caching
│ ├── Connection pooling
│ ├── Batch processing
│ └── Async processing
└── Architecture
├── Microservices
├── Event-driven
└── Message queues
Horizontal Scaling
Before: 1 server × 1000 RPS = 1000 RPS
After: 10 servers × 1000 RPS = 10,000 RPS
Key: Must be stateless or externalize state
Connection Pooling
Without Pooling:
Request → Create Connection → Use → Close → Response
(100ms overhead) (10ms)
Total: 110ms per request
With Pooling:
Request → Get Pooled Connection → Use → Return → Response
(1ms overhead) (10ms)
Total: 11ms per request
10x improvement in throughput!
Batch Processing
Individual Processing:
1000 items × 10ms each = 10 seconds
Batch Processing:
10 batches × 100ms each = 1 second
10x improvement by batching!
Tradeoff: Higher latency per item, higher throughput
Message Queues
Synchronous:
Request → Service A → Service B → Service C → Response
(100ms) (100ms) (100ms) (300ms)
Asynchronous (with queue):
Request → Service A → Queue → Response (100ms)
Queue → Service B → Service C
Service A throughput: 3x improvement (doesn't wait)
Throughput Optimization Checklist
- Identify bottleneck: Profile to find limiting factor
- Scale horizontally: Add more instances
- Pool connections: Reuse database connections
- Cache results: Avoid recomputation
- Batch operations: Process multiple items together
- Async non-critical: Don't block on slow operations
- Optimize queries: Index properly
- Compress responses: Reduce network transfer
Practice Problems
Design a scalable Throughput 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 Throughput 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 Throughput 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 formula for Little's Law?
2. What is the most common throughput bottleneck in web applications?
3. How does connection pooling improve throughput?
4. What is the tradeoff of batch processing?
Flashcards
Question
What is throughput?
Click to reveal answer
Answer
The number of operations a system can handle per unit time. Measured in RPS (requests/sec), TPS (transactions/sec), QPS (queries/sec), MPS (messages/sec).
Question
What is Little's Law?
Click to reveal answer
Answer
L = λ × W. L = average requests in system, λ = arrival rate (throughput), W = average time in system (latency). Links throughput and latency.
Question
What are common throughput bottlenecks?
Click to reveal answer
Answer
CPU bound (high utilization), Memory bound (low RAM), Network bound (large payloads), Disk bound (frequent I/O), Database bound (slow queries).
Question
How does horizontal scaling improve throughput?
Click to reveal answer
Answer
Adding more servers distributes load, multiplying total capacity. 10 servers × 1000 RPS = 10,000 RPS. Requires stateless services or externalized state.
Question
What is Throughput?
Click to reveal answer
Answer
Throughput is a key concept in system design.
Revision Notes
Key Takeaways
- 1.Throughput measures operations per unit time (RPS, TPS, QPS)
- 2.Little's Law links throughput and latency: L = λ × W
- 3.Database bottlenecks are most common in web applications
- 4.Connection pooling and batching significantly improve throughput
- 5.Always identify the bottleneck before optimizing
Interview Tips
- •Calculate expected throughput based on business requirements
- •Discuss specific throughput targets (e.g., 10K RPS)
- •Identify bottlenecks and propose solutions
- •Consider the throughput-latency tradeoff
Cheat Sheet
Throughput - Cheat Sheet
Metrics:
- RPS: Requests per second
- TPS: Transactions per second
- QPS: Queries per second
- MPS: Messages per second
Little's Law:
L = λ × W
L = requests in system
λ = arrival rate
W = time in system
Common Bottlenecks:
- CPU: High utilization
- Memory: Low available
- Network: Large payloads
- Disk: Frequent I/O
- Database: Slow queries
Improvement Strategies:
- Horizontal scaling
- Connection pooling
- Caching
- Batch processing
- Async processing
- Query optimization