Practice & Assessment
Test your understanding of Scalability and Load Balancing
Multiple Choice Questions
5Why does horizontal scaling require stateless application servers?
Which load balancing algorithm is best for requests with highly variable processing times (e.g., a mix of quick reads and slow report generation)?
When adding a new server to a system using consistent hashing, how many keys need to be remapped?
What is the main limitation of using IP Hash as a load balancing strategy?
A CDN is LEAST helpful for which type of content?
Coding Challenges
1Consistent Hash Ring Implementation
Implement a consistent hash ring that supports three operations: addServer(serverName), removeServer(serverName), and getServer(key). Use SHA-256 to hash both server names and keys to positions on a 0 to 2^32 ring. Each server should have 3 virtual nodes (append ':0', ':1', ':2' to server name before hashing). getServer must return the server whose virtual node position is the first one >= the key's hash position (wrap around if needed). Input: sequence of operations as function calls. Output: getServer must return the correct server name string. Test with: addServer('A'), addServer('B'), addServer('C'), then call getServer with 10 different keys and verify consistent assignment. Estimated time: 25 minutes.
Mini Project
Mini Load Balancer Simulator
Build a simulation of a load balancer in code. Implement three algorithms: Round Robin, Least Connections, and IP Hash. The simulator takes a list of server names, a list of (clientIP, requestDuration) tuples, and an algorithm name. It must: assign each request to a server using the selected algorithm, track active connections per server, simulate request completion based on duration, print a request log showing which server handled each request, and print a final distribution summary showing how many requests each server handled. Expose a CLI interface: node lb-sim.js --algorithm=round-robin --servers=A,B,C --requests=requests.json. Use this module's concepts: stateless distribution, health awareness (skip servers with >10 active connections), and algorithm trade-offs in the summary output.
