title: Representing (and incrementing) relationship strength in Neo4j
body: <p>I would like to represent the <em>changing</em> strength of relationships between nodes in a Neo4j graph.</p>
  
  <p>For a static graph, this is easily done by setting a "strength" property on the relationship:</p>
  
  <pre><code>  A --knows--&gt; B
         |
       strength
         |
         3
  </code></pre>
  
  <p>However, for a graph that needs updating over time, there is a problem, since <em>incrementing</em> the value of the property can't be done atomically (via the REST interface) since a read-before-write is required. Incrementing (rather than merely updating) is necessary if the graph is being updated in response to incoming streamed data.</p>
  
  <p>I would need to either ensure that only one REST client reads and writes at once (external synchronization), or stick to only the embedded API so I can use the built-in transactions. This may be workable but seems awkward.</p>
  
  <p>One other solution might be to record multiple relationships, without any properties, so that the "strength" is actually the count of relationships, i.e.</p>
  
  <pre><code>A knows B
  A knows B
  A knows B
  </code></pre>
  
  <p>means a relationship of strength 3. </p>
  
  <ul>
  <li>Disadvantage: only integer strengths can be recorded </li>
  <li>Advantage: no read-before-write is required</li>
  <li>Disadvantage: (probably) more storage required</li>
  <li>Disadvantage: (probably) much slower to extract the value since multiple relationships must be extracted and counted</li>
  </ul>
  
  <p>Has anyone tried this approach, and is it likely to run into performance issues, particularly when reading? </p>
  
  <p>Is there a better way to model this?</p>