Quiz — Chapter 32: Transaction Design Patterns

Multiple Choice

1. What does the "A" in ACID stand for? - a) Accessibility - b) Atomicity - c) Availability - d) Authentication

2. In a DB2 batch COBOL program, what happens if the program terminates normally without an explicit COMMIT? - a) All changes are lost - b) All changes since the last COMMIT are committed automatically - c) The program abends - d) Changes are held in a pending state

3. What is the primary purpose of two-phase commit? - a) To speed up transaction processing - b) To coordinate commits across multiple resource managers - c) To prevent deadlocks - d) To enable parallel processing

4. What is the most effective strategy for preventing deadlocks? - a) Using longer timeouts - b) Avoiding all concurrent access - c) Acquiring locks in a consistent order (resource ordering) - d) Using optimistic locking exclusively

5. In optimistic locking, how do you detect that another transaction has modified the data? - a) The database returns a lock error - b) You compare a version column or timestamp to the value read earlier - c) The COMMIT fails - d) A deadlock occurs

6. What is a "saga" in transaction design? - a) A long-running SQL query - b) A sequence of short transactions with compensating actions for rollback - c) A type of database lock - d) A batch program with checkpoint/restart

7. What does "idempotent" mean in the context of transaction design? - a) The transaction runs in isolation - b) The transaction produces the same result whether executed once or multiple times - c) The transaction cannot be rolled back - d) The transaction runs without locks

8. What SQLCODE indicates a deadlock or timeout in DB2? - a) -803 - b) -904 - c) -911 - d) -922

9. Which CICS command commits all changes in the current unit of work? - a) EXEC CICS COMMIT - b) EXEC CICS SYNCPOINT - c) EXEC CICS SAVE - d) EXEC CICS SYNC

10. What is the main disadvantage of committing after every record in a batch program? - a) Data inconsistency - b) High overhead from frequent commits - c) Increased deadlock risk - d) Loss of audit trail

True/False

11. In CICS, SYNCPOINT ROLLBACK undoes changes to all resource managers (DB2, VSAM, etc.) in the current unit of work. True / False

12. Pessimistic locking is always better than optimistic locking for online transactions. True / False

13. A DLET (delete) call in IMS can be used as a compensation action. True / False

14. Two-phase commit guarantees zero performance overhead. True / False

15. The "Lock-and-Think" pattern (holding locks during user think time) is an anti-pattern that should be avoided. True / False

Short Answer

16. Explain why a funds transfer (debit one account, credit another) must be a single unit of work. What could go wrong if the debit and credit are in separate units of work?

17. Describe three strategies for minimizing the duration of exclusive locks in a CICS online transaction.

18. A compensation transaction for "insert a claim record" is "update claim status to CANCELLED" rather than "delete the claim record." Explain why the UPDATE approach is preferred over DELETE.

19. A batch program processes payment records from an MQ queue. Due to a system restart, some messages may be delivered twice. How would you design the program to handle duplicate messages safely?

20. Explain the difference between the "Chatty Transaction" and "Mega-Transaction" anti-patterns. What is the correct approach that avoids both extremes?

Answer Key

  1. b — Atomicity: all or nothing.
  2. b — DB2 automatically commits uncommitted changes at normal program termination.
  3. b — Two-phase commit coordinates commits across multiple resource managers.
  4. c — Resource ordering (consistent lock acquisition order) is the most effective prevention.
  5. b — Optimistic locking compares a version/timestamp to detect changes.
  6. b — A saga breaks long-running processes into short, compensatable transactions.
  7. b — Idempotent operations produce the same result regardless of how many times they execute.
  8. c — SQLCODE -911 indicates deadlock or timeout.
  9. b — EXEC CICS SYNCPOINT commits the unit of work.
  10. b — Committing after every record adds significant I/O overhead.
  11. True — SYNCPOINT ROLLBACK is coordinated across all resource managers.
  12. False — Optimistic locking is better for low-contention scenarios; the choice depends on the access pattern.
  13. True — Though using status flag updates is generally preferred for auditability.
  14. False — Two-phase commit adds overhead from extra log writes and coordination messages.
  15. True — Holding locks during user interaction drastically reduces concurrency.
  16. If debit and credit are separate UOWs, a failure after the debit but before the credit leaves the source account debited without the destination being credited. Money "disappears." The accounts no longer balance, violating both business rules and regulatory requirements.
  17. (1) Perform all calculations and validations before acquiring locks. (2) Commit immediately after the update. (3) Use optimistic locking instead of pessimistic locking for appropriate scenarios.
  18. UPDATE preserves the audit trail (the record exists with CANCELLED status), is idempotent (updating to CANCELLED twice has the same effect), and supports compliance requirements that may mandate record retention. DELETE removes evidence and is harder to diagnose if problems occur later.
  19. Assign each payment a unique ID. Before processing, check whether that ID already exists in the payment history table. If it does, skip processing (idempotent skip). If not, process the payment and insert the ID into the history table within the same unit of work.
  20. The Chatty Transaction commits too frequently, breaking logical units of work and risking inconsistency. The Mega-Transaction never commits, risking catastrophic rollback times. The correct approach commits at logical business boundaries — after each complete unit of work — balancing consistency with recovery time.