CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Eric Wise

Business & .NET

February 2006 - Posts

  • On the move

    Just wanted to make a quick announcement that I'll be starting a new position on Monday working for Pets Marketing in Canton, OH.  They are owned by the hartville group and are involved with pet insurance which is something that is pretty big in Europe and Japan and on the rise here in the United States.  This is a really good opportunity for me to get into a relatively young and growing company and hopefully make a solid impact.

    The shop is running with the latest and greatest- .net 2.0 and SQL 2005.  The culture is solid and the upper management seems to be a pretty big fan of IT and the value it can bring to the organization.  I also got to pick out my own laptop!

    Anyways, they have a variety of sites if you have the time and interest:

    www.petsmarketing.com

    www.wagnpet.com

    www.petshealthplan.com

    www.healthybarkandpurr.com

    www.healthyandhappypets.com

  • "Transactional" Database Structures

    I was meeting with a group of developers the other day and the topic, which I will not go into detail about came up about using a transactional database structure for some data that required a history versus the typical method of keeping current records in one table and on any change writing to a history table.  I've seen some transactional based structures in other projects before and I was slightly surprised that more than half the people in the meeting had never seen one before.  This can mean only one thing: it's blog time!

    Disclaimer: While I have a bit of skill with SQL Server, it's not something I usually "teach" on, so if any of this is unclear I apologize in advance.

     

    What do you mean by a "Transactional" structure?

    In concept, it's very similar to financial accounting principals where you have debits and credits.  You post credits and debits in equal values throughout the accounting system such that as money flows through accounts you end up with a balanced total.  At the end of the day, you have an endpoint where there is a credit or debit with no counter-balance and that ends up representing profit (or loss).  This concept can be similarily applied to transactional history data.

    For example, let's imagine an insurance company that issues a Cobra policy to an employee.  For those of you unfamiliar with how Cobra works, basically you make a payment on the first of the month to get insurance coverage for that month.  Now if you don't make your payment, your policy shows as cancelled and if you submit a claim it will be rejected.  However, you have a 30 day period to make your payment, and if at any time in that 30 days you do make the payment then your previous claim can be resubmitted and will be accepted.

    What the transactional structure brings us the ability to do is use an effective date such that we can look back in history to see what the state of your account was on a particular date.  This is easier to understand with some hard data: 

    We will say you had a policy that started (TransCode ST), on January 1 :

    RecordId PolicyId TransCode TransFlag EffectiveDate PolicyDate
    1 1000 ST 1 1/1/2006 1/1/2006

    First thing you'll notice is that the data is denormalized.  We will use transcode ST for start and SP for stop.  Transflag will always be 1 or -1, which is how we define a valid current record.  If the sum of the trans codes for a particular record is 0, then it is considered to be invalid if you are looking at the "current" view.

    Per our example, let's say that the employee does not make a payment on February 1st, and their policy is cancelled.  At this point you will insert a new record into the table to show that their policy has ended:

    RecordId PolicyId TransCode TransFlag EffectiveDate PolicyDate
    1 1000 ST 1 1/1/2006 1/1/2006
    2 1000 SP 1 2/1/2006 2/1/2006

    Now we can easily see that if you ask on February 5th if they have coverage the answer is clearly no since they have an active stop date of 2/1/2006.  Here's where the fun comes in, let's say that the employee makes their payment on February 10th.  This means that the insurance company will make their policy retroactively effective so that the claim on the 5th can be valid.  This requires invalidating the stop date that was entered:

    RecordId PolicyId TransCode TransFlag EffectiveDate PolicyDate
    1 1000 ST 1 1/1/2006 1/1/2006
    2 1000 SP 1 2/1/2006 2/1/2006
    2 1000 SP -1 2/10/2006 2/1/2006

    Now, when we submit the claim on or after the 10th, the effective date kicks in an shows that the sum of the TransFlags for the stop entry is 0, hence is invalid and can be ignored.  So we end up with a start date of 1/1/2006 with no end date which means their policy is currently active.

    The neat thing about this is that we have also preserved the history through the use of the effective dates.  If we were to query based on an effective date of 2/5/2006 then the invalidation of the stop date would not have occurred yet and you would be shown the accurate state of this person's account at that specific date and time.

     

    What are the advantages of structuring data this way?

    • Simplification
      • There are fewer columns/datapoints/tables than in a more traditional and relational active record + history table setup.
      • By eliminating these extra tables and logs we no longer need to worry about using triggers etc to maintain said logs.
      • We only use inserts.  Existing data is never altered or deleted which puts a great integrity constraint on the data
      • Effective dates allow an easy query interface to view the state of an account at a point in time, stored procedures are structured such that the default view is "today"
    • Flexibiliity
      • Normalized structures in this case will be more performant.
      • Business rules and interfaces can change without changing the data structure (In general, you will write views that perform the transaction flag summations, grouping and filtering)
    • History
      • Pefectly maintained and with an insert-only constraint incorruptable
    • Archiving / DataCleaning
      • This is very easy to do because you have an effective date (it is common since you end up with more datarows than in a traditional structure to periodically archive everything prior to X date, like in accounting when you close the books for the last fiscal year.  When archiving you typically copy the old data into an archive table and then put the aggregate info into a data warehouse type structure for fast and easy historical querying)

    What are the disadvantages?

    • Less Readable
      • Structuring for normalization, performance, and data capture gives a base table that is not all that readable or reportable directly.  Reports etc should use prefabricated views or a data warehouse so that the "non-sql elite" can get at information in a good reporting format easily.
      • This also means there is a learning curve to developers who have never seen this structure before.  Many people go crosseyed when first looking at it.  =)
    • Performance
      • Do to aggregates, summations, and denormalization you have to be very careful about how you structure your queries and indexes.  You can really shoot yourself in the foot if you do it wrong.  Luckily fixing it is a matter of performance tuning.

    In conclusion, when used in a proper scenario, this technique can give a much more history friendly structure that is reliable and fast to query.  It is certainly not applicable anywhere, and you should be cautious and consult a good DBA before you attempt to implement this type of structure but it really does pay big dividends in the right situations.

  • Fantastic Article

    I don't normally post links, but this article is great.

    http://www.developer.com/design/article.php/3573356

  • Is Open Source Killing The IDE/Tools Market?

    So, I see that Delphi is for sale. I'm actually not all that surprised since there are free alternative IDEs popping up everywhere, the most notable of which is Eclipse.  The IDE and tools market seems to be losing margins rapidly as free components and tool sets compete with traditional corporate offerings.

    Is this a good thing or a bad thing?  I often note that the Open Source community seems to play catch up to the for profit offerings.  Open Office for example has been chasing Microsoft Office for years and each time it starts to catch up Microsoft has to add new features and functionality to remain dominent.  In a way, this is a good thing because it keeps Microsoft from being lazy but in a way I can also see this being a bad thing if eventually the free offering gets "good enough" that Microsoft would decide to leave the market.  Why do I feel this way?  Simply put it is the innovation factor.  I have in general seen very little (note "very little" not "none" before a flame war sparks) in the way of innovation from the free open source community.  This is not to say that there are not quality products out there, but is more a statement of the drive to "catch up" and play "me too" against commercial vendors.  What will drive innovation if commercial vendors pull out of the market?

    Another concern I have is that there is so much fragmentation in the free open source world.  Certainly one can argue that the great thing is that you can customize your packages however you like, but what tends to get glossed over is once you have customized things how do you smoothly upgrade to the next version?  Is there enough interoperability being focused on between packages?  The community as is has made great strides improving this, but I still think they have a ways to go when it comes to seamless interop that you get from the Windows / Office / etc suites where you can drag and drop from anywhere to anywhere.  The additional problem with having such a diverse community is that in the standards argument there will always be groups that simply will not accept Direction A and will fork to Direction B which leads to more fragmentation and pain for users that pick Direction A which is eventually declared a failure and abandoned for Direction B.

  • A Culture of Success

    Culture is king.  Think about that for a moment.  Think back on all the jobs you've ever worked, successes and failures.  When it all boils down to it, a strong culture is probably the most influential factor in the success or failure of an organization.

    Case in point: If you've been paying any attention at all to the business news lately, you'll see that Ford and GM are scrambling to remain competitive after taking some serious losses in the midst of one of the biggest economic booms we've had in a while.  Why do you suppose this is?  The truth is trickling out, particularily from Ford which is now touting a "new culture" initiative that is attempting to make them more innovative and attractive to the consumer.  I encourage everyone to look at what they are going through and analyze why this is so.  Here's my take:

    Currently I'm enrolled in an Operations Management MBA class.  In this class we focus on how to improve on the bottom line of a business from an operational standpoint.  What this means is that raising prices isn't the focus to make more money, but reducing the costs of doing business.  In general, there are two specific ways you can go about this: technology and process.  As IT professionals, we are all aware of how technology can help improve the bottom line through things like automation, reducing errors, etc.  The whole concept of Just In Time inventory systems is built on the advanced telecommunications we have available today.  Process on the other hand may involve technology at some points, but is really focused on the steps and conditions that occur from start to finish and how things can be arranged more efficiently and less costly.

    I can hear some of you saying "well duh, but what does this have to do with culture?".  Simply put:

    • You can design the best process in the world, implement the latest technology, but if you can't get people to adopt it and use it properly it will fail.

    Think on this for a moment.  Have you ever created a software package that is "better" than an existing package and had people resist the change?  Processes and technologies are tools, and without people willing and able to use the tools properly the benefits will not be realized.  It's so simple, yet so many companies just don't seem to get it.  There is a natural resistance to change in many people and if the culture doesn't help reduce the impact of this it can cause a lot of pain.  In Ford's case, they've rolled through 3 CEOs in recent years and have very little to show for it.  You can either determine that all three of these CEOs were boneheads, or that something in the organization prevented them from making the positive impact they wanted made.  Repeated failures by multiple people speaks to me that the problem likely lies in the organization and culture, which not surprisingly was the message in the multiple superbowl ads Ford aired.

     

    Symptoms of a Failing Culture

    Here's a few of them:

    Information Hoarding- Information hoarding occurs when people in an organization fear losing control over their critical data or through competition with other teams are trying to seize power.  The fear of losing control usually rises from a lack of trust in other departments or teams.  That they will cause harm to the holder.  Open communication requires trust and faith that information when shared will not come back to haunt the granter.  The other case of competition and seizing power can be tied right back to the upper management that allows such a condition / perception to exist in the first place.

    Devaluation Syndrome- People generally need to feel valued and appreciated in their work.  When companies take their workers for granted, stop respecting the work/life balance, and don't solicit feedback it tends to make them feel like "another butt in the seat".  A big cause of this during times of change is the solicitation of feedback.  Oftentimes you see companies bringing in teams of high priced consultants who impose their will upon existing teams.  This can cause feelings of resentment as employees may feel like management does not trust or value their opinion on how to make things better.  I tend to be a big fan of getting people involved, even if only peripherally in changes that have a big impact on their job whenever possible.

    Shooting the Messenger- The earlier management is made aware of problems, the more cost effective it will be to fix them (or eliminate a bad process faster).  If workers feel like they can't be honest about the reality of what is going on internally, they will stay close-mouthed and management will not be aware of the issues occuring until it all blows up.  Obviously clinging to a losing process for longer than necessary is not good for the stress level of the workers or the bottom line of the company.

    Successful Cultures Need the Following:

    Communication.  Open communication, free of politics and repercussions for reporting the truth.  How does a software project end up a year late?  One day at a time.  If your teams are sweeping problems under the rug because they are "small" or because they can "catch up later" over time it will pile up to a point where it will bite the organization.  Then the crap flows downhill as the executive champion takes heat for going over budget, the manager of the project takes heat for not raising the alarm earlier, and ultimately the workers suffer when the project ends up being outsourced or cancelled.

    Rewarding positive behavior.  Positive reinforcement is far more effective than negative reinforcement particularily when it comes to the creative thinking positions like development.  When your mind is free of negative emotions you can focus on the task at hand much more than when in the back of your head you are dwelling on negative feelings which ultimately demotivates the worker.  I have seen coworkers completely frozen by depression, anger, and anxiety.  It's not a pretty sight.

    Empowerment- very little is more motivating than being in control of your own projects.  It is one thing to fail at something that doesn't have your name on it and another thing altogether to fail at someone else's initiative.  It is far too easy when not being empowered to shift the blame for how things are going to a 3rd party instead of inward.  The teams in your organization are experts in their domains.  While management's goal is to keep the big picture in focus and make sure processes move effectively through the organization the granular details within the teams are often best influenced by the people actually doing the work.  Setting aggressive goals and rewarding employee innovation is a big key to productivity and job satisfaction.  Just be sure to be agressive but reasonable and appreciative or you'll  end up with the title of company slave driver!

More Posts

Our Sponsors

Proudly Partnered With