Books about dependency injection and inversion principle

You would not be “switching classes” in this case. Using your sketch, the “Data service” should be able to decide if the “master database” or one of the “read slaves” should be used. In most cases, it would also be tied to the cache server like Redis, where it would cache queries again depending on logic for X period of time.

When it receives a request, it will parse the query, decide if it should go to write or read, if read, it will check if it has a valid cache result if it will use it, if not it will pull from the read slave, etc.

Now, at 200k users you do not really need the cache part, unless you have some expensive queries. Though utilizing cache of the queries with varying degrees of TTL, can really save on database server cost (i.e. you won’t need as many slave servers).

If you are talking about having the ability to easily change between if the system should use MySQL, Cassandra, or even a text file for storage solution depending on the connection/user. In this case, I would recommend looking into hexagonal architecture.