System design: how do databases work in a distributed application?
Interview Experience
I'm preparing for system design interview .A common system design solution to a global service is to load-balance by location, so you have independent local instances running in AMER, EMEA, APAC, etc.
Full Details
I'm preparing for system design interview .A common system design solution to a global service is to load-balance by location, so you have independent local instances running in AMER, EMEA, APAC, etc. And clients can connect to the closest instance of your server. I have questions about databases. 1. How does this solution deal with the global database? Because all the instances must have the same "state". For example, if I design a load-balanced banking application, I have to make sure that someone can't coordinate a double-withdrawal from both Europe and Asia at the same time. It seems like even if I can parallelize request-handling, each server's SQL mutations are inherently sequential and are a bottleneck. 2. How would I horizontally scale a database? Continually adding compute to a single database has limitations, and I imagine a single instance could become too huge and take too long to query even if it was well-indexed. I'm thinking about hashing the primary key, so I can shard a database into separate instances, but doesn't that make JOINs super slow if I need to join across separate db instances?