This is one practical example when noSQL approach is the best way how to handle data storage.

Invoices are part of many IS and in RDBMS database the usually have structure like this:

Invoices - simple ClassDiagram

Of course this is very simplified but I hope you know what I mean. Many programs store these data this way. It looks very good and very clean – what you think?

Well truth is that this works only in books. In praxis nothing is so simple. And I learned it in hard way.

Actually this clean relational approach is especially for invoice-like documents really bad. Usually life-cycle of these documents is simple – once you signed and send them you will never ever touch them again. And therefore documents which you have in your database must not be changed.

Which can be in clean relational solution real “pain in the …” Why? People using IS sometimes have strange ideas like – they rewrite old addresses or old customers instead of adding new. Why they do this? Please ask them. I also do not understand it. But such a simple operation will show how really “bullet proof” is their IS. And you would be surprised how weak are sometimes some commercial system. If authors did not anticipated such a situation then because of change in some list of customers, addresses, productes etc. you suddenly will see changes in old invoices etc.

NoSQL approach can really help in this situation. Since document is of type “must never ever change” you will simply store the whole content as noSQL structure. Like JSON:

{"type": "invoice",
"number": "2015001",
"company": {
"name": "Some big company",
"address": {"street": "Main road 10", "city": "Zurich", "zip": 12345},
"phone": "+41 125 478 55221"},
"created": 2015-01-01,
.....
"items": [
{"name": "something 1",
"price": 10,
"amount": 1},
{"name": "something other",
"price": 20,
"amount": 5},
....
]
}

This is heavily simplified but I thing the idea is clear.

Of course it can raise questions like -what if I want to generate some reports from old invoices – what about response time?

Answer is simple all depends on number of invoices, frequency of reports, power of your machines etc. If necessary you can create some aggregations from documents to speed up your analytical queries.