Concurrency Issues in Retail: Managing with Oracle

Concurrency Issues in Retail Systems: An Analytical Perspective

In a busy retail chain such as Agora Gulshan in Dhaka, multiple users access and update shared database records simultaneously. Without proper concurrency control, significant anomalies can arise, affecting data integrity and operational reliability.

1️⃣ Lost Update Anomaly

Scenario Analysis: Two cashiers at Agora Gulshan read the stock of "Chashi Aromatic Rice" (ID: 101) as 20 units.
Cashier A sells 5 units, updating stock to 15. Cashier B, unaware, sells 10 units and updates stock to 10.
Impact: Cashier A’s update is overwritten, causing inaccurate stock data and potential stockouts.

2️⃣ Dirty Read Anomaly

Scenario Analysis: At Shwapno Dhanmondi, Manager A updates the price of "Fresh Sugar" (ID: 202) to 55 BDT but doesn’t commit.
Manager B reads this uncommitted price for a report. Manager A rolls back, but Manager B’s report now contains invalid data.
Impact: This can mislead decision-making and damage trust in reporting accuracy.

Analytical Insights

  • Locks: Prevent simultaneous updates but can cause deadlocks if not managed carefully.
  • Isolation Levels: Ensure transactions see consistent data (e.g., SERIALIZABLE prevents lost updates and dirty reads).
  • MVCC: Enables snapshot-based reads for consistent data views without blocking other readers.

Oracle Implementation Example

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;

BEGIN
  DECLARE
    v_stock NUMBER;
  BEGIN
    SELECT stock INTO v_stock FROM products WHERE product_id = 101;
    v_stock := v_stock - 5;
    UPDATE products SET stock = v_stock WHERE product_id = 101;
    COMMIT;
  EXCEPTION
    WHEN OTHERS THEN
      ROLLBACK;
      DBMS_OUTPUT.PUT_LINE('Transaction failed and rolled back.');
  END;
END;
/

Conclusion

Concurrency issues in the retail environments—like Agora Gulshan and Shwapno Dhanmondi—can compromise inventory and pricing accuracy.
Leveraging Oracle’s transaction isolation levels and robust concurrency control mechanisms ensures data accuracy, reliability, and business efficiency, even during peak hours.

একটি মন্তব্য পোস্ট করুন