I have a big MySQL database, D_Big, with a bunch of data in it. I also have a service, S1, with APIs that read or write from this database. For example, one API might get something from the database. Another might write a row to the database. etc.
I also have a small, secondary database, D_Small, that S1 (and only S1) is reading and writing to. I want to leave the small secondary database alone, but I want to change the way data is accessed from the big MySQL Database, D_Big.
I want to make it so that the only way to access the big MySQL database is through API calls to a second service, S2, which also has access to the big database. When S1 want the data in D_big, it will have to call the APIs in S2 which will return the data in D_Big. Thus, I want to remove S1's direct dependency on D_Big.
What are some good ways to go about doing that? What are some tips/advice? The most straightforward way seems to be to replace every single API call in S1 that accesses D_Big directly with an API to a corresponding API in S2 that just performs the exact same database access that S1 would have performed directly. For example, imagine that we have these APIs in S1:
API_1 returns columns [foo, bar, baz] from table1 in D_Big
API_2 writes value foo to table2 in D_Big
API_3 returns columns * from table3 in D_Big
I would just replace these with:
API_1 in S1 calls corresponding API in S2 which returns columns [foo, bar, baz] from table1 in D_Big
API_2 in S1 calls corresponding API in S2 which API_2 writes value foo to table2 in D_Big
API_3 in S1 calls corresponding API in S2 which API_3 returns columns * from table3 in D_Big
But what about cases where the ideal mapping isn't one to one? Like when you should combine APIs (ex. one API in S1 calls two different APIs in S2 to get the data it needs or two different APIs in S1 call the same API in S2 but with different parameters)?
How do you make a good interface decoupling two services from what used to be a shared data source (D_Big)? Assume that both S1 and S2 use a Java/XML/Spring based system to transfer data over API calls.