Conflicts from multiple users editing same data

What are the best practices are for avoiding conflicts, where more users try to access and edit the same data?

I have an application where users can create user-generated treasure hunts/games. The problem is how to manage when more users try to edit fx. Game_Foo at the same time. Off course a normal user can not edit another users game, but a user with Admin rights can. So the situation can appear in the following cases:


[*]the author or one or more admin users try to edit the game simultaneously

[*]More persons can be logged in as the same user (fx. on different computers)


I see the following possibilities to solve the conflicts:


[*] To block a user from entering the edit of the specific game if another user is already editing that game

[*] To throw out the current user from the edit of the specific game if another user enters to edit that game

[*] To let both users edit same game simultaneously and then try to resolve worst conflicts by error handling and DB-transactions

[*] Your Solution here :)


Ad(1) a challenge is to know when a user has finished editing. In some cases a timeout will be needed, so a Game will not be locked if the editing user do not leave editing properly. I am also in doubt how to create this solution in the best way. As the conflict can be between two session of the same user, I guess a solution could be to make field in the game_table saving the session_ID of the person currently editing the game. A check would be needed for every action of the user to see wether the session_ID in the game_table is equal to the session_ID.

But it would also be necessary to have a timestamp_field which was continuously updated whenever the user makes an action. This can be made, but it is not a very elegant solution and can easily create messy code.

Ad(1) (2) This is in most aspects similar to (1), but no need for expiration check would be needed. However information to the user pushed out would be needed.

Ad(3) This can be a solution if the conflict of more user_sessions editing the the same game does not happen too often and if the possible conflicts can be solved at least to an extent that the conflicts does not create serious errors like inconsistent data saved to the database.

Ad(4) If you have any ideas to other kind of solutions

I guess the problem I have described above could appear in many more complex applications, so it could be interesting to hear different thoughts on how to solve it.

I hope I have put enough information about the problem. If not, please tell me, and I will write more info.

Best Regards Sune


I personally suggest Optimistic Locking as the simplest one, but there are also other solutions mentioned in this thread.

Hi Sune, welcome to the forum.

I would also vote for the 3rd method.

It’s the most simple and reliable.

The 1st one might be the most user friendly solution if we could design it in a smart way, but it seems very expensive just as you pointed out correctly.

You will be interested in this topic, too.

Thank you very much, it seems like a good solution :) And a really fast reply.

I might consider later to build in some features to support multiuser-editing better. In many cases it could be nice to have a team of people working on the same game. But that will go on the wishing list:)