I'm developing API for quiz game in which there are 3 tables:
1)Games: various games stored here
2)Player: Players involved in a various game (game_id foreign_key) with its turn number
3)answer: Here the user's answer will be store
Now when the game starts question will be displayed to the player with turn_number 1 and the player will submit an answer. After that next question will be displayed to the player with turn_number 2 and the player will submit an answer.
Now, We have one lifeline that if the next player not submitted his/her answer than the previous player can undo their choice. So if a player with turn 2 not submitted their answer than a player with turn 1 can undo his/her choice and can change their answer.
But my issue is when a player with turn 1 click undo and a player with turn 2 submit an answer at the same time. Because of this, my data is becoming inconsistent.
I want to decide which request came first and when undo request is in progress no one can submit an answer or when submit answer request is in progress no one can undo.
How can I handle this situation? Please help.
Note: When undo/submit answer there will be a change in multiple tables, not one table.