tags:

views:

2171

answers:

16

An SQL database is overkill if your storage needs are small. When I was young and dumb, I used a text file and flock()ed it when I needed to access it. This doesn't scale, but I still feel that non-database solutions have been completely ignored in Web 2.0.

Does anyone not use an SQL database for storage? What are the alternatives?

A: 

I would check out XML if I were you. See w3schools XML tutorial section on the left side. Tons of possibilities without using SQL database.

ChrisAD
99% of the time there are better alternatives to xML supported in the language... for php, I'd use var_export/eval so I don't have to parse anything.
Steve Hanov
Whats wrong with XML? If he wants to store data, and using database is a bit overkill I would think XML would suit perfectly imo.
ChrisAD
The problem with XML is that it doesn't scale, you end up with exactly the same issue that you have with a text file.
ilivewithian
A: 

LAMP makes it so easy that you don't need to think about finding another way.

EDIT

The OP tagged the question with LAMP, therefore I would assume he has MySQL already installed. Therefore, I would use MySQL, even if it is just for storing a few small things.

ck
+4  A: 

It probably depends how dynamic your web site is. I used wiki software once that used RCS to check in and out text files. I wouldn't recommend that solution for something that gets as many updates as StackOverflow or Wikipedia. The thing about database is that they scale well, and the database engine writers have figured out all the fiddly little details of simultaneous access, load balancing, replication, etc.

Paul Tomblin
+6  A: 

A distributed hash table like google bigtable or hadoop is a simple and scalable non SQL database and often suits the websites far better than a SQL database. SQL is great for complex relational data, but most websites don't have this requirement. Most websites store and retrieve data in a few forms and don't need to run complex operations on the data.

Take a look at one of these solutions as they will provide all of the concurrent access that you need but don't subscribe to the traditional ideas of data normalisation. They can be thought of as pretty analogous to a bunch of named text files.

Jack Ryan
+1 generally true, but then if someone is concerned, that SQL is overkill, going BigTable would be mega-overkill.
vartec
+29  A: 

There are a lot of alternatives. But having SQLite which gives you SQL power combined with no fuss of file based storage, there is no need to look for these alternatives. SQLite is light enough to be used in cell phones and MP3 players, so I don't see how it could be considered an overkill.

So unless your application needs something very specific, don't bother. Most alternatives are a lot harder to use and have less performance.

vartec
+3  A: 

I would say that it doesn't depend on whether you store less or more information, it depends on how often you are requesting the stored data. Databasemanagers are superb on caching queries, so they are often the better choice performance wise. How ever, if you don't need a dynamic web page and are just loading static data - maybe a text file is the better option. Which format the data is stored in (i.e. XML, JSON, key=pair) doesn't matter - it's I/O operations that are performance heavy.

When I'm developing web applications, I always use a RDBMS as the primary data holder. If the web application don't need to serve dynamic data at every request, I simply apply a cache functionality storing the data in a cache file that gets requested when no new data have been added to the primary data source (the RDBMS).

Björn
A: 

Thats also my opinion. You do not need database for simple stuff. I am using for 'read-only' data text files (CVS or XML) as you mentioned in your question. Although, it can be benefit to use sqlite instead of plain text sometimes (benefit are easy queries).

It is not too hard to use session store for most of the volatile data (that normally would be stored in sql database) or just store them in memory (memcached)!

At the point when I need some data to be written persistenly I would use a database - it makes a life a lot of easier.

Jiri
+1  A: 

Check CouchDB.

bwalliser
+6  A: 

CouchDB (http://couchdb.apache.org/index.html) is a non-sql database, and seems to be a popular project these days, as well as Google's bigtable, or GT.M (http://sourceforge.net/projects/fis-gtm) which has been around forever.

Object databases abound as well; dbforobjects (http://www.db4o.com/), ZODB (http://www.zope.org/Products/StandaloneZODB), just to name a few.

All of these are supposedly faster and simpler than traditional SQL databases for certain use cases, but none approach the simplicity of a flat file.

vezult
ZODB is most often used with RDBMS as a storage layer, so I'm not sure if that's a good example. It's more like an ORM.
vartec
An ORM is tightly coupled with the idea of a relational back-end. ZODB is not. It was designed as an object database with pluggable storage. I stand beside my choice. ;o)
vezult
+1  A: 

I have used LINQ to XML as a data source in a .NET project. It was a small solution, and used caching to mitigate performance concerns. I would do it again for the quick site that just needs to keep data in a common place without increasing server requirements.

ccook
+12  A: 

SQLite is invented for this.

It's just a flat-file that contains a complete SQL database. You can query, update, insert, delete, there's little to no overhead in installation and all you need is the driver (which comes standard in PHP )

SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.

Kind of weird that nobody mentioned this already?

SchizoDuckie
SQLLite is currently the top voted answer...
ck
A: 

Depends on what you're storing and how you need to access it. Generally sql provides great reporting and manual management ability. Almost everything needs some way to manage what's stored and report on it.

Jay
+2  A: 

It depends what you are storing. My blog uses Blosxom (written in Perl but a similar thing could be done for PHP) where each individual entry is a separate text file. The first line is plain text (the title) and the rest is unrestricted HTML. Following a few simple rules, these are rendered to form a simple but effective blogging framework.

It does have drawbacks but it also means that each post is a discrete file, which works well for updating on a local machine and then publishing to a remote web server. This is limited when it comes to efficient querying though, so certainly not a good choice if you want fine-grained control and web-based interaction with your data.

basswulf
+3  A: 

I wouldn't choose whether to use an SQL database based on how much data I wanted to store - I would choose based on what kind of data I wanted to store and how it is to be used.

Wikipeadia defines a database as: A database is a structured collection of records or data that is stored in a computer system. And I think your answer lies there: If you want to store records such as customer accounts, access rights and so on then a DB such as mySQL or SQLite or whatever is not overkill. They give you a tried and trusted mechanism for managing those records.

If, on the other hand, your website stores and delivers unchanging file-based content such as PDFs, reports, mp3s and so on then simply storing them in a well-defined directory layout on a disk is more than enough. I would also include XML documents here: if you had for example a production department that created articles for a website in XML format there is no need to put them in a DB - store them on disk and use XSLT to deliver them.

Your choice of SQL or not will also depend on how the content you wish to store is to be retrieved. SQL is obviously good for retrieving many records based on search criteria whereas a directory tree, XML database, RDF database, etc are more likely to be used to retrieve single records.

Choice of storage mechanism is very important when trying to scale high-traffic site and stuffing everything into a SQL DB will quickly become a bottleneck.

Steve Claridge
A: 

One level down from SQL databases is an ISAM (Indexed Sequential Access Method) - basically tables and indexes but no SQL and no explicit relationships among tables. As long as the conceptual basis fits your design, it will scale nicely. I've used Codebase effectively for a long time.

If you want to work with SQL-database-type data, then consider FileMaker.

le dorfier
A: 

In Perl I use DBM or Storable for such tasks. DBM will update automatically when variable is updated.

Alexandr Ciornii