Search code examples
graphmany-to-manyrelationshipcouchbasenosql

NoSQL: new kind of relationships using Arrays?


I had to manage relationships between documents over a NoSQL engine (Couchbase), and I figured out this way to solve my problem. Here is my solution and the steps that let me realize it:

https://forums.couchbase.com/t/document-relationships-using-arrays-and-views-passing-though-graph-theory/3281

My questions are:

  • What do you think about this solution?
  • Have you ever used something like this? How is it working?
  • Are there any better ideas? Critical points of this solution should be helpful

Thank you.


Solution

  • Interesting post Matteo. After reading it I realized that you can possibly improve on few aspects:

    • Consider 1-1 node relationships. In your post you focus on N-N node relationships (sure one can argue that 1-1 is a subset of N-N)...however I think there is a potential of having a different (optimized) implememgtaion for 1-1 relationships. for 1-1 I use node key value as a field in my json doc (e.g. user: {name:string, dob:date, addressID:string})

    • Node key design to address relationships: You can encode in the key value relationship information, e.g. key: "user#11", "user#11#address#123", "address#123#user#11", etc.

    • Data integrity aspects: Take into consideration missing complex transactions. i.e. you can't mutate several documents in one transaction. The design should compensate for that.

    I have used similar solution in my model design for Couchbase in the past. Its now in production for several years already and its performing just fine (load is about 250 tps)...I was trying to avoid as much as possible creating complex node relations and ended up having very few 1-1 and 1-N types.