4

For CouchDB you can create multiple views and/or multiple design documents.

Is it better to group views in the same design document or keep each view to its own design document?

Justin Elkow
  • 2,833
  • 6
  • 28
  • 60

1 Answers1

9

Internally, views within each design document are managed together in a "view group". Each view group spawns a separate view server when accessed - i.e. if there are 8 view groups, you will have 8 JavaScript processes. This certainly has design and performance implications. From the CouchDB documentation,

View index rebuilds occur when one view from the same the view group (i.e. all the views defined within a single a design document) has been determined as needing a rebuild. For example, if you have a design document with different views, and you update the database, all three view indexes within the design document will be updated.

So, from a design/deployment perspective, you need to be aware that changing a single view will rebuild all of the other views within the design document. You can use this trick to build them in the background but it is still going to build all of the views in the group so is potentially expensive.

You can also use the view group-view server relationship to your advantage. For example, if you have a CPU with 8 cores you might have 8 view groups, 1 for each core, to improve parallelism.

Arup Rakshit
  • 116,827
  • 30
  • 260
  • 317
Will Holley
  • 1,745
  • 10
  • 11
  • Will thanks for the clarification. I have a follow up question. What about update functions in design documents? Or more generally what happens if the design document does not contain any views? – Akshat Jiwan Sharma Dec 30 '13 at 11:04
  • 2
    My understanding is that the view group identity is determined using an MD5 signature of the "views" section of a design document. This is why the background view building trick works (two design design docs can share the same view group if the signature is the same). If there are no views then the design document should not spawn a view server because there is no associated view group. – Will Holley Dec 30 '13 at 13:35
  • 3
    I understand that disadvantage of keeping multiple views in the same design document. It would rebuild all the indexes from scratch if the design document is updated. What is the advantage of keeping multiple views in the same design document? – Ayushi Dalmia Sep 01 '16 at 14:35