I guess in many coding interviews there'll be follow-up questios for scalability, millions user request, large data, etc. So how to scale up simple program into providing real-world services? For example if we have a very simple service just to store employee's salary information and then retrieve the salary given employee's name. We just need to maintain a hashmap for implementation.
class EmployeeSalary {
Map<String, Double> salaryMap;
EmployeeSalary() {}
storeSalary(String name, int salary) {}
getSalary() {}
}But in real-world such a hashmap is obviously insufficient. And I tried to summarize different scenarios of scalability question.
Heavy write / heavy calling storeSlary(String name, int salary) Practically data should be written into database, rather than hashmap. And if there's multiple threads concurrently writing into DB, we should consider conflict and apply safe-thread mechanism like locks? And modern DBMS should already have built-in such mechanism? Also if scalability of written request is super high then should consider load balancer?
Heavy read / heavy calling getSalary() Similar consideration of database, safe-thread, load balancer. And in most cases read request is much heavier than write thus has more needs for load balancer. But for read, we could design cache for the most popular or recent request.
If name and salary are stored in logs, storeSalary(String logs), and the logs are extremely huge and are stored at different servers/machines, and how to approach this? The only vague solution I can come up is sth like MapReduce or Distributed storage?
And possibly there are many more scalability related scenarios and follow-up questions, let's discuss!