Tips on Scaling System

Tips on Scaling System

1. Create Stateless web tiers (Separate storage for State data)

  • In Stateless architecture , HTTP request can be sent to any web servers
  • State data is stored on shared data store and kept out of web server
  • Its simple , robust and easy to scale

2. Data Caching

  • Stores result of expensive responses or frequently used/accessed data

3. Consider Multiple Data Center

  • GeoDNS can be used to direct traffic to nearest data center depending on where user is located
  • Replicate data across multiple data center which helps in failover use-cases
  • With multiple data center , it helps to test and deploy application

4. Store Static Dataset in CDN

  • CDN is a network of geographically dispersed servers used to deliver static content (like images,videos,CSS,javascripts)
  • CDNs are run by 3rd party providers and are charged on every data request. Infrequent used assets must be moved out of CDN
  • Set up appropriate cache expiry
  • Static contents must be served via CDN and avoids load on web server
  • Database load is lightened by caching data

5. Shard Data tier

  • First , read about Vertical and Horizaontal scaling from here
  • Read about Database Sharding from here
  • Vertical scaling is also known as Scale Up [scaling by adding more power CPU , RAM , DISK ,etc]
  • Horizontal scaling is better known as Sharding [scaling by adding more server]

A few major challenges from Sharding

  • Celebrity problem : Also known as Hotspot key problem. Example : In Instagram , if we have data of Ronaldo , Lady Gaga , The Rock , Messi , etc in same shard. The shard will be overwhelmed with read operations. To solve this , we would require re-distribute or reallocate data in different shards or increase shards accordingly

  • Join and aggreation : Once db is sharded across multiple servers , its hard to perform join/aggregation operation across database shards. Common practice is denormalize the database.

6. Split tiers into individual services

7. Monitoring system

  • It includes logging and metrics system for operations
  • Automation is necessary at every step