educative.io

Educative

System Design Problems - Designing a URL Shortening service like TinyURL

Hi, I read the following in TinyURL chapter -
We can add a Load balancing layer at three places in our system:

  1. Between Clients and Application servers
  2. Between Application Servers and database servers
  3. Between Application Servers and Cache servers

I’m not clear on point number 2 (Load balancer between App Server and DB server). If we have multiple DB servers say DB1, DB2, DB3. Then how is data in DB1 different from DB2 and DB3? Do they all contain same data? If yes, then how do we synchronize the data between DB1, DB2, DB3 when a new URL is inserted into DB1? How are changes propagated to other databases DB2 and DB3?

This is my first question here. So let me know if the posted in the wrong place.

Thanks

“Database Replication” copies over data from one database (considered as “master”) to the read-only databases. Cloud providers like AWS have “read-replicas” that allow data replication. You can find more here

Esentially, we can use data replication methods to replicate data.
How this generally works is

  • You have multiple database servers, say DB1, DB2 and DB3.

  • You can read data from all of them, but can write to only one of them. Let’s assume we can write to DB1 only.

  • Whenever something gets written in DB1, that data is replicated to DB2 and DB3. There are different ways to replicate the data, synchronous, asynchronous etc.

  • Whenever you have to read something, your load balancer will forward your request to either of DB1, DB2 or DB3. Since data is being replicated, you can read from any of them. This is how we distribute read queries between servers so that one server does not get overloaded.