I have a complex web application that manages stores and their customers.

The application follows a basic MVC architecture and I should migrate it to a multi-tenant application: - I should go from one store to more stores belonging the same company

  • I will have a db for each store (one db with tenant_id is not an option)

  • I would like to keep the existing interfaces, for example customer.getOrders(). But now "customer" must search on several stores/db. This would allow me keep most of the logic and presentation

It's not clear to me how what is the best pattern from an OOP point of view.

Should I have for example an interface Customer and then 2 implementations, CustomerSingle (the existing one) and CustomerMulti that contains a collection of CustomerSingle? Is there a known software pattern for this situation?

In other words, all the original classes will be still valid in the multi tenant situation but I must "aggregate" their result.

  • Keep in mind that transactions across multiple databases are problematical - and that using multiple databases will prevent you aggregating data where it can be done most efficiently - at the DB server... – MZB Oct 30 '15 at 22:49
  • I'm not very interested in transactions (90% is reading) and the solution with 1DB+tenant_id would imply a complete code rewrite, with no automated testing available.... – Glasnhost Oct 31 '15 at 0:33

Just looking for suggestions, experiences ...

Design for the new functionality. Without the big picture how can you - much less I - assess a microscopic issue like a Customer interface.

Once you see what you need you can better assess how the existing code base might change. Once you see what needs to change you can contemplate how.

Design is everything. If you start by ripping apart your code as random thoughts cross your mind, well, you're in for a world of hurt.

  • I agree with what you said but I tried to give just a small example. The need is clear for me: I want to make the transition from 1 DB to many in a way as transparent as possible for the original application... – Glasnhost Oct 31 '15 at 0:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.