views:

329

answers:

2

Hello,

What are the pros and the cons when we have the choise beetween using a direct database accès or using a web services ?

What would be your choice for a critical application, that should be responsive (<0.5 sec) and with a low call to this webservice/DB (NB : the web service will be maintained by an other team).

+4  A: 

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.

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.

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.

duffymo
A: 

Obviously, a direct database access will always be faster in simple scenarios.

With a WebService, you gain flexibility :

  • plug-in a different implementation,
  • when several applications need access to the same data, make one responsible for that data, and have the other one access it through a WebService : you will have no data lag between the two ; and you can keep often-accessed data in memory in that application, instead of using the database to communicate between applications....

Given your context of responsiveness (with possibly a problem with the other team), I would try to go the direct database access route, unless several applications need to share the data...

KLE
I couldn't say either way which would be better. In the context of your app a database access would certainly work. It would depend on how beneficial services could be to your entire enterprise.
duffymo
The issue with this is that it sometimes difficult or impossible to know ahead of time when your db will be used by multiple apps. This is yet another reason stored procedures are a better investment than parametrized queries that live in the app source.
David Lively