Slashdot Mirror


Where Does the Business Logic Belong?

logic-Dilemma queries: "I'm currently working in a big project that involves creating tons of reports. These reports require extensively data operation and manipulation in order to be build, and most of that can be handled directly by the DBMS (which would greatly increase performance and implementation time). However, letting all business logic sit in the database implies that we will be extremely attached to one vendor, which kills any attempt at portability. What would you do to tackle this dilemma? Have you ever faced a situation in which the choice between clean design/portability versus performance would change dramatically the whole system design? What have you chosen?"

6 of 92 comments (clear)

  1. Do you need portability? by GOD_ALMIGHTY · · Score: 4, Interesting

    Is this an internal app? Is it going to sit on an Oracle or DB2 box forever? Then toss the business logic in the database if it can be done more efficiently that way.

    If you're going to try to market this as a product, then concentrate on devleoping the business logic, after all, that's what businesses want to buy. They'll pay you to port it to their database or just buy a copy of the database you've written it for, if it's valuable enough to them.

    I've been working on apps like this for years. Just stick it in the database. It's so much easier than maintaining a bunch of query engine code or mappings so you can keep your precious business logic in a "programming language". If your using Oracle, you could just write it in Java and install it on the database. PL/SQL or whatever you're writing the business logic in will probably be around longer than any app language like .NET or PHP. People spend more money migrating their data than they ever do migrating their code. If you put the code next to the data on the database, your likely to get yourself a high performance app that will provide you support contracts till the end of days.

    All that being said, this approach works best if you're using a database that has support for stored procedures, embedded code and custom types, either one of the commercial biggies (Oracle, DB2) or PostgreSQL. Firebird (or whatever they're calling it this week) might work too. I wouldn't trust MySQL for this type of work yet though, I don't think it supports code in the database all that well yet.

    Personally, I think databases are going to wind up absorbing application servers like J2EE containers and will eventually look like a relational/object hybrid with interfaces to various protocols and container environments. After all, those engines are pretty simple to slap on top of a good database. Oracle and IBM are already moving in this direction somewhat. Oracle more than IBM. I think MS is going to move this way with SQL Server as well, but of course it will only be for .NET and MS tech.

    Does that help?

    --
    Arrogance is Confidence which lacks integrity. -- me
  2. Portability by Cranx · · Score: 3, Interesting

    My experience is this works best:

    Reports and other visual output generated at the client using simple data structures spit out by a procedure (middle-tier) layer.

    Java/Ruby/Perl/Python/C++ (gasp! adjust for efficiency) through XML-RPC or SOAP works well as a middle-tier layer. Export the grunt work of searching and sorting as SQL statements to your database. Give the layer an SQL-pass-through command so you can prototype code in your client easily, then port/move the code into the middle layer.

    Do it over HTTP or pipe it through SSH.

    The database can be anything, MySQL/Oracle/MS SQL. Don't write any procedures or anything to them. They are not very portable; it's very easy to get blocked in, at least in my experience. I'm sure lots of people are good at not getting blocked in, but it's not automatic.

  3. Fascade Pattern by HaiLHaiL · · Score: 3, Interesting

    This is what the fascade pattern is for. I wouldn't worry too much about RDBMS portability. However, putting your SP calls behind some kind of fascade at least gives you portability for the code which will utilize the report data. Let the DBMS do what DBMS's are good at.

    --


    reech bee-yond ur clip-0n
  4. There is no "choice" here by Mycroft_514 · · Score: 3, Interesting

    After 20+ years of wroking with DBMSes, including 10+ as a DBA, I can tell you that you want your business logic in the DBMS - EVERY TIME YOU POSSIBLY CAN DO IT. This is especially true of RI in the DBMS.

    If you think that application developers are going to implement the business logic in the application, you better think again. I have watched many systems over the years, and NOT ONCE has the application group implemented the business logic in the application and gotten it right.

    In one shop (RI not available in the DBMS, thank you to THAT vendor) we had 1 guy whose job it was to fix data errors. I tracked usage, and he was responsible for 1/3 of the resources used day in and day out just fixing errors in the data every day.

  5. If you're using Oracle by f00zbll · · Score: 3, Interesting
    I would suggest reading up on materialized views, which were originally designed for data mining and reporting purposes. The next thing i would do is look at Oracle's OLAP support and see if OLAP covers all the functionality you need. The only time I would put the business logic in a middle tier is when SQL doesn't provide the expressiveness needed to generate the reports. For example, if you need to use some complex mathematic calculations that combine several rows, doing it in PLSQL probably would be painful. If you're ok with embedding java in your sql, Oracle allows you to do that and optimize those calculations.

    Other good reasons for externalizing the business logic is if a significant part of the data is external to the database. In that case, you may want to calculate what you can in the database and store it in a table, then use those calculated values with the external data to get the final values.

  6. Unhelpful but funny --or-- things BL stands for by MarkusQ · · Score: 3, Interesting

    The first question to ask yourself when deciding where to put something is where did it come from? Often, this is the best place to put it.

    I have been part of the whole where-does-the-business-logic-belong process many times, and if your company is anything like the ones I've seen, some middle manager with training in a field unrelated to anything you're dealing with pulled the "business logic" out of someplace, and you might suggest that they stuff it back in the same place when they are finished with it.

    In any case, bright light often is bad for business logic, so it should be kept someplace like that anyway.

    -- MarkusQ