There are always two ways to solve everything: the easy way and
the hard way. Time and time again, I see people choosing the hard
way. It is not always done consciously. More usually, it is done
out of ignorance. They never expected the database to be able to
do 'that'. I, on the other hand, expect the database to be
capable of anything and only do it the 'hard' way (by writing it
myself) when I discover it cannot do something.
For example, I am frequently asked 'How can I make sure the end
user has only one session in the database?' (There are hundreds
of other examples I could have used here). This must be a
requirement of many applications but none that I've ever worked
on — I've not found a good reason for limiting people in
this way. However, people want to do it and when they do, they
usually do it the hard way. For example, they will have a batch
job run by the operating system that will look at the V$SESSION
table and arbitrarily kill sessions of users who have more then
one session. Alternatively, they will create their own tables and
have the application insert a row when a user logs in, and remove
the row when they log out. This implementation invariably leads
to lots of calls to the help desk because when the application
'crashes', the row never gets removed. I've seen lots of other
'creative' ways to do this, but none is as easy as:
ops$tkyte@ORA8I.WORLD> create profile one_session limit sessions_per_user 1;
Profile created.
ops$tkyte@ORA8I.WORLD> alter user scott profile one_session;
User altered.
ops$tkyte@ORA8I.WORLD> alter system set resource_limit=true;
System altered.
That's it — now any user with the ONE_SESSION profile can
log on only once. When I bring up this solution, I can usually
hear the smacking of a hand on the forehead followed by the
statement 'I never knew it could do that'. Taking the time to
familiarize yourself with what the tools you have to work with
are capable of doing can save you lots of time and energy in your
development efforts.
The same 'keep in simple' argument applies at the broader
architecture level. I would urge people to think carefully before
adopting very complex implementations. The more moving parts you
have in your system, the more things you have that can go wrong
and tracking down exactly where that error is occurring in an
overly complex architecture is not easy. It may be really 'cool'
to implement using umpteen tiers, but it is not the right choice
if a simple stored procedure can do it better, faster and with
less resources.
I've worked on a project where the application development had
been on going for over a year. This was a web application, to be
rolled out to the entire company. The HTML client talked to JSPs
in the middle tier, which talked to CORBA objects, which talked
to the database. The CORBA objects would maintain 'state' and a
connection to the database in order to maintain a session. During
the testing of this system we found that they would need many
front end application servers and a very large database machine
to support the estimated 10,000 concurrent users. Not only that,
but stability was an issue at times given the complex nature of
the interaction between the various components (just exactly
where in that stack is the error coming from and why? —
that was a hard question to answer). The system would scale, it
would just take a lot of horsepower to do it. Additionally, since
the implementation used a lot of complex technologies — it
would require experienced developers to not only to develop it
but to maintain it. We took a look at that system and what it was
trying to do and realized that the architecture was a little more
complex than it needed to be in order to do the job. We saw that
simply by using the PL/SQL module of Oracle iAS and some stored
procedures, we could implement the exact system on a fraction of
the hardware, and using less 'experienced' developers. No EJBs,
no complex interaction between JSPs and EJBs — just the
simple translation of a URL into a stored procedure call. This
new system is still up and running today, exceeding the estimated
user count and with response times that people do not believe. It
uses the most basic of architectures, has the fewest moving
pieces, runs on an inexpensive 4-CPU workgroup server and never
breaks (well a tablespace filled up once, but that's another
issue).
I will always go with the simplest architecture that solves the
problem completely over a complex one any day. The payback can be
enormous. Every technology has its place — not every
problem is a nail, we can use more than a hammer in our toolbox.