Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, russell.

Asked: February 26, 2016 - 12:11 am UTC

Last updated: February 27, 2016 - 1:57 am UTC

Version: 12.1

Viewed 1000+ times

You Asked

Tom,

Many years ago I think I remember you stating your development philosophy on where application logic should be built. Something along the lines that over the years front-end development platforms have come and gone but the data stays in Oracle so if you develop in the database eventually it is going to pay off when you need a new platform. Among other reasons as well probably. I've always developed under the mantra of first try and code in SQL, then if necessary PL/SQL, and finally if necessary front-end application. Obviously the game has changed from when I first remember reading this in the client/server days. Have you published such a development philosophy and what are your updated thoughts on the matter?

and Connor said...

Connor here - so what follows is my opinion not Toms :-)

For me, I think the philosophy has if anything been strengthened over the years. A friend once coined the term "YAFET" (Yet Another Front End Technology) representing the fact that today's front-end tool is tomorrow's legacy piece of junk. And its never been more true than today - all that has changed is the names are now more funky :-)

It seems to be the case that we're stuck in this endless cycle of:

"Oh... you built your app in JingleBells ? You should move to the FerrisWheel framework".

(10 mins later)

"Oh... you built your app in FerrisWheel ? You should move to ChocolateHamster".

and so on, and so on.

Dont get me wrong, I've little doubt that each of these new frameworks/technologies are an evolution and improvement of the previous, but businesses run the risk of a giant soup of technologies to look after in the long term. That's ok though - we developers will claim we can glue it altogether with microservices and charge on regardless :-)

Now I'm also a realist, so I know that the rapid fire arrival of new development technologies will not cease. So for me, the principles of SQL and PL/SQL remain unchanged, in that, when I'm dealing with the data, if its nicely encapsulated within SQL and PL/SQL, then I'll be much better equipped to ship out/ship in changes to app dev technologies as they appear. I'd much rather that stability than having to go hunting in 'ChocolateHamster' for data access code so I can refactor it to 'PumpkinSandwich 2.0' or whatever tomorrow's cool tech is.

And even though SQL and PL/SQL are within my realm of expertise, I'm not particular bigoted toward them. It's more about what they offer - great data access language, code that is close to the data, near seamless transition between to two etc etc... For example, I think NodeJS related technologies could easily fall into similar territory, ie, you can run it close to the data (ie, on the database server), you can consolidate data access through it etc. It's the principles via which SQL and PLSQL succeed, rather than them in their own right, if that makes sense.

With the world becoming cloud-cloud-cloud-cloud-cloud-cloud :-) such consolidation and close-to-data code is going to get all the more important, because as servers continue to get insanely fast, latency ultimately becomes king of response time.

Bryn Llewellyn also has a paper on the topic which you might find interesting

https://blogs.oracle.com/plsql-and-ebr/entry/why_use_pl_sql

Other welcome to share their thoughts.

Rating

  (5 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Absolutely agree with Connor

Kim Berg Hansen, February 26, 2016 - 7:23 am UTC

An example from my (previous) work I've quoted several times, but still valid:

At my then employer we wrote an application for customers to enter their car registration number and it returned which rims and tires in our assortment would fit their car and showed those rims graphically on picture of customers car.

The logic for finding the rims/tires was written in SQL and wrapped in a PL/SQL packaged procedure returning a cursor variable. Front end graphic web code was written in ASP and Java applet.

3 years later java applets were out of style and Shockwave Flash was the hype (+ faster and better at the graphics.) Front end re-written. PL/SQL and SQL untouched.

3 years later customers were using iPads all over, which meant no Flash worked. Front end re-written in HTML-5 to be responsive to multiple devices. PL/SQL and SQL untouched.

Front end code need to move with the times. If we hadn't re-written front end over and over, we would have lost customers. But we saved a lot by not having to touch the back end logic.

As Connor states, this way of doing app development is valid not just for Oracle PL/SQL and SQL. It'll be equally valid in Microsoft T-SQL or other database environments.

The point is that the business logic part of your app that works with the data - code it as close to the data as possible. This part will change much less and less often than UI code.

The part of your app that deals with user interface - code it in whatever front-end framework that works to provide users with good experience in "present-day environment". This part will change often when user demands change due to new devices, cloud, VR, whatever... "Game changes" most often happen at this level.

Separating app code like that has been good advice for many years and will continue to be good advice going forward.

You might read http://thehelsinkideclaration.blogspot.com (start from the earliest blog posts in March 2009) - it explains very nicely separating code into layers like this.

Connor McDonald
February 26, 2016 - 10:22 am UTC

Thanks for stopping by Kim.

Data-oriented business logic

Stew Ashton, February 26, 2016 - 9:49 am UTC

Hi Russell,

You started out asking about "where application logic should be built". Kim Berg Hansen changed the expression to "the business logic part of your app that works with the data".

The change in terms is extremely important.

"Business logic" is what needs to be done, not how it's done. Business logic was implemented for centuries before computers existed.

When we say "application logic", we are already talking about "how" to implement business logic in software.

The term "application logic" is often used because of the Java / J2EE dogma of separating code into presentation, application and data layers - all of which are to be coded in Java of course.

In reality, "business logic" is sometimes data-oriented and sometimes not. The logical data model and its implementation in DDL all have to do with business rules concerning data. On the other hand, sending an email when my order has been shipped is not fundamentally a data issue.

It is vital to identify "the business logic part of your app that works with the data".
- Implement it as much a possible in the physical data model (DDL, constraints).
- Provide APIs to the application layer using SQL wrapped in stored procedures and views. The APIs should deal with individual objects (for OLTP), or multiple objects (for bulk processing), or should provide set-based access for batch and BI processing.
- The APIs should never commit or roll back! The APIs should never turn unforeseen exceptions into return codes! Otherwise you will break "statement level atomicity".

The "application layer" manages the transaction. It commits or rolls back. It does any non-persistent calculations, and it manages distributed transactions.

Connor and Kim hardly mention the "application layer". I think that is because many applications are mainly data-oriented and don't have much need of one.

I worked for years with Java dogmatists. All three layers were to be written in Java. The data layer was managed by Hibernate to allow for database portability. As a result, the "application layer" was huge and the other layers were frameworks.

For years now, we have admitted that the presentation layer has to be done in Javascript - and that we have to take different browsers into account.

We should do the same with the data layer: take different databases into account and use data-oriented languages with specific added value.

Once we do that, what's left in the "application layer"? Often not much.

Implement the data-related business rules (and security!) as close to the data as possible. Then you only need to change them when the data model changes.

Best regards, Stew

Make your DBMS a service provider in your architecture

Toon Koppelaars, February 26, 2016 - 1:02 pm UTC

It's all here (above) and there (Bryn's paper, Helsinki blog). Kim mad a couple of true statements. Stew coined a couple of good definitions. And Connor eloquently demonstrated the Yafet syndrome. I'm not even going to try and give a summary of my view on this topic, you can read the Helsinki blog for that. The arguments over there prove to be timeless.

If there's just one thing I'd like you to take away from 'us database guys' telling you to do stuff in the database tier, it would be this:

Make the DBMS a service provider in your architecture.

If you have an app page that given a car registration number needs to get info on rims and tires, then *logically* build a service module in the database that has as its input a registration number, and as it outputs rim+tire info. Now whether you do that as ref-cursor, or as a stored-procedure with formal IN and OUT params, is not really relevant.

If you have an app page that given a logged in user, needs to display information, be it aggregated or not, that originates from multiple tables in the database, again then logically build a service module in the database that has the username as its input and returns all required display information as its output. Dependent upon the complexity of the display information to be returned you may consider giving back an XML-document or a JSON string, instead of a set of formal OUT params.

What is important is that you *not* embed SQL statements or PL/SQL blocks (other than the ones calling the db resident service modules) nor any conditional logic around them in your UI-technology du-jour (Yafet).
Because if you do, your agility to move to the next 'whitechipmunk' paradigm in UI-land, diminishes drastically.

Oh, and by the way, if you do this right, it will all perform 1, 2, sometimes 3 orders of magnitude better, while running on less hardware. Yes, I know, because I do this for a living nowadays.
That's orders-of-magnitude, ok? Not 2 or 3 times faster. No, 100 and sometimes 1000 times faster.




Connor McDonald
February 26, 2016 - 4:30 pm UTC

Thanks for your comments Toon.

A nice read

Bryn, February 26, 2016 - 5:19 pm UTC

I enjoyed reading this piece. Of course I second what was said. Thanks, Connor, for citing my paper.

Interesting discussion

Evan, February 26, 2016 - 11:10 pm UTC

This is a very interesting discussion.

I like the term YAFET - I'll have to remember that one. Also, I love the names of the various front end technologies that you've come up with. :) My favourite is Ferris Wheel Framework.
Connor McDonald
February 27, 2016 - 1:57 am UTC

Oh no... you're still on FerrisWheel? Dear oh dear... you should move to WeepingCactus - its more automated and faster.

:-)

More to Explore

Data Pump

All of the database utilities including Data Pump are explained in the Utilities guide.