Share via


Why and When to use transactions?

Many people ask - do I need transactions? Why do I need them? When to use them?

The answer is simple: use them all the time, unless you have a very good reason not to (for instance, don't use atomic transactions for "long running activities" between businesses). The default should always be yes. You are in doubt? - use transactions.

Why are transactions beneficial? They help you deal with crashes, failures, data consistency, error handling, they help you write simpler code etc. And the list of benefits will continue to grow with time.

Don't think in terms of transactions only when you talk to two or more databases. Starting with technologies like LTM, transactions are made available to be used for any multi-action operation. "X = A+B; Y = C*D;" can be transactional or atomic, as some prefer to name it, and can be seen as a single unit of work.

That is also why support for transactions is available almost everywhere. In database systems, in COM+, in ASP.NET, in .Net Framework with System.Transactions and EntepriseServices, in Indigo, in Biztalk etc

You might be saying now: "but my friend X doesn't use transactions - why it is important that I use them?". It is mostly a problem on the education side. The industry didn't talk a lot about transactions and their usage until recently. The original scope of transactions was limited to database scenarios. But technologies around transactions evolved and continue to evolve, in terms on capabilities, ease of use, flexibility, performance etc.

We used to talk about composable objects (as in OOP). We currently talk a lot about composable web services (as in SOA). The technologies are already here to start talking about composable atomic units of work.

How about the future? One avenue is STM or "software transactional memory". Maybe another one is transactional support at hardware level.

Comments

  • Anonymous
    October 05, 2005
    Informative blog - keep up the good work. I'd like to know if Indigo supports transactions with snapshot isolation. Snapshot isolation is new to SQL Server 2005 (I believe Oracle already has it in 10g) and I'd like to know if Indigo supports this level of isolation.

  • Anonymous
    October 06, 2005
    To GK: Indigo transaction support is based on System.Transactions. Since System.Transactions supports Snapshot (see http://msdn2.microsoft.com/en-us/library/248t96aw), Indigo will do the same.

  • Anonymous
    October 12, 2005
    Thanks for the confirmation. Does it hold true for Oracle as well?

  • Anonymous
    November 27, 2007
    PingBack from http://feeds.maxblog.eu/item_295789.html

  • Anonymous
    January 10, 2008
    to GK: System.Transactions will pass the configured isolation level to any provider, including Orcle's. The provider has the option to interpret the isolation level and take it into account.