Question

A task is assigned to a group and tasks are managed via database. What are the different locking mechanisms that can be implemented to prevent multiple accepts?

riyazahmadganaie610
May 10, 2026

Answer

Locking mechanism is used to ensure that chaos doesn’t erupt when multiple users try to read or modify the same piece of data concurrently. Mainly there are two types of locking Pessimistic & Optimistic.


In Pessimistic Locking we assume conflicts are probable when multiple users try to modify same information. In this mechanism, the idea is acquire locks on resources preemptively, maintaining exclusive access to these resources for the entire duration of a transaction or critical operation. By doing so, it prevents other users or processes from accessing or modifying the locked resource until the lock is released.


Optimistic Mechanism assumes that conflicts are infrequent or less likely to occur. It allows transactions to proceed independently and optimistically assumes that conflicts won’t arise during the execution phase. Before committing changes, the system checks whether any other transaction has modified the resource since the current transaction started. This validation is typically done by comparing versions.


In our case, we can use optimistic locking mechanism. When a task is assigned to group and multiple users opened the same task, Accept task button will be visible to all of them. The user who first hits the accept button will be the owner of the task. When other users try to accept the task, we will check if it is accepted already and display a proper message.




SeniorSecurity#task
Loading comments...