views:

79

answers:

5

In my work, i have a friend that insists to keep the business logic inside the database using stored procedures ...

What are the arguments that i can use to convince him not to do such thing?

The reason he want to do this is because we have multiple systems with diferent plataforms (Web Application in .NET with VB.NET and another Desktop Application developed in Power Builder - Sybase).

Thanks!

+2  A: 

What are the arguments that i can use to convince him not to do such thing?

What are your arguments against it? Why do you necessarily want to stay away from stored procedures?

This is actually not a bad idea. If you have different systems written in different languages access the database, it may help to keep at least some of the business logic in the database.

Developer Art
Good point, but as it's not an answer, better suited as a comment.
sleske
+1 - I decided to leave the same opinion as a comment, but it's equally valid as an answer. Presumably the OP must have some of his own reasons for wanting to go down a particular path.
Greg Beech
Generally if you want different systems in different languages to access the database you provide the ubiquitos and interoperable solution, i.e. a XML/HTTP interface, that way all your clients just need a HttpClient rather than a database vendor library and knowledge of your schema. You can then freely change the internals of your web service without affecting any of your clients.
mythz
+2  A: 

I would go for the web service for several reasons:

  • You can expose your services to all kind of clients to use it
  • It's more flexible, more convenient for debugging, for testing
  • You will gain a better source control support
  • Your programming language will be probably more expressive than SQL
anthares
+2  A: 
  • Not strongly-typed.
  • Cannot easily refactor, breaks clients at runtime.
  • Not unit-testable.
  • Most likely not all business logic can be a stored-proc so your logic is split amongst db and code.
  • Stored procedures are not as capable or powerful as a programming language
  • Harder to obtain the right level of encapsulation requiring your client to know the internals of your data schema
  • Harder to version
  • Business logic is tied to a database vendor which you'll be stuck with for life
Edit: other user-contributed points:
  • harder and more expensive to scale
mythz
sleske
If you write your business logic in .NET you will be stuck to .NET for life ... So, what is the point here ?
anthares
.NET is a free open-specification that runs everywhere (servers, desktops, embedded devices, linux/mono) and is known and supported by millions of developers world wide. It can be componentized and re-used in multiple languages, etc.
mythz
Why would you like to run your server on a embedded device? And you can run the your database server on a desktop machine. But why would you do that? And get serious mono is not an option for a serious products. Sorry, I don't think this point is applicable here. It's true in general, but not related to this question.
anthares
@anthares: I'm with you on this. @mythz: sorry, but you sound like an architecture astronaut...
gbn
I'm answering your question explaining the difference between a proprietary db vendor and an open-specification, multi-vendor implemented language. It's not your database that you would run on your embedded device, it's your business logic. Business logic needs to be written in a language, that's a given but why would you tie it to your proprietary persistence provider?
mythz
You can add to this list: harder to scale (much more expensive to updgrade a db server than to add app server instances)
Pascal Thivent
"Not unit-testable" - explain?
Tony Andrews
"harder and more expensive to scale" - well, maybe Oracle is an exception but I find a solution built on stored procedures scales brilliantly, without the need to keep adding more servers.
Tony Andrews
@Tony "Not unit-testable" means you cannot test it in isolation, in-memory without access to external resources (i.e. the database itself). This is important if you want to maintain a CI of automated builds and test-suites, ensuring your software doesn't introduce bugs or breaking-changes. You're still able to run Integration tests but they more difficult to configure and are a lot slower to run.
mythz
A: 

Define business logic

Anyway, you simply use the DB to do what it does best. Stuff like aggregation and data integrity.

But every system is a compromise. If you have 5 different sets of clients, then the DB might be the best place. Not every spreadsheet or Access DB can call your beautiful middle tier web services...

gbn
I see, so you have excel and access db's calling your stored procedures?
mythz
In some systems yes, in others no. And we have web services too.
gbn
ok I'm having trouble working out the benefit of doing this over writing the sp-logic in code. What's a good example that you've done when this is a good idea?
mythz
Don't understand. If you read my answer, I don't say to do everything in SQL Server. Or in client code. As for example, if you can aggregate a table and join data in client code better than a DB engine then either you're very good or very arrogant.
gbn
You did suggest to call SP's in access/excel instead - I'm trying to work out when that's a good idea. You're better selecting from a db view (not calling an SP) if you want to aggregate data.
mythz
I would always use SPs (if i can) whether or not I have business logic. Not least, encapsulation, security, consistent signature (are stored procs not methods?). As for using a view: not really.
gbn
+1  A: 

Pro web services, con database logic:

  1. If your database is shared by others your app will now be coupled both at the data and logical layers if you put the logic in the database. That's usually a bad thing.
  2. I would be concerned about load on the database server. If your relational database is getting hammered by queries and calculations you won't have the possibility to scale it as easily as you would if the middle tier is doing calculations.

Pro database logic, con web services:

  1. If the database is wholly owned by your app, perhaps putting the logic in it is an acceptable choice.
  2. I don't worry as much about the fear of switching databases, because that happens more rarely than middle tier changes. Middleware fashions come and go, but the data is the crown jewel of any business.
  3. Web services have their downside, too. Translating XML to objects and back is a waste of CPU cycles. In-memory calls are orders of magnitude faster than network calls. A single roundtrip to your "simple" service today might be 200 ms, but start adding those up and pretty soon your SLA will be gone.

Don't give in to dogma. Consider the pros and cons of both and make a rational decision based on your app's particular situation. Both you and your co-worker sound like you've make it a black or white emotional decision. Remember: the outcome doesn't reflect on you as a person. You'll find out about what it says about you as a designer after it's in production.

duffymo
Web services are more scalable and can handle more concurrent connections. Most of the time the its the database that is the bottleneck. You're not limited to XML, there are other high performance options available e.g. Protocol Buffers, etc.
mythz
Agreed - that's what I'm saying in the third paragraph: "...won't have the possibility to scale it as easily..." It might be worded awkwardly, though. I'll edit it - thanks.
duffymo