System design — Quick Recap
2 min readJan 7, 2023
This is similar to the evolution of mankind. Initially single server setup was there. As the system got complex, multi server setup came into picture.
Let us dive into basic concepts of system design.
Database
- Relational database [stored in tables and rows]
- Non Relational database [ key value stores, graph stores, column stores, document stores.
Database Replication
Uses Master slave model:
- Master database for write operations
- Slave database for read operations
Vertical Scaling vs Horizontal Scaling
- Vertical Scaling — scale up- add more CPU, RAM
- Horizontal Scaling — Scale out — add more servers — desirable for large scale applications
- Horizontal Scaling is also known as sharding.
- Sharding seperates large databases into smaller, more easily manages parts called shards.
- Resharding data — when one shard has large data and other shard has small data — solved by consistent hashing
- Celebrity problem — hotspot key problem — allot each shard for each celebrity
Load Balancer
- Distributes traffic among servers
Cache
- Stores frequently accessed in memory.
- Response time would be improved.
- Use when data is read frequently but modified infrequently.
- Set some expiration policy. Should neither be too short ( data modified frequently) or too long (stale data).
- Cache eviction — LRU, LFU, FIFO
Content Delivery Network (CDN)
- Geographically dispersed servers used to deliver static content.
Stateful architecture — Remembers everything
- Remembers client data from one request to other.
- Client request will be sent to specific servers.
Stateless architecture — Frequent forgetter
- State data stored in shared data store.
- Client request will be sent to any servers.
- Since it forgets, it is useful in autoscaling( adds or removes server based on traffic)
Message Queue
Stored in memory, supports asynchronous communication. Serves as a buffer and distributes asynchronous requests.
Sample usecase: Photo customization