Stack Exchange
Size of couchdb documents
I have the following document in a couchdb database:
{
   "_id": "000013a7-4df6-403b-952c-ed767b61554a",
   "_rev": "1-54dc1794443105e9d16ba71531dd2850",
   "tags": [
       "auto_import"
   ],
   "ZZZZZZZZZZZ": "910111",
   "UUUUUUUUUUUUU": "OOOOOOOOO",
   "RECEIVING_OPERATOR": "073",
   "type": "XXXXXXXXXXXXXXXXXXX",
   "src_file": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
}

This JSON file takes exactly 319 bytes if saved in my local filesystem. My documents are all like this (give or take a couple of bytes, since some of the fields have varying lengths).
In my database I have currently around 6 millions documents, and they use 15 GB. That gives around 2.5KBytes/document. That means that the documents are taking 8 times more space on CouchDB as they would on disk.
Why is that?

The problem is related to the way the document id is used: it is stored not only in the document, but in other data structures. That means that using a standard UUID (000013a7-4df6-403b-952c-ed767b61554a 36 characters) is going to use up lots of disk space. If collission is a minor issue, with base64 you can number 16 millions of documents with just 4 characters,
and over 1 thousand million documents with 5 characters. A good choice for a dictionary is one which is ordered (in the "View Collation" sense):
-@0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ

Using this method, I have reduced the size of my database from 2.5Kbytes/doc to 0.4Kbytes/doc. My new database uses only 16% of the space of the old database, which I would say is a very big improvement.

CouchDB uses something called MVCC which basically means it keeps previous versions of the documents as you modify them.  It uses these previous versions to help with replication in case of conflicts and by default keeps 1000 revisions (see this for more info).
You can lower the number of revisions to keep if you aren't using replication or some how know that those sorts of conflicts will never happen.
You also might want to familiarize yourself with compaction as that can help (temporarily) lower the storage footprint as well.

No revisions: this is a database newly created, with just new documents inserted. No documents have been updated. Actually, after checking the issue with the couchdb people, I have found the problem: the document id, which is used internally in couchdb for lots of structures, has a big impact in database size. If you want to reduce the size of the documents, one easy thing to do is to use a base64 (or base62, or whatever) encoded document id.
