开发者

Web Service Architecture - multi tenancy design pattern (maybe)

I having a slight design problem : I have to create a Web Service (asmx or wcf) that retrieves customer data from multiple database servers, each one is exactly the same except they will contain data for different States (1 DB server per state, big states can have multiples etc).

This will be used by a call center, for example, someone calls the call center and says, can i have an indication when my order will be delivered my order no is "aa_etc" and the service should run a query on all servers and return all the orders details for that order.

This is straight forward, except there is multiple servers to query.My idea is to have ce开发者_C百科ntral sqlite db with all connection strings of the current online servers and then query each one in turn


public class OnlineServer 
{
 public string Name {get;set;}
 public string ConnectionString {get;set;} 
}
...
public class Order
{
   public List OrderDetail getDetails(string orderno,string connstring)
   {
     //Code to get all orders from database using specified connstring
   }
   ....
}
....

List servers = getOnlineServers();

foreach(OnlineServer in servers)
{
  OrderDetails d = Order.getDetails("aa_etc",OnlineServer.ConnectionString);
}


Just writing down this idea feels totally wrong.

I would really appreciate it if someone can help me get going with this in the right direction, this is a really big project and starting this wrong will just end up in tears later on.

Thanks


If you cannot some how merge the data in to a single DB. You may be able to use nHibernate. It can query multiple databases see http://mikehadlow.blogspot.com/2008/10/mapping-entities-to-multiple-databases.html

You would have to set up a different entity per server. By doing it this way it would take care of all your DB connections, pooling, sessions etc.


I want to consider this problem a bit futher but I have an off-the-wall idea which might be of interest so I'll through it out there.

My idea is to have central sqlite db with all connection strings of the current online servers and then query each one in turn

This gave me an idea: why not fire off a search query to each system asynchonously? I'm thinking AJAX here (but you could use iFrames)...

  1. The user enters a search and hits "Go".
  2. Somehow you loop through your collection of known data sources, but each "sub" search is seperate and asynchonous (think federated search).
  3. As results come back they are displayed on screen to the user - who can then stop the search process if they get a match they like.

I'm assuming the data would be "pulled together" visually by the UI - either by straight layout or via clever client-side code - this would give you further options to tailor the UI but at the expense of a more complex client-side code base.

You'd have other options too, like allowing the user to narrow their search by data source if they wanted to.

Also, adding / removing data sources would be simple.

This is where I need to address you're actual question more directly; in my opinion you'd most definately want a seperate service per database - but there's flexibility in how you do that.

  • Having a collection of services that reflects the data sources gives you a clean logical architecture.
  • Doing this doesn't preclude putting something over the top that brings it together (thinking of loose-coupling here).
  • It's always much easier to put stuff together than tear them apart.
  • You'd still be able to re-use code: multiple instances perhaps.
  • You'd have some management overhead due to multiple instances - but also the flexibility to management them better: access control, dedication of resources, etc.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜