且构网

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

直接访问数据库vs Web服务

更新时间:2023-12-03 07:57:34

任何一端的任何变化都会影响另一端。但它有简单的优点,需要一个更少的网络跳。

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.