Maybe serializing the parallel writing query would be helpful to your solution. In your situation, You have 11 functions, simulating 11 different social networking actions. In your description, I thought that some of the actions(transactions) may be executed in sequential order (e,g, you can only accept friend request after your friend sent an invitation). You may serialize some write transactions. In other words, some queries will be blocked until the previous ones finished.
With the help of Causal chaining and bookmarks, you can serialize the operations for each session. For example, if you have three functions, sendInvitationToFriend, reject friend, acceptFriend. reject/accept transactions will be blocked until the sendInvitationToFriend transaction finished.
Some code snippets (neo4j-java-driver 4.1) :
List<Bookmark> bookmarks = new ArrayList<>();
// Send Invitation.
try ( Session session = driver.session( builder().withDefaultAccessMode( AccessMode.WRITE ).build())){
session.writeTransaction( tx -> this.sendInvitationToFriend( tx, "friendId", "yourId"));
savedBookmarks.add(session.lastBookmark() );
}
// accept the invitation
try (Session session = driver.session( builder().withDefaultAccessMode( AccessMode.WRITE ).withBookmarks( savedBookmarks ).build())){
session.writeTransaction( tx -> this.acceptFriend(tx, "friendId", "yourId"));
}
// Create a friendship between the two people created above.
try (Session session = driver.session(builder().withDefaultAccessMode( AccessMode.WRITE).withBookmarks(savedBookmarks ).build())) {
session.writeTransaction( tx -> this.rejectFriend( tx, "friendId", "yourId"));
}
You also mentioned that your simulation is somehow random. My suggestion you could define a retry strategy in your program, re-attempt the query serval times until it goes well and let the main thread to sleep for a while between any two retries. You can find more details information from the link
Wish this post will be helpful to you.