一个很大的网络服务或许多小网站?

时间:2022-03-28 01:12:48

I'm building a set of methods to provide functionality to a number of different web applications, the methods basically get some data from SQL perform some operations on it and then pass it back to the calling application. They have to be implemented via web services.

我正在构建一组方法来为许多不同的Web应用程序提供功能,这些方法基本上从SQL获取一些数据,然后将其传递回调用应用程序。它们必须通过Web服务实现。

So my question is what are the pros and cons between creating one massive webservice with lots of methods or dividing the methods up into logical groups and encompassing each of these into their own webservice. I think there will be a lot of subsequent methods implemented after the first version so whatever I do has to be easily maintainable.

所以我的问题是用大量方法创建一个大规模的Web服务或者将这些方法划分为逻辑组并将每个方法包含在他们自己的Web服务中之间的优缺点是什么。我认为在第一个版本之后会有很多后续方法实现,所以无论我做什么都必须易于维护。

If it has any impact on the answers I'm using .Net 3.5, C# and can't use WCF at the moment.

如果它对我使用.Net 3.5,C#的答案有任何影响,目前无法使用WCF。

4 个解决方案

#1


4  

One big
Pros:

一大优点:

  • No need to maintain a lot of service references.
  • 无需维护大量服务引用。
  • Can be easier to find what you're looking for, and get an overview.
  • 可以更容易地找到您要找的内容,并获得概述。

Cons:

缺点:

  • If you ever update 1 signature, clients will need to add that huge (?) reference and reread the WSDL.
  • 如果您更新了1个签名,客户端将需要添加那个巨大的(?)引用并重新读取WSDL。
  • Harder to delegate the work if a lot of clients are present.
  • 如果有很多客户在场,就很难委托工作。

Lotsa small ones
Pros:

Lotsa small ones优点:

  • Easier to maintain. One change in a signature is a small change for the clients.

    更易于维护。签名的一个变化是客户端的一个小变化。

  • Easier to use different hosts.

    更容易使用不同的主机。

Cons:

缺点:

  • Can easily grow into a mess.
  • 很容易长成一团糟。

My advice is to look at the logic packages of your services. Are clients likely to use a portion of your services, or all of them? Are there any cases where they will need to use half of service #1 and half of service #2? Try to figure out what the common scenarios are, and design your services so that they will only need to create one proxy for it to work.

我的建议是查看服务的逻辑包。客户是否可能使用您的部分服务或全部服务?是否有任何需要使用服务#1的一半和服务#2的一半的情况?尝试弄清楚常见的场景是什么,并设计您的服务,以便他们只需创建一个代理就可以使用它。

#2


5  

Some food for thought: Granular is good for more control, but it does have an associated performance penalty. If you go too granular, you may end up with an API that would require multiple network round-trips to do anything non-trivial. So, I would keep the network round-trip and latency in mind when designing the service. If the service is to be potentially located across a WAN, I would refrain from making a "chatty" interface and go for methods that return more data.

一些值得思考的东西:粒度有助于更多控制,但它确实有相关的性能损失。如果你过于细化,你最终可能会得到一个API,需要多次网络往返才能做任何非平凡的事情。因此,在设计服务时,我会考虑网络往返和延迟。如果服务可能位于WAN上,我会避免使用“聊天”界面并寻找返回更多数据的方法。

As a for instance, prefer retrieving an entire user plus their order history, instead of one distinct call for the user's data and another distinct call for the order history if most of the time the user and order history will both be required by the caller. You need to consider how the service is going to be used, and factor your interfaces accordingly.

例如,如果调用者需要用户和订单历史记录的大部分时间,则更喜欢检索整个用户及其订单历史,而不是对用户数据进行一次不同的调用以及对订单历史记录进行另一次不同的调用。您需要考虑如何使用该服务,并相应地考虑您的接口。

#3


2  

We had to make the same decision several years ago. We went with the very granular approach. It served us very well. It allowed us to turn out webservices into an API of sorts. This was not our original intent, but it worked very well for us.

几年前我们不得不做出同样的决定。我们采用了非常精细的方法。它非常适合我们。它允许我们将web服务变成各种API。这不是我们原来的意图,但它对我们来说非常有效。

Randy

兰迪

#4


2  

The advantage to splitting them up into separate services is that if you start to run into performance problems you can always move individual services onto separate servers.

将它们分成单独的服务的优点是,如果您开始遇到性能问题,您始终可以将各个服务移动到单独的服务器上。

The advantage of keeping them together in one big service is that certain code (e.g. reading config information from a file) is going to be the same across all services and you can re-use the code if it's all in a single service (you could also put your re-used code in a separate class library).

在一个大服务中将它们保持在一起的优点是某些代码(例如,从文件中读取配置信息)在所有服务中都是相同的,如果它们都在一个服务中,您可以重新使用代码(您可以还将您重用的代码放在一个单独的类库中)。

You could make arguments for either case. The two biggest questions I would have are: 1) Are the services related? Does it make sense to group them together or are you just grouping them together for convenience? If they are related, it might make sense to keep them together.

你可以为这两种情况提出论据。我最大的两个问题是:1)服务是否相关?将它们组合在一起是否有意义,或者您只是为了方便将它们组合在一起?如果它们相关,那么将它们保持在一起可能是有意义的。

2) What kind of load do you expect? Can you realistically expect one server to handle the load of all the services for the next couple of years? If not, it might be better to break them apart now.

2)您期望什么样的负荷?您能否真实地期望一台服务器能够在接下来的几年内处理所有服务的负载?如果没有,现在将它们分开可能会更好。

#1


4  

One big
Pros:

一大优点:

  • No need to maintain a lot of service references.
  • 无需维护大量服务引用。
  • Can be easier to find what you're looking for, and get an overview.
  • 可以更容易地找到您要找的内容,并获得概述。

Cons:

缺点:

  • If you ever update 1 signature, clients will need to add that huge (?) reference and reread the WSDL.
  • 如果您更新了1个签名,客户端将需要添加那个巨大的(?)引用并重新读取WSDL。
  • Harder to delegate the work if a lot of clients are present.
  • 如果有很多客户在场,就很难委托工作。

Lotsa small ones
Pros:

Lotsa small ones优点:

  • Easier to maintain. One change in a signature is a small change for the clients.

    更易于维护。签名的一个变化是客户端的一个小变化。

  • Easier to use different hosts.

    更容易使用不同的主机。

Cons:

缺点:

  • Can easily grow into a mess.
  • 很容易长成一团糟。

My advice is to look at the logic packages of your services. Are clients likely to use a portion of your services, or all of them? Are there any cases where they will need to use half of service #1 and half of service #2? Try to figure out what the common scenarios are, and design your services so that they will only need to create one proxy for it to work.

我的建议是查看服务的逻辑包。客户是否可能使用您的部分服务或全部服务?是否有任何需要使用服务#1的一半和服务#2的一半的情况?尝试弄清楚常见的场景是什么,并设计您的服务,以便他们只需创建一个代理就可以使用它。

#2


5  

Some food for thought: Granular is good for more control, but it does have an associated performance penalty. If you go too granular, you may end up with an API that would require multiple network round-trips to do anything non-trivial. So, I would keep the network round-trip and latency in mind when designing the service. If the service is to be potentially located across a WAN, I would refrain from making a "chatty" interface and go for methods that return more data.

一些值得思考的东西:粒度有助于更多控制,但它确实有相关的性能损失。如果你过于细化,你最终可能会得到一个API,需要多次网络往返才能做任何非平凡的事情。因此,在设计服务时,我会考虑网络往返和延迟。如果服务可能位于WAN上,我会避免使用“聊天”界面并寻找返回更多数据的方法。

As a for instance, prefer retrieving an entire user plus their order history, instead of one distinct call for the user's data and another distinct call for the order history if most of the time the user and order history will both be required by the caller. You need to consider how the service is going to be used, and factor your interfaces accordingly.

例如,如果调用者需要用户和订单历史记录的大部分时间,则更喜欢检索整个用户及其订单历史,而不是对用户数据进行一次不同的调用以及对订单历史记录进行另一次不同的调用。您需要考虑如何使用该服务,并相应地考虑您的接口。

#3


2  

We had to make the same decision several years ago. We went with the very granular approach. It served us very well. It allowed us to turn out webservices into an API of sorts. This was not our original intent, but it worked very well for us.

几年前我们不得不做出同样的决定。我们采用了非常精细的方法。它非常适合我们。它允许我们将web服务变成各种API。这不是我们原来的意图,但它对我们来说非常有效。

Randy

兰迪

#4


2  

The advantage to splitting them up into separate services is that if you start to run into performance problems you can always move individual services onto separate servers.

将它们分成单独的服务的优点是,如果您开始遇到性能问题,您始终可以将各个服务移动到单独的服务器上。

The advantage of keeping them together in one big service is that certain code (e.g. reading config information from a file) is going to be the same across all services and you can re-use the code if it's all in a single service (you could also put your re-used code in a separate class library).

在一个大服务中将它们保持在一起的优点是某些代码(例如,从文件中读取配置信息)在所有服务中都是相同的,如果它们都在一个服务中,您可以重新使用代码(您可以还将您重用的代码放在一个单独的类库中)。

You could make arguments for either case. The two biggest questions I would have are: 1) Are the services related? Does it make sense to group them together or are you just grouping them together for convenience? If they are related, it might make sense to keep them together.

你可以为这两种情况提出论据。我最大的两个问题是:1)服务是否相关?将它们组合在一起是否有意义,或者您只是为了方便将它们组合在一起?如果它们相关,那么将它们保持在一起可能是有意义的。

2) What kind of load do you expect? Can you realistically expect one server to handle the load of all the services for the next couple of years? If not, it might be better to break them apart now.

2)您期望什么样的负荷?您能否真实地期望一台服务器能够在接下来的几年内处理所有服务的负载?如果没有,现在将它们分开可能会更好。