TutorChase logo
Login
AQA A-Level Computer Science

19.5.3 Concurrency Control Techniques

Concurrency control ensures that when multiple users access and modify a database at the same time, the integrity and consistency of the stored data is preserved. It prevents data conflicts, inconsistencies, and system errors that can occur in multi-user environments.

Record locking

Record locking is a widely used concurrency control technique that prevents more than one user from modifying the same data at the same time. This technique allows multiple users to read data simultaneously but restricts access when a user wants to update it.

What is record locking?

When a user initiates a transaction to change a record, the database management system (DBMS) locks the record. This lock prevents other transactions from reading or writing the same record until the lock is released, usually once the transaction is completed and committed or rolled back.

This helps ensure that:

  • No other transaction can change the same record while it is being modified.

  • The result of the transaction reflects the correct and expected changes.

  • Data integrity is preserved in concurrent environments.

Locks are typically handled automatically by the DBMS. Users do not need to manually lock or unlock records. However, developers must be aware of how locking works, especially when designing systems where many users access shared data.

Binary locking

Binary locking is the simplest form of record locking. Each record has a lock flag with two possible states:

  • Locked: The record is currently being used by a transaction and cannot be accessed by others.

Take your grades to the next level!

UPGRADING TO PREMIUM UNLOCKS
AI Tutor
AI-powered study assistant
instant feedback and guidance
Predicted Papers
Examiner-style predicted papers
based on recent exam trends
Practice Questions
All exam practice questions
by topic for each subject
Study Notes
All detailed revision notes
written by expert teachers
Cheat Sheets
Quick revision summaries
perfect for last-minute review
Past Papers
Complete collection
of practice and past exam papers
Email
Password
Confirm Password
Already have an account?

Practice Questions

FAQ

Allowing concurrent access in database systems is essential for maintaining efficiency and performance, especially in environments with multiple users or high transaction loads. If every transaction had to run sequentially, users would experience delays due to a bottleneck, as only one user could interact with the database at a time. This would be unacceptable in real-world applications like banking, online shopping, or airline bookings, where thousands of users interact with the system simultaneously. Concurrency allows multiple transactions to be interleaved, maximising system throughput and resource utilisation. Importantly, modern DBMSs are designed to handle concurrent access safely through techniques like locking, serialisation, and ordering mechanisms. These ensure that even though transactions run in parallel, the final state of the database remains consistent and valid. Without concurrency, systems would be inefficient and unable to meet user demand. With controlled concurrency, performance is optimised without sacrificing data integrity.

Two-phase locking (2PL) is a protocol used to enforce serialisability in transaction execution and is more sophisticated than basic binary locking. It involves two distinct phases for a transaction: the growing phase, where locks are acquired and no locks are released, and the shrinking phase, where locks are released and no new locks are acquired. This ensures that once a transaction begins releasing locks, it cannot obtain any new ones, thereby reducing the risk of inconsistencies. In contrast, binary locking simply refers to whether a record is locked or unlocked at any given time and does not control when locks can be acquired or released. Binary locking lacks rules to prevent inconsistencies that arise from overlapping transactions. Two-phase locking, by enforcing this structured approach, guarantees a serialisable schedule and avoids many problems like lost updates or unrepeatable reads. However, it can lead to deadlocks, which require additional handling.

When a system using timestamp ordering experiences frequent transaction rollbacks, it usually indicates high contention for the same data or poor transaction design. Since timestamp ordering requires transactions to follow a strict sequence based on their start times, any transaction that attempts to read or write data in a way that would violate this sequence must be aborted and restarted. If this occurs too often, it can lead to performance degradation, increased response times, and wasted computational resources. To address this, developers can redesign transactions to be shorter and reduce overlapping access to the same data items. Introducing better indexing strategies or batching operations can also help reduce conflict. Some systems may implement hybrid approaches, combining timestamp ordering with other concurrency controls to reduce rollbacks. Ultimately, while timestamp ordering is effective at maintaining consistency, excessive rollbacks are a sign that the system's concurrency model or data access patterns need to be optimised.

Commitment ordering is especially beneficial in distributed database systems or multi-database transactions where traditional locking mechanisms are difficult to coordinate across separate nodes. For example, financial systems handling inter-bank transfers, global e-commerce platforms with geographically dispersed servers, or systems using microservices with separate databases can benefit significantly. In these environments, maintaining global locking or timestamp synchronisation across networks introduces overhead and complexity. Commitment ordering allows transactions to be executed independently at each node while ensuring that their commits follow a global serialisable order. This means systems can maintain data consistency without frequent communication between nodes during execution. Additionally, commitment ordering can be combined with protocols like two-phase commit to ensure atomicity across distributed transactions. It is also useful in real-time systems where operations must proceed quickly and coordination delays are undesirable. Its ability to support high availability and consistency in loosely coupled environments makes it ideal for modern distributed applications.

Concurrency control works closely with database recovery mechanisms to ensure that the database remains in a valid state, even when errors or crashes occur. When transactions are executed concurrently, recovery mechanisms must be able to undo or redo operations without violating the order or isolation of transactions. For this reason, systems use transaction logs, which record every operation performed, including reads, writes, and commit points. If a transaction fails or is rolled back due to a conflict (e.g. in timestamp ordering) or a system crash, the log is used to reverse its changes safely. In the case of concurrent transactions, the system must also ensure that undoing one transaction does not affect others that have already committed. Concurrency control techniques like serialisation and locking help maintain clear boundaries between transactions, making it easier to apply rollbacks precisely. Without such coordination, recovery would risk corrupting data modified by overlapping or interdependent transactions.

Hire a tutor

Please fill out the form and we'll find a tutor for you.

1/2
Your details
Alternatively contact us via
WhatsApp, Phone Call, or Email