且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

直接访问数据库与Web服务

更新时间:2023-12-03 07:53:04

直接数据库访问将您紧密地绑定到架构。任何一端的变化都会影响另一端。但是它具有简单且只需较少网络跳数的优点。

Direct database access couples you tightly to the schema. Any changes on either end affects the other. But it's got the virtues of being simple and requiring one less network hop.

Web服务意味着可以通过更高一级的间接访问来实现更好的抽象和更宽松的耦合。 Web服务可以充当数据的单一管理者。当您只使用应用程序时,就可以直接使用数据库,但是如果其他应用程序出现并且需要相同的数据,则有一天他们将需要更改架构的机会增加了。这些更改也会影响您的应用程序。代价是更多的延迟。

A web service means better abstraction and looser coupling via one additional level of indirection. A web service can act as the single steward of the data. You'll get away with going directly against the database when it's just your app, but if other apps come along and require the same data you'll increase the chances that they'll need schema changes some day. Those changes will affect your app as well. The cost is more latency.

Web服务可以是集中授权和安全性的好地方。数据库也可以做到这一点,所以也许很容易。

A web service can be a good place to centralize authorization and security. A database can do this as well, so perhaps it's a wash.