I am writing a web application that has a front-end and a back-end.
The back-end is the Admin Panel where users will be posting new products. Let’s call it: www.example.com and it’s a VPS.
Now, I have another VPS that should be accessed as username.example-products.com/product-1
For now, I am storing all the data inside a MySQL database in example.com. Since the front-end example-products.com will have very large traffics, I have to separate these two servers. My question is, how do I access the data stored by example.com server from example-products.com server?
The solutions I’ve thought of are here:-
- Keep 2 Databases in 2 Servers. When a new product is published on example.com, store it in that server as well as send it to example-products.com too (using an API) to store. This way, the two servers are different and will not affect each other. But the problem is, we are duplicating data and there could be inconsistencies.
- Keep 1 common MySQL Server and access that from both the servers. This way, we have a single source of truth. But where should I keep that MySQL server? In example.com VPS or example-products.com VPS? Shouldn’t there be delays in accessing a MySQL server residing in a different VPS?
Any other solution is welcome. I just want to make sure that example-products.com is very fast and scalable and traffics in this server doesn’t affect the back-end server (example.com).