System Design.

Day - 1
High level Design
Vertical Scaling → increase the server memory, cpu etc
Horizontal Scaling →Create multiple servers, with same configuration.
Cron job → like in the example prepare before hand during non-peek hours.
Backups → Backup server.
Horizontal Scaling → Buy more servers and DB
Micro-service Architecture → individual servers can handle their loads individually(Requests and response)
Distributed System(Partitioning) → like local servers everywhere.
Load balancer → Distributes across multiple servers, so that it can find the server with low response time. to reach customer.
Decoupling → Decoupling in terms of business requirements, ex: Delivery agent is a separate Operation.
Logging and Metric’s calculations → Logging every Problem that occur during the execution.
Scaling
Scalability is the ability of a system to handle growing amounts of work by adding resources
Vertical Scaling
Vertical scaling refers to increasing the capacity of a single server by upgrading its hardware specifications like adding more CPUs, memory, or faster storage.
Advantages
Simplicity: Requires little to no change in application code architecture
Consistent Performance: All resources are in one machine, avoiding network latencies between nodes.
Disadvantages
Physical Limits: A single machine has finite maximum CPU, memory, etc…
Single Point of Failure: If the upgraded machine fails, the entire service can go down.
Horizontal Scaling
Horizontal scaling adds more machines (servers or instances), distributing incoming requests or data across multiple nodes.
Implementation using
Load Balancing:- Traffic is routed through a load balancer that evenly routes requests to the available nodes.
Microservices:- Individual services instance or server can be replicated horizontally.
Horizontal / Vertical Scaling.
Horizontal Scaling (buy more machines) | Vertical Scaling (buy bigger machines). |
1. Load Balancer Required | N/A |
2. Resilient (if one server fails route to diff one. | Single point failure |
3. Network calls between services(slow) (RPC) | Inter process communication |
4. Data Inconsistency | Consistent |
5. Scales well as users Increase. | Hardware limit |
Load balancing
Naive (Modulo) Hashing :- →Maintains a ordered list on N servers, indexed 0 to N-1
→ For each incoming request compute h = H(request_key)
using a uniform hash function
→ A front‑end proxy or load‑balancer applies this mapping on every request to decide which backend to forward to
Limitations
High Remapping Overhead:- when scaling from 5 to 6 servers the modulo modules changes, so almost all keys has to be remap to different servers.
Cache Missmatches:- After remap to the different servers the cache stored inside the previous servers are gone, it can’t be reused.
Consistent Hashing Technique
Consistent hashing arranges the hash space as a logical circle (0…2ᵐ−1), both servers and keys are hashed into this space:
Hash each servers unique Id, to one or more points on the ring(virtual nodes).
Hash each request key into the same ring space.
Move clockwise from the key’s position until you encounter the first server(virtual node). That server handles the request.
Each physical server is represented by V virtual node.each with its own hash position.
Node adding and removal :- Hash its node into virtual node. Only keys that fall between each new virtual node and its predecessor node get remapped, Only O(K/N) keys move when nodes change, compared to ≈K in naive hashing.
High Fault Tolerance: On node failure, only its key range redistributes, avoiding system‑wide cache flushes.
Scalability: Seamless horizontal scaling with predictable key movement
So Consistent Hashing Technique. is the best options for the Stateful load balancing, CDN’s (Content Delivery Network), Distributed Caching and Databases.
Subscribe to my newsletter
Read articles from Manoj Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
