<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Circles and Crosses &#187; Database</title>
	<atom:link href="http://ox.no/posts/tag/database/feed" rel="self" type="application/rss+xml" />
	<link>http://ox.no</link>
	<description>Håvard Stranden&#039;s website</description>
	<lastBuildDate>Sun, 22 Apr 2012 22:21:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Object-Relational Mappings Considered Harmful</title>
		<link>http://ox.no/posts/object-relational-mappings-considered-harmful</link>
		<comments>http://ox.no/posts/object-relational-mappings-considered-harmful#comments</comments>
		<pubDate>Tue, 04 Mar 2008 22:48:25 +0000</pubDate>
		<dc:creator>Håvard</dc:creator>
				<category><![CDATA[Software Design]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://ox.no/posts/object-relational-mappings-considered-harmful</guid>
		<description><![CDATA[Creating an Object-Relational Mapping (ORM) has become the de facto way of handling persistence in the object-oriented programming paradigm. Almost all systems require some form of persistent state, and relational databases have become the de facto place to put that &#8230; <a href="http://ox.no/posts/object-relational-mappings-considered-harmful">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Creating an Object-Relational Mapping (ORM) has become the de facto way of handling persistence in the object-oriented programming paradigm. Almost all systems require some form of persistent state, and relational databases have become the de facto place to put that state. Relational databases are proven, scale well, and organize data in a tabular manner suitable for many of the real world problems that we try to solve, so they are an obvious choice. Choosing them, however, means we have a new problem at our hands, known as the <a href="http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch" title="The Object-Relational Impedance Mismatch">object-relational impedance mismatch</a>.</p>

<!-- more -->

<p>The problem is that a relational database is not suited for storing an object-oriented model. An object is almost always a non-scalar value, meaning that it won&#8217;t fit well in a table row. Hence, we have to create a schema suitable for persisting our objects to a set of tables. This schema will be different for each type of object we have, so it&#8217;s a rather tedious task, but it solves the problem.</p>

<p>As always, we developers tend to dislike repetitive tasks, so we try to simplify and automate the extra work involved with creating an ORM. This has led to various design patterns such as DAO, and in recent years a set of fully automated ORM tools such as <a href="http://hibernate.org/" title="Hibernate">Hibernate (Java)</a>, <a href="http://nhibernate.org" title="NHibernate">NHibernate (.NET)</a>, <a href="http://sqlalchemy.org" title="SQLAlchemy">SQLAlchemy (Python)</a>, and <a href="http://propel.phpdb.org/" title="Propel">Propel (PHP)</a> have become very popular. These tools offer a highly transparent solution to the ORM problem, at the addition of a cost that varies heavily with the nature of the ORM problem. Still, their presence moves us closer and closer to a solution &#8211; we are creating an abstraction that fully encapsulates the difference between a relational database as our storage for persistent objects, and the objects themselves. Hopefully, we will soon be able to create an ORM that induces a linear or perhaps even constant cost on our solution, regardless of the nature of the problem we are trying to solve.</p>

<p>But wait. The real problem we are trying to solve is how to persist the state of our objects, remember? The database is indeed a store, and hence a candidate solution, but using it introduces an impedance mismatch, which is another problem we need to solve. It really is like trying to fit a square block in a round hole.</p>

<p>Let&#8217;s stop trying to solve the wrong problem of creating an ORM, and start finding a solution to our initial and real problem of persisting our objects. Recent innovations such as <a href="http://en.wikipedia.org/wiki/Language_Integrated_Query">LINQ</a> has taken us a step in the right direction by making persistence an integral part of the language, but we&#8217;re still a long way from automated persistence for our objects. I am certain, though, that moving focus away from the challenges of an ORM and on to the challenge of persistence in general will take us further.</p>

<p>Let&#8217;s do that.</p>

<p>(And I&#8217;m sorry for reusing <a href="http://www.u.arizona.edu/~rubinson/copyright_violations/Go_To_Considered_Harmful.html" title="Go To Statement Considered Harmful">Dijkstra&#8217;s</a> already <a href="http://meyerweb.com/eric/comment/chech.html" title="Considered Harmful Essays Considered Harmful">overused</a> phrase.)</p>
]]></content:encoded>
			<wfw:commentRss>http://ox.no/posts/object-relational-mappings-considered-harmful/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Five advices on implementing a cache</title>
		<link>http://ox.no/posts/five-advices-on-implementing-a-cache</link>
		<comments>http://ox.no/posts/five-advices-on-implementing-a-cache#comments</comments>
		<pubDate>Thu, 25 Oct 2007 20:57:35 +0000</pubDate>
		<dc:creator>Håvard</dc:creator>
				<category><![CDATA[Software Design]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://ox.no/posts/five-advices-on-implementing-a-cache</guid>
		<description><![CDATA[I&#8217;ve spent the last few days at work implementing a cache in the data access layer (DAL) of one of our services. The cache works great, and speeds up our service very much in some cases, and somewhat in all &#8230; <a href="http://ox.no/posts/five-advices-on-implementing-a-cache">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent the last few days at work implementing a cache in the data access layer (DAL) of one of our services. The cache works great, and speeds up our service very much in some cases, and somewhat in all cases. I&#8217;ve implemented caches before, and experienced many of the difficulties that arise when introducing a cache. It always seems rather easy, and always has unwanted side effects. The general advice is of course not to do it (and the advice from the database guys are always not to do it), but here are my five best advices on what you should consider if you decide to do it.</p>

<!-- more -->

<p><strong>1. Make sure the cache is transparent.</strong></p>

<p>The system shall not in any way notice that there is a cache handing objects to it instead of the database, nor should the introduction of a cache require changes in any layers above the layer where the cache resides. If you decide that changes are required, be aware that you are making changes to code that does work, and that re-verifying its behavior is a hard and expensive task.</p>

<p><strong>2. If your system is transactional, make sure that the lifetime and mutability of objects in your cache matches your transaction isolation level.</strong></p>

<p>The obvious solution for a cache in a transactional system is a cache that lives per transaction, but this is not guaranteed to work. As an example, let&#8217;s say that transaction 1 reads some data and starts operating on them. Meanwhile, transaction 2 reads, alters, and commits some data that partially or fully depends on the data read by transaction 1. After the commit, transaction 1 reads some other data that depend on the new data committed by transaction 1. In this case, a cache in transaction 1 alters the system behavior if a too low isolation level is used (the alteration is most likely correct, but does not need to be, and it most certainly changes the behavior nonetheless) (see <a href="http://en.wikipedia.org/wiki/Isolation_(computer_science)" title="Transaction isolation">this Wikipedia page</a> for an explanation of transaction isolation levels). Be aware of your isolation level, and know also that the default isolation level is different from RDBMS to RDBMS. As an example, MySQL uses repeatable read as the default isolation level, while MS SQL Server uses read committed. With an isolation level less than repeatable read, a cache with any mutable data in it is essentially useless.</p>

<!--adsense-->

<p><strong>3. Use the cache for immutable data as much as possible.</strong></p>

<p>Also, use the cache for mutable data as little as possible, since this significantly increases the difficulty of the cache implementation, and with it the risk of errors.</p>

<p><strong>4. Give the objects in the cache an as short lifetime as possible.</strong></p>

<p>When implementing a cache, you want the objects in your cache to live as long as possible, since accessing the cache is much faster than accessing the database. Well, think about this: A cache with objects that live forever is actually a replacement for your database, which is not what you want to achieve. To avoid an implementation that is difficult, hard to verify, and unnecessary complex, make objects live as short as possible, while maintaining an increase in speed.</p>

<p><strong>5. Be absolutely certain that the keys you use in your cache identify objects uniquely and unambiguously.</strong></p>

<p>This sounds obvious, but with complex object hierarchies and caching of different parts of the hierarchy at different levels, it suddenly becomes very hard. In general, cache either the top-most or the lower-most objects in your hierarchy. The choice of an approach depends on how you access your data. The best way to decide which approach to take is to do a thorough analysis of your data and the objects that represent them, how you access these objects, how you use them, and in which cases you are most likely to gain speed by introducing a cache.</p>
]]></content:encoded>
			<wfw:commentRss>http://ox.no/posts/five-advices-on-implementing-a-cache/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

