Web Scalability for Startup Engineers
By Artur Ejsmont (2015)
My Notes
Typical scalability journey:
- A single server for everything
- Upgrade machine/network (vertical scalability)
- Use a CDN
- Deploy each service on a different machine (web server, DB, etc)
- Other horizontal scalability efforts
- Multiple data centres
💡 Different systems will have different needs (bottlenecks will appear in different places).
Vertical Scalability
Upgrade the infrastructure.
- Add memory (to reduce swapping/virtual memory use)
- Use RAID (optimise for throughput)
- Use SSDs (improves random access performance)
- Upgrade the network
- Upgrade/add processors/cores
Horizontal Scalability
Spread the workload logically.
… let’s think of it as running each component on multiple servers and being able to add more servers whenever necessary.
Horizontal Scalability Strategies
Delegate Work
Use REST, make sure GET requests have no side-effects and are constant over time (not: shopping carts, pages that require authorisation). Caches can affect analytics.
- CDNs
- Browser cache
- Web Storage API
Reduce the Workload
Spread the Workload
- Cloning (stateless) services behind a load balancer
- Service partitioning
- Functional: microservice-style
- Technical: front-end v back-end v …
- DB cluster
- Multiple read-only replicas (beware of operations that will not replicate correctly, e.g.,
RAND()
) - Sharding. Same schemas, different data. Queries across shards in the app layer only. Use e.g.,
auto_increment_increment
to avoid ID clashes
- Multiple read-only replicas (beware of operations that will not replicate correctly, e.g.,
- Multiple data centres using round-robin DNS or GeoDNS
NoSQL
Origins in distributed stores. Because ACID has problems in distributed stores, they sacrifice parts.
Term | Definition |
---|---|
Atomicity | Transaction done or not |
Consistency | Only valid data is saved |
Isolation | Transactions don’t affect others |
Durability | Written data not lost |
Caching
The higher the better (less work arrives at the lower layers).
Cache Location | Savings |
---|---|
Client | 100% |
CDN | 98% |
Reverse proxy | 66-98% |
Server | 50-75% |
Where to apply caching? Measure! Rank each page/endpoint by,
Time to serve response × number of requests made
Speed Comparison
Operation | Time (ns) | Multiplier |
---|---|---|
Memory access | 100 | ×1 |
Disk seek (SSD) | 100,000 | ×1,000 |
Packet round trip (same data centre) | 500,000 | ×5,000 |
Disk seek (non-SSD) | 10,000,000 | ×100,000 |
Read 1MB sequentially from network | 10,000,000 | ×100,000 |
Read 1MB sequentially from non-SSD | 30,000,000 | ×300,000 |
Packet round trip (across Atlantic) | 150,000,000 | ×1,500,000 |