Sunday, October 11, 2009

Where do you keep (serialize) application data?

Applications keep data everywhere. From plain text file, INI file, Windows registry, database to proprietary file format.

Take a browser as an example, it needs to serialize user options, bookmarks, cookies and history. The designer can choose to keep each kind of persistence in different files. For example, options in one file and bookmarks in one file. The designer can also choose to keep user options in Windows registry, while keeping the bookmarks in a file.

Can we keep everything (or almost everything) in a single place? Sure, database to the rescue! I am not talking about client/server database system like Oracle and SQL Server. I am talking about small but powerful database system such as SQLite and embedded Firebird. For a real world example, Firefox 3 uses SQLite to keep bookmarks, histories and cookies.

There are several apparent advantages of using database to keep data. It is easy to backup and restore if everything is kept in one database. You are also free from opening and closing various files. Retrieving data quickly is easily accomplished by using index. You can also avoid data inconsistency by using transactions.

Some people will complain that using database to keep small set of data is an overkill. You’ll have to judge that by yourself. Do you want to free yourself from headaches such as creating indexes and creating your own file formats? If so, start to serialize your data to database now. You can then focus on developing your software and release it quicker.

And yes, there are people who keep big list of bookmarks and histories.

No comments:

Post a Comment