Neo4J - Simple "follower" graph
Question: I'm attempting to create a simple Twitter-esque "follower / friend" graph
using Neo4J and Python. The graph would look something like

    
    
    user_1 FOLLOWS user_2
    user_1 FOLLOWS user_3
    user_2 FOLLOWS user_1
    

After a day of reading I thought it best to dive straight in using the REST
interface and, since I'm using Python, py2neo. Here is my code:

    
    
    from py2neo import neo4j
    
    def main():
        g = neo4j.GraphDatabaseService()
    
        # Create an index for our user nodes
        index = g.get_or_create_index(neo4j.Node, "user")
    
        # Create a single node, User 1
        node = index.get_or_create("user", "User_1", {"id": "User_1"})
    
        # Populate the graph with some more users just for testing
        nodes = []
        for user in ["User_2", "User_3", "User_4", "User_5"]:
            nodes.append( index.get_or_create("user", user, {"id":user}) )
    
        # Create a relationship between User_1 and User_2
        g.get_or_create_relationships( (node, "FOLLOWS", nodes[0]) )
    
    if __name__ == '__main__':
        main()
    

As you can see, I'm using get_or_create_relationships to prevent duplicate
relationships and when adding thousands of nodes I'm assuming this is going to
incur some kind of overhead.

Using straight up "node.create_relationship_to(nodes[0], "FOLLOWERS")" seems
to create duplicate relationships each time the script is run which for a
graph db newbie confuses me slightly since the relationship is exactly the
same.

The likelihood of creating duplicate relationships is very low but in the
event it were to happen, would this cause issues with graph traversal? Should
I be indexing my FOLLOWS index with some kind of unique function?


Answer: I would use cypher `CREATE UNIQUE` to only create a FOLLOWs releationship if
there is none existing, see <http://docs.neo4j.org/chunked/milestone/query-
create-unique.html>

Would that work?

