Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should a developer use web services instead of direct connections to a db? [closed]

I'm looking for a "top ten" list of reasons why we should be connecting to remote databases via web service instead of directly connecting to the db. This is an internal debate right now and I'm pro-web service but losing the argument. I have a basic grasp of WCF / web services, no one else does. We can do whatever we want moving forward but we need to stick with whatever we choose now.

Here is what I've come up with. Any more?

  1. WCF web services can, if configured correctly, be more secure.
  2. Changes to the DB only need to be made at the service level (config file or recompile service).
  3. Once setup and hosted, web services are easier to consume.
like image 635
DenaliHardtail Avatar asked Jan 26 '10 19:01

DenaliHardtail


People also ask

Why do developers use Web services?

Web services are used for a variety of applications, but the most common is for reusing code and connecting existing programs. The web service method can help developers segment applications into components that can be used and reused for various needs.

Should a database connection stay open?

Absolutely it is safe to do this. This is how client-server applications work. If you are using a three-tier application, the application server will keep a pool of connections open anyway.

What is a direct database connection?

Overview. Direct Connect is the simplest way to connect your database to Mode. You provide Mode with the necessary credentials, and Mode's servers connect directly to your database. Most databases hosted by third parties such as Amazon, Google, and Segment are publicly accessible and are compatible with Direct Connect.

Is SQL a Web service?

SQL Server allows you to create native web services. By using this feature, you can expose your data directly on the web. The first step in creating native web services is to create stored procedures or functions that will be called over the web.

What is web services in web development?

Web Services allows different applications to talk to each other and share data and services among themselves. Other applications can also use the services of the web services. For example VB or .NET application can talk to java web services and vice versa. So, Web services is used to make the application platform and technology independent.

Why add a web service in between a web interface?

In contrast, adding a web service in between lets you evolve the interface to mobile clients in more manageable ways: for example, you could keep the old interface in place, add a new one that works "in parallel" with it, and then entirely restructure your database without breaking a single client.

Should you let your clients connect directly to the database?

Once you let a mobile client connect directly to the database, your design is "married" to that database structure: almost any change would break backward compatibility to a client that may be reluctant to upgrade his app.

What are the advantages of using web-services?

For Eg: A Currency converter can be implemented as a web service and it can be published on a url. But then, the same can be created as a web-application. Where is the actual advantage of using web-services? Also as per some posts in SO, webservices should be used if no UI is involved and web-applications if a gui is required.


2 Answers

  1. Security. You're not granting DB access to anyone but web server/app user.

    This is extra important when you have tons of users. You avoid the pain of user/role maintenance on DB side.

  2. DB load reduction. Web service can cache the data it retrieved from DB.

  3. Database connection pooling (hat/tip @Dogs).

    A web service can use a small pool of permanently opened DB connections. The helps in a variety of ways:

    • DB connection pool is limited on database server side.

    • opening a new DB connection is VERY costly (especially to database server).

  4. Ability for fault tolerance - the service can switch between primary/DR data sources without having details of fail-over be implemented by service consumers.

  5. Scalability - the service can spread requests between several parallel data sources without having details of the resource picking be implemented by service consumers.

  6. Encapsulation. You can change underlying DB implementation without impacting service users.

  7. Data enrichment (this includes anything from client customization to localization to internalization). Basically any of these might be useful but any of them is a major load on database and often very hard to implement inside a DB.

  8. May or may not apply to you - certain architecture decisions are not DB acces friendly. E.g. Java Servers running on Unix have an easy access to a database, whereas a java client running on a Windows PC is not database aware nor do you possibly want it to be.

  9. Portability. Your clients may not all be on the same platform/architecture/language. Re-creating a good data access layer in each one of those is harder (since it must take into account such issues as above-mentioned failovers/etc...) than building a consumer layer for a web service.

  10. Performance tuning. Assuming the alternative is clients running their own queries (and not pre-canned stored procedures), you can be 100% sure that they will start using less than optimal queries. Also, if the web service bounds the set of allowable queries, it can help with your database tuning significantly. I must add that this logic is equally applicable to stored procedures, not unique to web services.

A good list can also be found on this page: 'Encapsulating Database Access: An Agile "Best" Practice'

Just to be crystal clear - some of these issues may not be applicable to ALL situations. Some people don't care about portability. Some people don't need to worry about DB security. Some people don't need to worry about DB scalability.

like image 75
DVK Avatar answered Sep 30 '22 14:09

DVK


In my opinion, you should not automatically be exposing your database as a web service. If it turns out you need a service to expose your data, then write one, but not all database access should be done through web services.

  1. There is no reason why a database connection should not be secure
  2. You can encapsulate the database in a data access layer (possibly Entity Framework)
  3. Web services are no easier to consume than a well-written data access layer.
like image 45
John Saunders Avatar answered Sep 30 '22 13:09

John Saunders